[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
This commit is contained in:
Marco Pennekamp
2023-12-20 00:40:25 +01:00
committed by Space Team
parent 69a2bc9abc
commit d3d21b3f34
17 changed files with 187 additions and 103 deletions
@@ -13,7 +13,7 @@ import org.jetbrains.kotlin.analysis.api.standalone.base.project.structure.KtMod
import org.jetbrains.kotlin.analysis.api.standalone.base.project.structure.KtModuleWithFiles
import org.jetbrains.kotlin.analysis.low.level.api.fir.test.base.AnalysisApiFirTestServiceRegistrar
import org.jetbrains.kotlin.analysis.low.level.api.fir.test.base.configureOptionalTestCompilerPlugin
import org.jetbrains.kotlin.analysis.low.level.api.fir.test.configurators.KtLibraryBinaryModuleFactory
import org.jetbrains.kotlin.analysis.test.framework.project.structure.KtLibraryBinaryModuleFactory
import org.jetbrains.kotlin.analysis.test.framework.project.structure.KtModuleFactory
import org.jetbrains.kotlin.analysis.test.framework.project.structure.KtSourceModuleFactory
import org.jetbrains.kotlin.analysis.test.framework.project.structure.TestModuleStructureFactory
@@ -66,14 +66,11 @@ object StandaloneModeLibraryBinaryTestConfigurator : StandaloneModeConfiguratorB
}
private class KtCombinedModuleFactory : KtModuleFactory {
private val sourceModuleFactory = KtSourceModuleFactory()
private val libraryBinaryModuleFactory = KtLibraryBinaryModuleFactory()
override fun createModule(testModule: TestModule, testServices: TestServices, project: Project): KtModuleWithFiles {
return if (testModule.name == "app") {
sourceModuleFactory.createModule(testModule, testServices, project)
KtSourceModuleFactory.createModule(testModule, testServices, project)
} else {
libraryBinaryModuleFactory.createModule(testModule, testServices, project)
KtLibraryBinaryModuleFactory.createModule(testModule, testServices, project)
}
}
}