Commit Graph

124 Commits

Author SHA1 Message Date
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
Dmitrii Gridin 02d99769ff [Analysis API] Use library name in result jar
^KT-62888
^KT-62651
2024-01-03 13:39:41 +00:00
Dmitrii Gridin 282cd82539 [Analysis API] AnalysisApiFirSourceTestConfigurator: supports mixed multi-module tests
^KT-64468
2023-12-21 19:48:22 +00:00
Dmitrii Gridin c0b333dfc1 [Analysis API] AbstractAnalysisApiBasedTest: exit from ignored tests before any analysis
It is possible that `prepareToTheAnalysis` will throw an exception for
ignored test

^KT-64468
2023-12-21 19:48:22 +00:00
Dmitrii Gridin 00db7fdaeb [Analysis API] mark MODULE_KIND directive as module-level
^KT-64468
2023-12-21 19:48:22 +00:00
Dmitrii Gridin d1cb9ab060 [Analysis API] TestModuleKind: introduce moduleKind util
^KT-64468
2023-12-21 19:48:22 +00:00
Marco Pennekamp d3d21b3f34 [AA] Support multi-module tests with mixed KtModule kinds
- This commit adds a `MODULE_KIND` directive to Analysis API tests which
  can be used to change a test module's `KtModule` kind from the default
  determined by the test's registered `KtModuleFactory` (which in turn
  depends on the `moduleKind` configured during test generation).
- The most important use case is the ability to have multi-module tests
  where a main module references symbols from a binary library module.
  This use case requires source configurations to compile libraries,
  which requires additional setup. This will be implemented in a
  following commit.

^KT-64468 Fixed
2023-12-21 19:48:22 +00:00
Marco Pennekamp bba5447b12 [Test/AA] Pass project disposable to getOrCreateApplicationEnvironment instead of application disposable
- The disposable passed to `getOrCreateApplicationEnvironment` should
  not actually be the application environment's disposable, which is
  created inside the function. Instead, it should be the project's
  disposable, which is used to track how many projects still rely on the
  shared application environment.
- This issue wasn't apparent before because there is no visible
  consequence when an application isn't disposed after all projects have
  been disposed (during tests). However, the solution for KT-63650
  relies on application environments being disposed after all projects
  are disposed, so that a new application environment with a different
  configuration can be created. (Only one shared application environment
  may be active at the same time.)

^KT-63650
2023-12-19 11:12:23 +00:00
Jinseong Jeon 10c9b81c79 AA standalone: introduce multi-module binary dependency test 2023-12-19 07:03:29 +00:00
Ilya Gorbunov d2aae67e03 Replace kotlin-test project dependencies in the project
Use dependency helper function that chooses whether to take them
from the bootstrap repository or from a configuration of kotlin-test

KT-61969
2023-12-13 15:40:25 +00:00
Sergej Jaskiewicz f844a86057 [utils] Introduce the bind function and use it throughout 2023-12-13 10:04:45 +00:00
Pavel Kirpichenkov fb9bf1782e [AA] Fall back to JVM stdlib dependencies in common test modules
Returns the old test behavior, until KT-63769 is implemented.
2023-12-01 18:12:23 +00:00
Pavel Kirpichenkov 0eb1a63a2f [AA] Add symbol tests for symbols from JS klibs
Use test compiler runner to compile JS libraries. Determine compiler
by the specified TARGET_PLATFORM. Add tests for dynamic type and
JS-specific .proto extensions.

Refactor the code for mock library compilation to make the switch
between platforms more straightforward.

KTIJ-27566
KT-63217
2023-12-01 18:12:23 +00:00
Artem Olkov 54c2339dfb [Analysis API] [Test Infra] move (de)compilation services
move (de)compilation services from static dependencies into DI
This is done for allowing different (de)compile strategies in the future


Merge-request: KT-MR-13213
Merged-by: Artem Olkov <artem.olkov@jetbrains.com>
2023-11-24 10:58:49 +00:00
Marco Pennekamp 1870189e47 [AA] Fix write access configuration in unit test application environments
- We cannot configure the application's write action accessibility on a
  per-test basis because (1) the application may be shared across
  concurrent tests and (2) the application is usually cached, so the
  configuration will be missed entirely.
- There is actually a much easier solution to allow write access
  selectively: We can enable it in `runWriteAction` blocks, and keep it
  in a thread local to support concurrent test runs. As Analysis API
  tests never call `runWriteAction`, there will be no "analyze cannot be
  called from a write action" error, and if `analyze` is somehow called
  from a write action, it will now be caught.

^KT-63560 fixed
2023-11-20 16:29:26 +00:00
Marco Pennekamp 03a7162f37 [AA] Enable test-specific configuration of write access permissions
- In general, Analysis API tests forbid write access because the
  Analysis API should not be used from write actions. However, in some
  cases we might want tests to e.g. modify PSI, which requires write
  access. This change allows `AnalysisApiTestConfigurator`s to enable
  write access for the specific test.
2023-11-16 19:50:51 +00:00
Marco Pennekamp 6189d68c3c [AA] Refactoring: Provide default implementations for functions of AnalysisApiTestServiceRegistrar
- Most inheritors of `AnalysisApiTestServiceRegistrar` only need to
  override one or two functions.
2023-11-16 19:50:51 +00:00
Ilya Kirillov a18c49d795 [LL FIR] retrieve Kotlin/Native KLib dependencies for compiled based tests
Previously, all tests were considered as JVM-only
from the library dependencies point of view.

^KT-62910
2023-11-10 06:41:03 +00:00
Ilya Kirillov d2b9b487c7 [Analysis API] add test for resolution into declarations with the kotlin. package
^KT-63223
2023-11-08 17:32:49 +00:00
Ilya Kirillov 063d73fa73 [Analysis] migrate analysis modules to use cliArgument helper instead of hardcoded CLI argument names
^KT-63294
2023-11-08 17:32:48 +00:00
Dmitrii Gridin 8e623ee73a [LL FIR] support script tests 2023-10-24 19:32:54 +00:00
Dmitrii Gridin 0771b60777 [Analysis API] support multiplatform test cases
^KT-62345
2023-10-17 17:19:40 +00:00
Dmitrii Gridin 2cac922cd0 [FIR] add tests on external annotations
Tests are excluded in COMPILED_JAVA mode because in this
mode external annotations are not present at all

^KT-62310
2023-10-13 12:16:12 +00:00