Commit Graph

146 Commits

Author SHA1 Message Date
Mikhail Glukhikh 8ac576614f Revert "Temporary: mute PRE_RELEASE_CLASS in some tests (KT-66551)"
This reverts commit 893e5cac
2024-03-15 11:33:10 +00:00
Yan Zhulanow 1f39bc9a18 [Analysis API] Add tests for foreign values 2024-03-14 10:20:29 +00:00
Mikhail Glukhikh 893e5cac94 Temporary: mute PRE_RELEASE_CLASS in some tests (KT-66551) 2024-03-13 20:38:44 +00:00
Marco Pennekamp 56a08319ec [AA] Add toString implementation for KtLibraryModuleImpl
- This allows stable mentions of test module libraries in output test
  data.

^KT-56288
2024-02-28 21:08:18 +00:00
Marco Pennekamp 56fd4b562b [AA] Improve modification event test directives
- Rewrite `TestModule.publishModificationEventByDirective`: we can get
  the `KtModule` to publish an event for via the test module. The
  directive can now be made optional, which is necessary when we want to
  specify it in potentially multiple modules.
- Introduce the `WILDCARD_MODIFICATION_EVENT` directive, which allows
  specifying THAT some modification event should be raised for a module,
  but not WHICH one. This allows generating multiple tests which raise
  different modification events over the same test data.
- Add various convenience functions for publishing wildcard modification
  events. `publishWildcardModificationEventsByDirective` for the test
  module structure is quite opinionated, but takes a lot of work from
  test implementations.
- Because `ModificationEventDirectives` are part of the analysis test
  framework, we register them as a general Analysis API test directive.

^KT-56288
2024-02-28 21:08:17 +00:00
Marco Pennekamp 3044941201 [AA] Add TestModule.getKtModule convenience function
^KT-56288
2024-02-28 21:08:17 +00:00
Marco Pennekamp 5207940f0b [LL] CleanableSoftValueCache: Add non-concurrent tests for value cleanup
- The non-concurrent `CleanableSoftValueCacheTest` ensures that
  deterministic cleanup behaves correctly. A Lincheck test can only
  discover differences between the single-threaded and concurrent
  executions of a test scenario, so it cannot find correctness issues
  with deterministic cleanup on its own.

^KT-61222
2024-02-27 16:45:52 +00:00
Marco Pennekamp 040b7472a9 [AA] Add MODIFICATION_EVENT test directive
- This allows tests to specify which modification event they want to
  publish.
- The modification event won't be published automatically. Tests need to
  invoke `publishModificationEventByDirective` at the right time.

^KT-56288
2024-02-27 16:45:52 +00:00
Marco Pennekamp 4ea3de1760 [AA] Refactoring: Rename KtModuleFactory to KtTestModuleFactory
^KT-65960
2024-02-26 21:57:23 +00:00
Marco Pennekamp 3f04604187 [AA] Tests: Improve handling of dependencyPaths
- The name wasn't specific enough.
- Remove default `emptyList()` argument from `CompiledLibraryProvider`
  so that passing `dependencyBinaryRoots` isn't missed. (My changes
  didn't include it in `KtLibraryBinaryModuleFactoryBase` yet, but it
  was actually missed from `KtLibrarySourceModuleFactory` even in the
  original commit.)

^KT-65960
^KT-64994
2024-02-26 21:57:23 +00:00
Marco Pennekamp 5663521a36 [AA] Tests: Remove topological ordering from KtTestModule creation
- The test infrastructure already requires test modules to be properly
  ordered regarding dependencies, so a module A which is a dependency
  for a module B must always be ordered before B. Hence, it makes no
  sense to also order modules topologically.
- Reordering modules may cause the resulting `KtTestModule`s to be
  out-of-order with the test modules, because the topological order
  might be different from the test module order, even if the dependency
  relationship already holds in the original order.
  `KtTestModuleProjectStructure` requires the same ordering as test
  modules to ensure the same order during iteration of `KtTestModule`s.

^KT-65960
^KT-64994
2024-02-26 21:57:23 +00:00
Marco Pennekamp 78ef58bef4 [AA] Tests: Remove decompiled files from LibraryBinary and add LibraryBinaryDecompiled
- `LibraryBinary` should not contain any decompiled files, as we want
  FIR symbols in tests to be provided from indexed stubs or class files,
  but definitely not from decompiled PSI. This brings `LibraryBinary`
  much closer to the behavior of binary libraries in the IDE.
- Some tests may still require access to a decompiled file, for example
  when trying to test `getOrBuildFir` for some `KtElement` coming from a
  library. This commit introduces `LibraryBinaryDecompiled`, which
  does contain decompiled files.
- We don't really need `LibraryBinary` as a main test module kind
  anymore, since tests generally want to access some main `KtFile`.
  Hence, test configurators for `LibraryBinary` have been turned into
  configurators for `LibraryBinaryDecompiled`.
- An alternative would be decompiling files on demand, but this is not
  currently feasible because the Standalone API doesn't reconcile stubs
  with decompiled PSI, like the IDE does automatically. (For the same
  declaration, the stub and the PSI will have a different identity.) As
  long as there is no support for this, we'll have to rely on a separate
  test module kind.

^KT-65960
2024-02-26 21:57:23 +00:00
Marco Pennekamp 7baaa38b8a [AA] Add KtTestModule.moduleKind
- `TestModule.explicitTestModuleKind` requires a directive to be present
  to get the `TestModuleKind`. But we still want to find out the test
  module kind for test modules without a directive. Hence, we have to
  add this property to `KtTestModule` during its construction.

^KT-65960
2024-02-26 21:57:23 +00:00
Marco Pennekamp dc0f498b15 [AA] Simplify prepareFilesInModule with KtTestModule
^KT-65960
2024-02-26 21:57:23 +00:00
Marco Pennekamp 6cc414bdfd [AA] Simplify createProjectStructureByTestStructure with KtTestModule
^KT-65960
2024-02-26 21:57:23 +00:00
Marco Pennekamp 2060709c03 [AA] Turn KtModuleWithFiles into KtTestModule (AA test framework)
- `KtModuleWithFiles` isn't actually used in a production Standalone API
  context, but it was exposed via `analysis-api-standalone-base`. In
  current production usages, the project structure is built with the
  module builder DSL.
- Hence, `KtModuleWithFiles` is only relevant for tests. This commit
  moves `KtModuleWithFiles` to the Analysis API test framework and
  renames it to `KtTestModule`. This removes any risk that an outside
  user could start using `KtModuleWithFiles` and completely uncouples
  the test project structure from production APIs.
- In addition, we can add the `TestModule` to `KtTestModule`, allowing
  tests to quickly access the original test module, for example to check
  the test module kind.
- The commit also removes the data class status of `KtTestModule` and
  `KtTestModuleProjectStructure` to avoid issues with destructuring when
  properties are added or removed.

^KT-65960
2024-02-26 21:57:23 +00:00
Marco Pennekamp 878eba7d52 [AA] Introduce AnalysisApiIndexingConfiguration test service
- The configuration allows the test infrastructure to decide whether to
  index binary libraries to stubs (when stub-based deserialized symbol
  providers are used) or to skip indexing (when class file-based
  deserialization is used).
- The information is needed in `AnalysisApiBaseTestServiceRegistrar`,
  where the `KotlinStaticDeclarationProviderFactory` is created. This
  service registrar shouldn't access `LLFirLibrarySymbolProviderFactory`
  and so checking the library symbol provider factory wasn't an option.
- Another alternative was adding a property to
  `AnalysisApiTestConfigurator`. However, this then requires passing the
  property to `AnalysisApiBaseTestServiceRegistrar`, because it doesn't
  have access to the configurator out of the box. This however goes
  against the design of our service registrars, which generally only
  access test services. So adding a test service seemed like the best
  solution.

^KT-65960
2024-02-26 21:57:23 +00:00
Yan Zhulanow 42c2e7d503 [Analysis API] Minor, prettify 'createModules()' 2024-02-26 18:02:08 +00:00
Yan Zhulanow b925462852 [Analysis API] Minor, tune the 'createModule()' signature
Move the 'dependencyPaths' parameter closer to other traits of
a created module.
2024-02-26 18:02:08 +00:00
Jaebaek Seo 171ea3571c K2: Use deserialized type annotation for lambda type resolution.
This commit adds code to check whether a deserialized cone type is a
special function type kind or not when resolving the type of a lambda
expression (anonymous function). If it is a special function kind, it
sets the type of lambda based on the special function kind.

^KT-64994 Fixed
2024-02-25 10:10:43 +00:00
Jaebaek Seo 512efb9649 K2: Support binary library dependencies between test modules
The test infrastructure for analysis supports binary module tests, but
the binary build does not use another binary module as a dependency when
it passes the class path. As a result, each binary module build does not
work when they have dependency on each other.

This commit fixes the issue by
1. Topological sort in the order of dependency graph for test modules.
2. Pass module paths as extra class paths when they have dependency on
   each other.

^KT-64994
2024-02-25 10:10:43 +00:00
Yahor Berdnikau 6b19b8b9d0 [Repo] Don't use kotlinOptions in repo build scripts
^KT-63419 In Progress
2024-02-22 14:48:10 +00:00
Dmitrii Gridin 2e2e592cc3 [Analysis API] CliTestModuleCompiler: support LANGUAGE_VERSION directive
^KT-64884
2024-02-13 16:07:17 +00:00
Ilya Goncharov 2340d59f40 [JS] Get rid of outputFile in compiler args (KT-61116)
^KT-56753 fixed
2024-02-09 18:20:08 +00:00
Dmitry Savvinov f19859db4e [Tests] Do not add .java-files of whole project to contentScope in K2
Previously, the code was calling into
TopDownAnalyzerFacadeForJVM.newModuleSearchScope, which includes
AllJavaSourcesInProjectScope.

This lead to .java-sources being incorrectly attributed to wrong
modules in tests, which, in turn, could've introduced undesired
behaviour around module-dependent checks (e.g. whether a variable
is from the other module and thus can't be smartcasted)
2024-01-31 09:53:44 +00:00
Yan Zhulanow e001fa4e72 [Analysis API] Explicitly specify the context module in a directive 2024-01-30 11:41:26 +00:00
Yan Zhulanow 3cd04a9e9e [Analysis API] Migrate existing code fragment tests to the new API 2024-01-30 11:41:26 +00:00
Yan Zhulanow 01ca31a061 [Analysis API] Add test infrastructure for code fragments
Now, Analysis API tests can define modules with code fragments.
The preceding module will be used as a context module.
2024-01-30 11:41:26 +00:00
Roman Golyshev fb225f5f20 [tests] Return caret names from ExpressionMarkerProvider
Render caret names in resolve testData, so that we don't have to guess
the indices of the carets;
it makes the multi-caret testData less error-prone.

Relevant for KT-65152 and KT-62695
2024-01-26 10:12:09 +00:00
Roman Golyshev 17c1352d82 [tests] Refactor AbstractReferenceResolveTest. Part 3
Add possibility to `ExpressionMarkerProvider` to get all the carets
from the file.
Use it in `AbstractReferenceResolveTest`, but not check all the carets
yet.

Required for KT-65152 and KT-62695
2024-01-26 10:12:09 +00:00
Pavel Kirpichenkov 24b19e3c32 [LL] Add test for KmpModuleSorter
KTIJ-27569
2024-01-19 10:20:52 +00:00
Yan Zhulanow e393282c67 [Analysis API] Remove test infrastructure for obsolete on-air analysis 2024-01-18 17:12:28 +00:00
Yan Zhulanow adb8b7b252 [Analysis API] Minor, improve naming for 'computeTestDataPath()' 2024-01-18 17:12:28 +00:00
Dmitrii Gridin cbae92f5c6 [Analysis API test] get rid of AbstractAnalysisApiSingleFileTest
^KT-64805
2024-01-10 22:07:03 +00:00
Dmitrii Gridin 476940c06b [Analysis API test] get rid of AbstractAnalysisApiBasedSingleModuleTest
^KT-64805
2024-01-10 22:07:03 +00:00
Dmitrii Gridin f8d95eceb7 [Analysis API] AbstractAnalysisApiBasedTest: implement test entry points to avoid boilerplate on implementation side
There are three test entry points:
* [doTestByMainFile] – test cases with dedicated main file.
Supports everything from single-file cases to multi-platform multi-module
multi-file cases
* [doTestByMainModuleAndOptionalMainFile] – test cases rather around
modules than files
* [doTestByModuleStructure] – all other cases with fully custom logic

Look at the KDoc of the corresponding method for more details.

^KT-64805 Fixed
2024-01-10 22:07:03 +00:00
Dmitrii Gridin b67deea21f [Analysis API] introduce getKtFiles util
^KT-64805
2024-01-10 22:07:03 +00:00
Dmitrii Gridin d828a646cf [Analysis API] move allKtFiles util from LL FIR module
^KT-64805
2024-01-10 22:07:03 +00:00
Dmitrii Gridin 1c2fac41c2 [Analysis API] ExpressionMarkerProvider: fix path for selected expressions
We are storing them by file path, but accessing them by
file name, which is inconsistent

^KT-64805
2024-01-10 22:07:03 +00:00
Dmitrii Gridin a7984c6794 [Analysis API] ExpressionMarkerProvider: do not expose implementation details
And add API for selected expressions

^KT-64805
2024-01-10 22:07:03 +00:00
Dmitrii Gridin 663b7fb76f [Analysis API] AbstractAnalysisApiBasedTest: introduce entry point for tests with main file
Pulled up the implementation from AbstractCompilerFacilityTest

^KT-64805
2024-01-10 22:07:03 +00:00
Marco Pennekamp ff0224d28d [AA] Test project structure: Fix duplicate binary library modules in main module dependencies
- `TestModuleStructureFactory.createProjectStructureByTestStructure`
  created `KtModule`s for each test module and then also created new
  `KtModule`s for binary dependencies. This split worked as long as no
  binary dependency was also a test module and thus part of the main
  modules. But if not, `addLibraryDependencies` created a duplicate
  `KtModule`, instead of referring to the existing binary module.
- The fix registers a main binary library module in the library cache
  before it can become the dependency of another main module. Because
  main modules can only depend on main modules preceding them in the
  list, a separate pass over all main modules is not needed.

^KT-64647 fixed
2024-01-10 10:13:23 +00:00
Yan Zhulanow 1b7d1dd08a [Analysis API] Simplify 'getNotUnderContentRootModule()'
In the resulting implementation of dangling file modules,
'getNotUnderContentRootModule()' is never called with a not-null file.
2024-01-05 16:04:14 +00:00
Yan Zhulanow 452d22e14f [Analysis API] Add IGNORE_SELF dangling file resolution mode
In the 'IGNORE_SELF' mode, dangling files don't have their own
declarations in providers. As a result, all references there resolve to
declarations of the original file. It is conceptually similar to that we
had in on-air resolve, however, now it's possible to work with the whole
content of the in-memory 'FirFile'.

As it can be seen in 'ProjectStructureProvider.kt'
(KtFile.danglingFileResolutionMode), the 'IGNORE_SELF' mode is
automatically applied for non-physical files with an original file being
set. For other scenarios, now there is a new 'analyzeCopy()' function
that allows to pass the analysis mode explicitly.
2024-01-05 16:04:14 +00:00
Yan Zhulanow 2899822102 [Analysis API] Extract dangling file module computation
Use the same code for creating dangling file modules inside tests,
the stand-alone API, and in the IDE.
2024-01-05 16:04:14 +00:00
Yan Zhulanow a614d0325f [Analysis API] Move test-only project provider closer to tests 2024-01-05 16:04:14 +00:00
Yan Zhulanow 5179462632 [Analysis API] Support non-JVM platforms in code fragments
The 'evalJs' test is not available, as there is no proper support for
klib loading in non-standalone Analysis API yet.

^KT-64197 Fixed
2024-01-05 16:04:14 +00:00
Yan Zhulanow 75abae23d8 [Analysis API] Fix WITH_STDLIB for common modules in Analysis API tests
The previous implementation in 'TestModuleStructureFactory' had very
custom and redundant logic for binary dependency collection.
In particular, JDK and kotlin-stdlib were specifically computed,
although both already were in the module classpath, which was handled in
'createLibrariesByCompilerConfigurators()'. In addition, there was no
support for common modules.

The new behavior is much closer to what happens in production.
2024-01-05 16:04:14 +00:00
Dmitrii Gridin 6c7d1babf0 [Analysis API] support Java compilation in tests
Previously we just skipped Java sources.
The order of classes in light classes test data is changed due to
differences in implementations of `compileLibraryToJar` and `runJvmCompiler`

^KT-62892
2024-01-03 21:35:12 +00:00
Dmitrii Gridin 8de9d42b0d [Analysis API] use createSearchScopeByLibraryRoots for test libraries
As it is more similar to production. Also, fixed scope search for klib.
Now we register main binary modules before to avoid duplication with
libraries from createLibrariesByCompilerConfigurators as now we can
have a declared library and regular sources

^KT-62888
^KT-62651
2024-01-03 13:39:42 +00:00