[Analysis API] AnalysisApiFirSourceTestConfigurator: supports mixed multi-module tests
^KT-64468
This commit is contained in:
committed by
Space Team
parent
c0b333dfc1
commit
282cd82539
+5
@@ -25,6 +25,11 @@ private val TestServices.ktModuleFactory: KtModuleFactory by TestServices.testSe
|
||||
*
|
||||
* By default, the [KtModuleFactory] registered with these [TestServices] is returned. It may be overruled by the
|
||||
* [MODULE_KIND][org.jetbrains.kotlin.analysis.test.framework.AnalysisApiTestDirectives.MODULE_KIND] directive for a specific test module.
|
||||
*
|
||||
* [DependencyKindModuleStructureTransformer][org.jetbrains.kotlin.analysis.test.framework.services.DependencyKindModuleStructureTransformer]
|
||||
* should be used to properly set up [DependencyKind][org.jetbrains.kotlin.test.model.DependencyKind] for module dependencies
|
||||
*
|
||||
* @see org.jetbrains.kotlin.analysis.test.framework.services.DependencyKindModuleStructureTransformer
|
||||
*/
|
||||
fun TestServices.getKtModuleFactoryForTestModule(testModule: TestModule): KtModuleFactory = when (testModule.moduleKind) {
|
||||
TestModuleKind.Source -> KtSourceModuleFactory
|
||||
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.analysis.test.framework.services
|
||||
|
||||
import org.jetbrains.kotlin.analysis.test.framework.AnalysisApiTestDirectives
|
||||
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.TestModuleKind
|
||||
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.moduleKind
|
||||
import org.jetbrains.kotlin.test.TestInfrastructureInternals
|
||||
import org.jetbrains.kotlin.test.model.DependencyDescription
|
||||
import org.jetbrains.kotlin.test.model.DependencyKind
|
||||
import org.jetbrains.kotlin.test.model.TestModule
|
||||
import org.jetbrains.kotlin.test.services.DefaultsProvider
|
||||
import org.jetbrains.kotlin.test.services.ModuleStructureTransformer
|
||||
import org.jetbrains.kotlin.test.services.TestModuleStructure
|
||||
import org.jetbrains.kotlin.test.services.impl.TestModuleStructureImpl
|
||||
|
||||
/**
|
||||
* This transformer is required for correct work of [getKtModuleFactoryForTestModule][org.jetbrains.kotlin.analysis.test.framework.project.structure.getKtModuleFactoryForTestModule]
|
||||
* to provide correct [DependencyKind] for dependencies
|
||||
*
|
||||
* @see org.jetbrains.kotlin.analysis.test.framework.project.structure.getKtModuleFactoryForTestModule
|
||||
*/
|
||||
@OptIn(TestInfrastructureInternals::class)
|
||||
object DependencyKindModuleStructureTransformer : ModuleStructureTransformer() {
|
||||
override fun transformModuleStructure(moduleStructure: TestModuleStructure, defaultsProvider: DefaultsProvider): TestModuleStructure {
|
||||
if (AnalysisApiTestDirectives.MODULE_KIND !in moduleStructure.allDirectives) return moduleStructure
|
||||
|
||||
val moduleMapping = moduleStructure.modules.associateBy(TestModule::name)
|
||||
return TestModuleStructureImpl(
|
||||
moduleStructure.modules.map { module ->
|
||||
module.copy(
|
||||
allDependencies = module.allDependencies.map { dependency ->
|
||||
transformDependency(dependency, moduleMapping)
|
||||
}
|
||||
)
|
||||
},
|
||||
moduleStructure.originalTestDataFiles,
|
||||
)
|
||||
}
|
||||
|
||||
private fun transformDependency(
|
||||
dependency: DependencyDescription,
|
||||
moduleMapping: Map<String, TestModule>,
|
||||
): DependencyDescription {
|
||||
val dependencyModule = moduleMapping.getValue(dependency.moduleName)
|
||||
val newKind = when (dependencyModule.moduleKind) {
|
||||
TestModuleKind.Source, TestModuleKind.LibrarySource, TestModuleKind.ScriptSource -> DependencyKind.Source
|
||||
TestModuleKind.LibraryBinary -> DependencyKind.Binary
|
||||
// There is no explicit module kind, so the dependency already has the right kind
|
||||
null -> return dependency
|
||||
}
|
||||
|
||||
return dependency.copy(kind = newKind)
|
||||
}
|
||||
}
|
||||
+6
@@ -30,6 +30,12 @@ object AnalysisApiFirLibraryBinaryTestConfigurator : AnalysisApiTestConfigurator
|
||||
override fun configureTest(builder: TestConfigurationBuilder, disposable: Disposable) {
|
||||
builder.apply {
|
||||
useAdditionalService<KtModuleFactory> { KtLibraryBinaryModuleFactory }
|
||||
configureLibraryCompilationSupport(this)
|
||||
}
|
||||
}
|
||||
|
||||
fun configureLibraryCompilationSupport(builder: TestConfigurationBuilder) {
|
||||
builder.apply {
|
||||
useAdditionalService<TestModuleCompiler> { DispatchingTestModuleCompiler() }
|
||||
useAdditionalService<TestModuleDecompiler> { TestModuleDecompilerJar() }
|
||||
}
|
||||
|
||||
+14
-2
@@ -1,13 +1,17 @@
|
||||
/*
|
||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.analysis.low.level.api.fir.test.configurators
|
||||
|
||||
import com.intellij.openapi.Disposable
|
||||
import org.jetbrains.kotlin.analysis.api.impl.base.test.configurators.AnalysisApiLibraryBaseTestServiceRegistrar
|
||||
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.services.DependencyKindModuleStructureTransformer
|
||||
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.AnalysisApiTestServiceRegistrar
|
||||
import org.jetbrains.kotlin.test.TestInfrastructureInternals
|
||||
import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder
|
||||
|
||||
open class AnalysisApiFirSourceTestConfigurator(
|
||||
@@ -18,6 +22,14 @@ open class AnalysisApiFirSourceTestConfigurator(
|
||||
|
||||
builder.apply {
|
||||
useAdditionalService<KtModuleFactory> { KtSourceModuleFactory }
|
||||
|
||||
@OptIn(TestInfrastructureInternals::class)
|
||||
useModuleStructureTransformers(DependencyKindModuleStructureTransformer)
|
||||
}
|
||||
|
||||
AnalysisApiFirLibraryBinaryTestConfigurator.configureLibraryCompilationSupport(builder)
|
||||
}
|
||||
}
|
||||
|
||||
override val serviceRegistrars: List<AnalysisApiTestServiceRegistrar>
|
||||
get() = super.serviceRegistrars + AnalysisApiLibraryBaseTestServiceRegistrar
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user