diff --git a/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/TestInfrastructureInternals.kt b/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/TestInfrastructureInternals.kt new file mode 100644 index 00000000000..81cc3944ae0 --- /dev/null +++ b/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/TestInfrastructureInternals.kt @@ -0,0 +1,14 @@ +/* + * Copyright 2010-2021 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.test + +/** + * This annotation used for marking low-level services of test infrastructure which + * normally should not be used. Please think twice before using something + * marked with this annotation + */ +@RequiresOptIn +annotation class TestInfrastructureInternals diff --git a/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/services/ModuleStructureExtractor.kt b/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/services/ModuleStructureExtractor.kt index c0161f13257..6ac7f7db09a 100644 --- a/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/services/ModuleStructureExtractor.kt +++ b/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/services/ModuleStructureExtractor.kt @@ -5,11 +5,13 @@ package org.jetbrains.kotlin.test.services +import org.jetbrains.kotlin.test.TestInfrastructureInternals import org.jetbrains.kotlin.test.directives.model.DirectivesContainer -abstract class ModuleStructureExtractor( +abstract class ModuleStructureExtractor @OptIn(TestInfrastructureInternals::class) constructor( protected val testServices: TestServices, - protected val additionalSourceProviders: List + protected val additionalSourceProviders: List, + protected val moduleStructureTransformers: List ) { abstract fun splitTestDataByModules( testDataFileName: String, diff --git a/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/services/ModuleStructureTransformer.kt b/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/services/ModuleStructureTransformer.kt new file mode 100644 index 00000000000..ff077417d37 --- /dev/null +++ b/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/services/ModuleStructureTransformer.kt @@ -0,0 +1,13 @@ +/* + * Copyright 2010-2021 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.test.services + +import org.jetbrains.kotlin.test.TestInfrastructureInternals + +@TestInfrastructureInternals +abstract class ModuleStructureTransformer { + abstract fun transformModuleStructure(moduleStructure: TestModuleStructure): TestModuleStructure +} diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/builders/TestConfigurationBuilder.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/builders/TestConfigurationBuilder.kt index 91cbadbe99e..ebc5be27049 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/builders/TestConfigurationBuilder.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/builders/TestConfigurationBuilder.kt @@ -7,12 +7,14 @@ package org.jetbrains.kotlin.test.builders import org.jetbrains.kotlin.test.Constructor import org.jetbrains.kotlin.test.TestConfiguration +import org.jetbrains.kotlin.test.TestInfrastructureInternals import org.jetbrains.kotlin.test.directives.model.DirectivesContainer import org.jetbrains.kotlin.test.impl.TestConfigurationImpl import org.jetbrains.kotlin.test.model.* import org.jetbrains.kotlin.test.services.* @DefaultsDsl +@OptIn(TestInfrastructureInternals::class) class TestConfigurationBuilder { val defaultsProviderBuilder: DefaultsProviderBuilder = DefaultsProviderBuilder() lateinit var assertions: AssertionsService @@ -26,6 +28,7 @@ class TestConfigurationBuilder { private val environmentConfigurators: MutableList> = mutableListOf() private val additionalSourceProviders: MutableList> = mutableListOf() + private val moduleStructureTransformers: MutableList = mutableListOf() private val metaTestConfigurators: MutableList> = mutableListOf() private val afterAnalysisCheckers: MutableList> = mutableListOf() @@ -115,6 +118,11 @@ class TestConfigurationBuilder { additionalSourceProviders += providers } + @TestInfrastructureInternals + fun useModuleStructureTransformers(vararg transformers: ModuleStructureTransformer) { + moduleStructureTransformers += transformers + } + fun useMetaTestConfigurators(vararg configurators: Constructor) { metaTestConfigurators += configurators } @@ -147,6 +155,7 @@ class TestConfigurationBuilder { additionalMetaInfoProcessors, environmentConfigurators, additionalSourceProviders, + moduleStructureTransformers, metaTestConfigurators, afterAnalysisCheckers, metaInfoHandlerEnabled, diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/impl/TestConfigurationImpl.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/impl/TestConfigurationImpl.kt index 1af0b7c00c3..3ab89227f97 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/impl/TestConfigurationImpl.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/impl/TestConfigurationImpl.kt @@ -8,6 +8,7 @@ package org.jetbrains.kotlin.test.impl import com.intellij.openapi.Disposable import org.jetbrains.kotlin.test.Constructor import org.jetbrains.kotlin.test.TestConfiguration +import org.jetbrains.kotlin.test.TestInfrastructureInternals import org.jetbrains.kotlin.test.directives.model.ComposedDirectivesContainer import org.jetbrains.kotlin.test.directives.model.DirectivesContainer import org.jetbrains.kotlin.test.directives.model.RegisteredDirectives @@ -16,6 +17,7 @@ import org.jetbrains.kotlin.test.services.* import org.jetbrains.kotlin.test.services.impl.ModuleStructureExtractorImpl import org.jetbrains.kotlin.test.utils.TestDisposable +@OptIn(TestInfrastructureInternals::class) class TestConfigurationImpl( testInfo: KotlinTestInfo, @@ -31,6 +33,7 @@ class TestConfigurationImpl( environmentConfigurators: List>, additionalSourceProviders: List>, + moduleStructureTransformers: List, metaTestConfigurators: List>, afterAnalysisCheckers: List>, @@ -70,6 +73,7 @@ class TestConfigurationImpl( additionalSourceProviders.map { it.invoke(testServices) }.also { it.flatMapTo(allDirectives) { provider -> provider.directives } }, + moduleStructureTransformers, this.environmentConfigurators ) diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/services/impl/ModuleStructureExtractorImpl.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/services/impl/ModuleStructureExtractorImpl.kt index 2cd06f5fbad..517d2fa470f 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/services/impl/ModuleStructureExtractorImpl.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/services/impl/ModuleStructureExtractorImpl.kt @@ -13,6 +13,7 @@ import org.jetbrains.kotlin.platform.jvm.JvmPlatforms import org.jetbrains.kotlin.platform.konan.NativePlatforms import org.jetbrains.kotlin.test.Assertions import org.jetbrains.kotlin.test.TargetBackend +import org.jetbrains.kotlin.test.TestInfrastructureInternals import org.jetbrains.kotlin.test.builders.LanguageVersionSettingsBuilder import org.jetbrains.kotlin.test.directives.AdditionalFilesDirectives import org.jetbrains.kotlin.test.directives.ModuleStructureDirectives @@ -35,11 +36,13 @@ import java.io.File * - All directives between `MODULE` and `FILE` directives belongs to module * - All directives before first `MODULE` are global and belongs to each declared module */ +@OptIn(TestInfrastructureInternals::class) class ModuleStructureExtractorImpl( testServices: TestServices, additionalSourceProviders: List, + moduleStructureTransformers: List, private val environmentConfigurators: List -) : ModuleStructureExtractor(testServices, additionalSourceProviders) { +) : ModuleStructureExtractor(testServices, additionalSourceProviders, moduleStructureTransformers) { companion object { private val allowedExtensionsForFiles = listOf(".kt", ".kts", ".java") @@ -57,7 +60,11 @@ class ModuleStructureExtractorImpl( ): TestModuleStructure { val testDataFile = File(testDataFileName) val extractor = ModuleStructureExtractorWorker(listOf(testDataFile), directivesContainer) - return extractor.splitTestDataByModules() + var result = extractor.splitTestDataByModules() + for (transformer in moduleStructureTransformers) { + result = transformer.transformModuleStructure(result) + } + return result } private inner class ModuleStructureExtractorWorker constructor(