From a66f3d26fdcfe9d352c7518860f7d71215352f57 Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Tue, 20 Jul 2021 16:54:37 +0300 Subject: [PATCH] [Test] Replace three fixed phases of tests with step system Now each test is just a sequence of any number of different steps. There are two kinds of steps: 1. Run some facade 2. Run handlers of specific artifact kind Through the test each module passed to each step (if it is compatible by kinds of artifacts) --- .../tests/CodegenTestsOnAndroidGenerator.kt | 2 + .../kotlin/test/TestConfiguration.kt | 19 +- .../org/jetbrains/kotlin/test/TestRunner.kt | 206 ++++++------------ .../org/jetbrains/kotlin/test/TestStep.kt | 84 +++++++ .../jetbrains/kotlin/test/TestStepBuilder.kt | 41 ++++ .../jetbrains/kotlin/test/WrappedException.kt | 14 +- .../jetbrains/kotlin/test/model/Facades.kt | 18 +- .../test/builders/CompilerTestDslHelpers.kt | 121 ++++++++++ .../test/builders/TestConfigurationBuilder.kt | 79 ++++--- .../kotlin/test/builders/TestPathMatcher.kt | 7 - .../frontend/fir/FirFailingTestSuppressor.kt | 9 +- .../kotlin/test/impl/TestConfigurationImpl.kt | 109 +++------ .../test/runners/AbstractDiagnosticTest.kt | 21 +- .../runners/AbstractDiagnosticsNativeTest.kt | 14 +- .../AbstractDiagnosticsTestWithJsStdLib.kt | 16 +- .../AbstractDiagnosticsTestWithJvmBackend.kt | 62 ++++-- .../test/runners/AbstractFirDiagnosticTest.kt | 30 ++- .../runners/AbstractForeignAnnotationsTest.kt | 20 +- .../runners/AbstractKotlinCompilerTest.kt | 2 + .../codegen/AbstractBlackBoxCodegenTest.kt | 7 +- .../codegen/AbstractBytecodeListingTest.kt | 34 +-- .../codegen/AbstractBytecodeTextTest.kt | 37 ++-- ...actCompileKotlinAgainstInlineKotlinTest.kt | 23 +- ...nAgainstKotlinWithDifferentBackendsTest.kt | 62 +++--- .../codegen/AbstractFirBlackBoxCodegenTest.kt | 26 ++- .../codegen/AbstractIrBlackBoxCodegenTest.kt | 9 +- .../AbstractJvmBlackBoxCodegenTestBase.kt | 41 +++- .../codegen/AbstractJvmIrAgainstOldBoxTest.kt | 53 ++--- .../codegen/BaseCodegenConfiguration.kt | 143 +++++++++--- .../test/runners/ir/AbstractIrTextTest.kt | 71 ++++-- .../AbstractIrInterpreterAfterFir2IrTest.kt | 28 ++- .../AbstractVisualizerBlackBoxTest.kt | 25 +-- .../visualizer/AbstractVisualizerTest.kt | 11 +- .../based/AbstractCompilerBasedTest.kt | 3 +- ...stractDiagnosisCompilerTestDataSpecTest.kt | 4 +- .../AbstractDiagnosisCompilerTestDataTest.kt | 4 +- .../api/test/base/AbstractLowLevelApiTest.kt | 4 +- 37 files changed, 900 insertions(+), 559 deletions(-) create mode 100644 compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/TestStep.kt create mode 100644 compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/TestStepBuilder.kt create mode 100644 compiler/tests-common-new/tests/org/jetbrains/kotlin/test/builders/CompilerTestDslHelpers.kt delete mode 100644 compiler/tests-common-new/tests/org/jetbrains/kotlin/test/builders/TestPathMatcher.kt diff --git a/compiler/android-tests/tests/org/jetbrains/kotlin/android/tests/CodegenTestsOnAndroidGenerator.kt b/compiler/android-tests/tests/org/jetbrains/kotlin/android/tests/CodegenTestsOnAndroidGenerator.kt index eb40b47abeb..cf33de24132 100644 --- a/compiler/android-tests/tests/org/jetbrains/kotlin/android/tests/CodegenTestsOnAndroidGenerator.kt +++ b/compiler/android-tests/tests/org/jetbrains/kotlin/android/tests/CodegenTestsOnAndroidGenerator.kt @@ -23,6 +23,7 @@ import org.jetbrains.kotlin.test.* import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder import org.jetbrains.kotlin.test.model.DependencyKind import org.jetbrains.kotlin.test.model.FrontendKinds +import org.jetbrains.kotlin.test.model.ResultingArtifact import org.jetbrains.kotlin.test.runners.AbstractKotlinCompilerTest import org.jetbrains.kotlin.test.services.* import org.jetbrains.kotlin.test.services.configuration.CommonEnvironmentConfigurator @@ -382,6 +383,7 @@ class CodegenTestsOnAndroidGenerator private constructor(private val pathManager "test${testDataFile.nameWithoutExtension.replaceFirstChar(Char::uppercaseChar)}", emptySet() ) + startingArtifactFactory = { ResultingArtifact.Source() } }.build(testDataFile.path) } diff --git a/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/TestConfiguration.kt b/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/TestConfiguration.kt index f650fbdfb4f..f5a459b0008 100644 --- a/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/TestConfiguration.kt +++ b/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/TestConfiguration.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ @@ -8,7 +8,9 @@ package org.jetbrains.kotlin.test import com.intellij.openapi.Disposable import org.jetbrains.kotlin.test.directives.model.DirectivesContainer import org.jetbrains.kotlin.test.directives.model.RegisteredDirectives -import org.jetbrains.kotlin.test.model.* +import org.jetbrains.kotlin.test.model.AfterAnalysisChecker +import org.jetbrains.kotlin.test.model.ResultingArtifact +import org.jetbrains.kotlin.test.model.TestModule import org.jetbrains.kotlin.test.services.MetaTestConfigurator import org.jetbrains.kotlin.test.services.ModuleStructureExtractor import org.jetbrains.kotlin.test.services.PreAnalysisHandler @@ -33,16 +35,11 @@ abstract class TestConfiguration { abstract val afterAnalysisCheckers: List + abstract val startingArtifactFactory: (TestModule) -> ResultingArtifact<*> + + abstract val steps: List> + abstract val metaInfoHandlerEnabled: Boolean - - abstract fun , O : ResultingArtifact> getFacade( - inputKind: TestArtifactKind, - outputKind: TestArtifactKind - ): AbstractTestFacade - - abstract fun > getHandlers(artifactKind: TestArtifactKind): List> - - abstract fun getAllHandlers(): List> } // ---------------------------- Utils ---------------------------- diff --git a/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/TestRunner.kt b/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/TestRunner.kt index 0e917e268b6..74f9a786651 100644 --- a/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/TestRunner.kt +++ b/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/TestRunner.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ @@ -7,13 +7,22 @@ package org.jetbrains.kotlin.test import com.intellij.openapi.util.Disposer import com.intellij.testFramework.TestDataFile -import org.jetbrains.kotlin.test.model.* +import org.jetbrains.kotlin.test.model.AnalysisHandler +import org.jetbrains.kotlin.test.model.ResultingArtifact +import org.jetbrains.kotlin.test.model.TestModule import org.jetbrains.kotlin.test.services.* import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull import java.io.IOException class TestRunner(private val testConfiguration: TestConfiguration) { - private val failedAssertions = mutableListOf() + companion object { + fun AnalysisHandler<*>.shouldRun(thereWasAnException: Boolean): Boolean { + return !(doNotRunIfThereWerePreviousFailures && thereWasAnException) + } + } + + private val allFailedExceptions = mutableListOf() + private val allRanHandlers = mutableSetOf>() fun runTest(@TestDataFile testDataFileName: String, beforeDispose: (TestConfiguration) -> Unit = {}) { try { @@ -68,27 +77,15 @@ class TestRunner(private val testConfiguration: TestConfiguration) { preprocessor.preprocessModuleStructure(moduleStructure) } - var failedException: WrappedException? = null - try { - for (module in modules) { - val shouldProcessNextModules = processModule(services, module, dependencyProvider, moduleStructure) - if (!shouldProcessNextModules) break - } - } catch (e: WrappedException) { - failedException = e - } catch (e: Exception) { - throw IllegalStateException("Unexpected exception type. Only WrappedException are expected here", e) + for (module in modules) { + val shouldProcessNextModules = processModule(module, dependencyProvider) + if (!shouldProcessNextModules) break } - for (handler in testConfiguration.getAllHandlers()) { - val wrapperFactory = when (handler) { - is FrontendOutputHandler -> WrappedException::FromFrontendHandler - is BackendInputHandler -> WrappedException::FromBackendHandler - is BinaryArtifactHandler -> WrappedException::FromBinaryHandler - else -> WrappedException::FromUnknownHandler - } + for (handler in allRanHandlers) { + val wrapperFactory: (Throwable) -> WrappedException = { WrappedException.FromHandler(it, handler) } withAssertionCatching(wrapperFactory) { - val thereWasAnException = failedException != null || failedAssertions.isNotEmpty() + val thereWasAnException = allFailedExceptions.isNotEmpty() if (handler.shouldRun(thereWasAnException)) { handler.processAfterAllModules(thereWasAnException) } @@ -99,100 +96,56 @@ class TestRunner(private val testConfiguration: TestConfiguration) { globalMetadataInfoHandler.compareAllMetaDataInfos() } } - if (failedException != null) { - failedAssertions.add(0, failedException) - } testConfiguration.afterAnalysisCheckers.forEach { withAssertionCatching(WrappedException::FromAfterAnalysisChecker) { - it.check(failedAssertions) + it.check(allFailedExceptions) } } - val filteredFailedAssertions = filterFailedExceptions(failedAssertions) + val filteredFailedAssertions = filterFailedExceptions(allFailedExceptions) filteredFailedAssertions.firstIsInstanceOrNull()?.let { throw it } services.assertions.assertAll(filteredFailedAssertions) } - private fun filterFailedExceptions(failedExceptions: List): List { - return testConfiguration.afterAnalysisCheckers - .fold(failedExceptions) { assertions, checker -> - checker.suppressIfNeeded(assertions) - } - .sorted() - .map { it.cause } - } - /* - * If there was failure from handler with `failureDisablesNextSteps=true` then `processModule` - * returns false which indicates that other modules should not be processed + * Returns false if next modules should be not processed */ private fun processModule( - services: TestServices, module: TestModule, - dependencyProvider: DependencyProviderImpl, - moduleStructure: TestModuleStructure + dependencyProvider: DependencyProviderImpl ): Boolean { - val sourcesArtifact = ResultingArtifact.Source() + var inputArtifact = testConfiguration.startingArtifactFactory.invoke(module) - val frontendKind = module.frontendKind - if (!frontendKind.shouldRunAnalysis) return true + for (step in testConfiguration.steps) { + if (!step.shouldProcessModule(module, inputArtifact)) continue - val frontendArtifacts: ResultingArtifact.FrontendOutput<*> = withExceptionWrapping(WrappedException.FromFacade::Frontend) { - testConfiguration.getFacade(SourcesKind, frontendKind) - .transform(module, sourcesArtifact)?.also { dependencyProvider.registerArtifact(module, it) } - ?: return true - } - val frontendHandlers: List> = testConfiguration.getHandlers(frontendKind) - for (frontendHandler in frontendHandlers) { - val thereWasAnException = withAssertionCatching(WrappedException::FromFrontendHandler) { - if (frontendHandler.shouldRun(failedAssertions.isNotEmpty())) { - frontendHandler.hackyProcess(module, frontendArtifacts) + when (val result = step.hackyProcessModule(module, inputArtifact, allFailedExceptions.isNotEmpty())) { + is TestStep.StepResult.Artifact<*> -> { + require(step is TestStep.FacadeStep<*, *>) + if (step.inputArtifactKind != step.outputArtifactKind) { + dependencyProvider.registerArtifact(module, result.outputArtifact) + } + inputArtifact = result.outputArtifact } - } - if (thereWasAnException && frontendHandler.failureDisablesNextSteps) return false - } - - val backendKind = services.backendKindExtractor.backendKind(module.targetBackend) - if (!backendKind.shouldRunAnalysis) return true - - val backendInputInfo = withExceptionWrapping(WrappedException.FromFacade::Converter) { - testConfiguration.getFacade(frontendKind, backendKind) - .hackyTransform(module, frontendArtifacts)?.also { dependencyProvider.registerArtifact(module, it) } ?: return true - } - - val backendHandlers: List> = testConfiguration.getHandlers(backendKind) - for (backendHandler in backendHandlers) { - val thereWasAnException = withAssertionCatching(WrappedException::FromBackendHandler) { - if (backendHandler.shouldRun(failedAssertions.isNotEmpty())) { - backendHandler.hackyProcess(module, backendInputInfo) + is TestStep.StepResult.ErrorFromFacade -> { + allFailedExceptions += result.exception + return false } - } - if (thereWasAnException && backendHandler.failureDisablesNextSteps) return false - } - - for (artifactKind in moduleStructure.getTargetArtifactKinds(module)) { - if (!artifactKind.shouldRunAnalysis) continue - val binaryArtifact = withExceptionWrapping(WrappedException.FromFacade::Backend) { - testConfiguration.getFacade(backendKind, artifactKind) - .hackyTransform(module, backendInputInfo)?.also { - dependencyProvider.registerArtifact(module, it) - } ?: return true - } - - val binaryHandlers: List> = testConfiguration.getHandlers(artifactKind) - for (binaryHandler in binaryHandlers) { - val thereWasAnException = withAssertionCatching(WrappedException::FromBinaryHandler) { - if (binaryHandler.shouldRun(failedAssertions.isNotEmpty())) { - binaryHandler.hackyProcess(module, binaryArtifact) + is TestStep.StepResult.HandlersResult -> { + val (exceptionsFromHandlers, shouldRunNextSteps) = result + require(step is TestStep.HandlersStep<*>) + allRanHandlers += step.handlers + allFailedExceptions += exceptionsFromHandlers + if (!shouldRunNextSteps) { + return false } } - if (thereWasAnException && binaryHandler.failureDisablesNextSteps) return false + is TestStep.StepResult.NoArtifactFromFacade -> return false } } - return true } @@ -204,57 +157,38 @@ class TestRunner(private val testConfiguration: TestConfiguration) { block() false } catch (e: Throwable) { - failedAssertions += exceptionWrapper(e) + allFailedExceptions += exceptionWrapper(e) true } } - private inline fun withExceptionWrapping(exceptionWrapper: (Throwable) -> WrappedException, block: () -> R): R { - return try { - block() - } catch (e: Throwable) { - throw exceptionWrapper(e) - } + private fun filterFailedExceptions(failedExceptions: List): List { + return testConfiguration.afterAnalysisCheckers + .fold(failedExceptions) { assertions, checker -> + checker.suppressIfNeeded(assertions) + } + .sorted() + .map { it.cause } } - private fun AnalysisHandler<*>.shouldRun(thereWasAnException: Boolean): Boolean { - return !(doNotRunIfThereWerePreviousFailures && thereWasAnException) + // -------------------------------------- hacks -------------------------------------- + + private fun TestStep<*, *>.hackyProcessModule( + module: TestModule, + inputArtifact: ResultingArtifact<*>, + thereWereExceptionsOnPreviousSteps: Boolean + ): TestStep.StepResult<*> { + @Suppress("UNCHECKED_CAST") + return (this as TestStep) + .processModule(module, inputArtifact as ResultingArtifact, thereWereExceptionsOnPreviousSteps) + } + + private fun > TestStep.processModule( + module: TestModule, + artifact: ResultingArtifact, + thereWereExceptionsOnPreviousSteps: Boolean + ): TestStep.StepResult<*> { + @Suppress("UNCHECKED_CAST") + return processModule(module, artifact as I, thereWereExceptionsOnPreviousSteps) } } - -// ---------------------------------------------------------------------------------------------------------------- -/* - * Those `hackyProcess` methods are needed to hack kotlin type system. In common test case - * we have artifact of type ResultingArtifact<*> and handler of type AnalysisHandler<*> and actually - * at runtime types under `*` are same (that achieved by grouping handlers and facades by - * frontend/backend/artifact kind). But there is no way to tell that to compiler, so I unsafely cast types with `*` - * to types with Empty artifacts to make it compile. Since unsafe cast has no effort at runtime, it's safe to use it - */ - -private fun AnalysisHandler<*>.hackyProcess(module: TestModule, artifact: ResultingArtifact<*>) { - @Suppress("UNCHECKED_CAST") - (this as AnalysisHandler) - .processModule(module, artifact as ResultingArtifact) -} - -private fun > AnalysisHandler.processModule(module: TestModule, artifact: ResultingArtifact) { - @Suppress("UNCHECKED_CAST") - processModule(module, artifact as A) -} - -private fun AbstractTestFacade<*, *>.hackyTransform( - module: TestModule, - artifact: ResultingArtifact<*> -): ResultingArtifact<*>? { - @Suppress("UNCHECKED_CAST") - return (this as AbstractTestFacade) - .transform(module, artifact as ResultingArtifact) -} - -private fun , O : ResultingArtifact> AbstractTestFacade.transform( - module: TestModule, - inputArtifact: ResultingArtifact -): O? { - @Suppress("UNCHECKED_CAST") - return transform(module, inputArtifact as I) -} diff --git a/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/TestStep.kt b/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/TestStep.kt new file mode 100644 index 00000000000..c86a266d5f9 --- /dev/null +++ b/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/TestStep.kt @@ -0,0 +1,84 @@ +/* + * 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 + +import org.jetbrains.kotlin.test.TestRunner.Companion.shouldRun +import org.jetbrains.kotlin.test.model.* + +sealed class TestStep, out O : ResultingArtifact> { + abstract val inputArtifactKind: TestArtifactKind + + open fun shouldProcessModule(module: TestModule, inputArtifact: ResultingArtifact<*>): Boolean { + return inputArtifact.kind == inputArtifactKind + } + + abstract fun processModule(module: TestModule, inputArtifact: I, thereWereExceptionsOnPreviousSteps: Boolean): StepResult + + class FacadeStep, O : ResultingArtifact>(val facade: AbstractTestFacade) : TestStep() { + override val inputArtifactKind: TestArtifactKind + get() = facade.inputKind + + val outputArtifactKind: TestArtifactKind + get() = facade.outputKind + + override fun shouldProcessModule(module: TestModule, inputArtifact: ResultingArtifact<*>): Boolean { + return super.shouldProcessModule(module, inputArtifact) && facade.shouldRunAnalysis(module) + } + + override fun processModule(module: TestModule, inputArtifact: I, thereWereExceptionsOnPreviousSteps: Boolean): StepResult { + val outputArtifact = try { + facade.transform(module, inputArtifact) ?: return StepResult.NoArtifactFromFacade + } catch (e: Throwable) { + // TODO: remove inheritors of WrappedException.FromFacade + return StepResult.ErrorFromFacade(WrappedException.FromFacade(e, facade)) + } + return StepResult.Artifact(outputArtifact) + } + } + + class HandlersStep>( + override val inputArtifactKind: TestArtifactKind, + val handlers: List> + ) : TestStep() { + init { + require(handlers.all { it.artifactKind == inputArtifactKind }) + } + + override fun processModule( + module: TestModule, + inputArtifact: I, + thereWereExceptionsOnPreviousSteps: Boolean + ): StepResult.HandlersResult { + val exceptions = mutableListOf() + for (outputHandler in handlers) { + if (outputHandler.shouldRun(thereWasAnException = thereWereExceptionsOnPreviousSteps || exceptions.isNotEmpty())) { + try { + outputHandler.processModule(module, inputArtifact) + } catch (e: Throwable) { + exceptions += WrappedException.FromHandler(e, outputHandler) + if (outputHandler.failureDisablesNextSteps) { + return StepResult.HandlersResult(exceptions, shouldRunNextSteps = false) + } + } + } + } + return StepResult.HandlersResult(exceptions, shouldRunNextSteps = true) + } + } + + sealed class StepResult> { + class Artifact>(val outputArtifact: O, ) : StepResult() + class ErrorFromFacade>(val exception: WrappedException) : StepResult() + data class HandlersResult( + val exceptionsFromHandlers: Collection, + val shouldRunNextSteps: Boolean + ) : StepResult() + + object NoArtifactFromFacade : StepResult() + } +} + + diff --git a/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/TestStepBuilder.kt b/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/TestStepBuilder.kt new file mode 100644 index 00000000000..71b471f83ee --- /dev/null +++ b/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/TestStepBuilder.kt @@ -0,0 +1,41 @@ +/* + * 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 + +import org.jetbrains.kotlin.test.model.* +import org.jetbrains.kotlin.test.services.TestServices + +sealed class TestStepBuilder, out O : ResultingArtifact> { + @TestInfrastructureInternals + abstract fun createTestStep(testServices: TestServices): TestStep +} + + +class FacadeStepBuilder, O : ResultingArtifact>( + val facade: Constructor> +) : TestStepBuilder() { + @TestInfrastructureInternals + override fun createTestStep(testServices: TestServices): TestStep.FacadeStep { + return TestStep.FacadeStep(facade.invoke(testServices)) + } +} + +class HandlersStepBuilder>(val artifactKind: TestArtifactKind) : TestStepBuilder() { + private val handlers: MutableList>> = mutableListOf() + + fun useHandlers(vararg constructor: Constructor>) { + handlers += constructor + } + + fun useHandlers(constructors: List>>) { + handlers += constructors + } + + @TestInfrastructureInternals + override fun createTestStep(testServices: TestServices): TestStep.HandlersStep { + return TestStep.HandlersStep(artifactKind, handlers.map { it.invoke(testServices) }) + } +} diff --git a/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/WrappedException.kt b/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/WrappedException.kt index a0834d90dbb..022a08622eb 100644 --- a/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/WrappedException.kt +++ b/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/WrappedException.kt @@ -5,26 +5,22 @@ package org.jetbrains.kotlin.test +import org.jetbrains.kotlin.test.model.AbstractTestFacade +import org.jetbrains.kotlin.test.model.AnalysisHandler + sealed class WrappedException( cause: Throwable, val priority: Int, val additionalPriority: Int ) : Exception(cause), Comparable { - sealed class FromFacade(cause: Throwable, additionalPriority: Int) : WrappedException(cause, 0, additionalPriority) { - class Frontend(cause: Throwable) : FromFacade(cause, 1) - class Converter(cause: Throwable) : FromFacade(cause, 2) - class Backend(cause: Throwable) : FromFacade(cause, 3) - + class FromFacade(cause: Throwable, val facade: AbstractTestFacade<*, *>) : WrappedException(cause, 0, 1) { override val message: String get() = "Exception was thrown" } class FromMetaInfoHandler(cause: Throwable) : WrappedException(cause, 1, 1) - class FromFrontendHandler(cause: Throwable) : WrappedException(cause, 1, 1) - class FromBackendHandler(cause: Throwable) : WrappedException(cause, 1, 2) - class FromBinaryHandler(cause: Throwable) : WrappedException(cause, 1, 3) - class FromUnknownHandler(cause: Throwable) : WrappedException(cause, 1, 4) + class FromHandler(cause: Throwable, val handler: AnalysisHandler<*>) : WrappedException(cause, 1, 2) class FromAfterAnalysisChecker(cause: Throwable) : WrappedException(cause, 2, 1) diff --git a/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/model/Facades.kt b/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/model/Facades.kt index 8066d86a1cf..a743d97cd48 100644 --- a/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/model/Facades.kt +++ b/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/model/Facades.kt @@ -8,6 +8,7 @@ package org.jetbrains.kotlin.test.model import org.jetbrains.kotlin.test.directives.model.DirectivesContainer import org.jetbrains.kotlin.test.services.ServiceRegistrationData import org.jetbrains.kotlin.test.services.TestServices +import org.jetbrains.kotlin.test.services.backendKindExtractor interface ServicesAndDirectivesContainer { val additionalServices: List @@ -22,6 +23,7 @@ abstract class AbstractTestFacade, O : ResultingArtifac abstract val outputKind: TestArtifactKind abstract fun transform(module: TestModule, inputArtifact: I): O? + abstract fun shouldRunAnalysis(module: TestModule): Boolean } abstract class FrontendFacade>( @@ -31,6 +33,10 @@ abstract class FrontendFacade>( final override val inputKind: TestArtifactKind get() = SourcesKind + override fun shouldRunAnalysis(module: TestModule): Boolean { + return module.frontendKind == outputKind + } + abstract fun analyze(module: TestModule): R final override fun transform(module: TestModule, inputArtifact: ResultingArtifact.Source): R { @@ -43,10 +49,18 @@ abstract class Frontend2BackendConverter val testServices: TestServices, final override val inputKind: FrontendKind, final override val outputKind: BackendKind -) : AbstractTestFacade() +) : AbstractTestFacade() { + override fun shouldRunAnalysis(module: TestModule): Boolean { + return testServices.backendKindExtractor.backendKind(module.targetBackend) == outputKind + } +} abstract class BackendFacade, A : ResultingArtifact.Binary>( val testServices: TestServices, final override val inputKind: BackendKind, final override val outputKind: BinaryKind -) : AbstractTestFacade() +) : AbstractTestFacade() { + override fun shouldRunAnalysis(module: TestModule): Boolean { + return testServices.backendKindExtractor.backendKind(module.targetBackend) == inputKind && module.binaryKind == outputKind + } +} diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/builders/CompilerTestDslHelpers.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/builders/CompilerTestDslHelpers.kt new file mode 100644 index 00000000000..b7ac916da65 --- /dev/null +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/builders/CompilerTestDslHelpers.kt @@ -0,0 +1,121 @@ +/* + * 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.builders + +import org.jetbrains.kotlin.test.HandlersStepBuilder +import org.jetbrains.kotlin.test.backend.classic.ClassicJvmBackendFacade +import org.jetbrains.kotlin.test.backend.ir.IrBackendInput +import org.jetbrains.kotlin.test.backend.ir.JvmIrBackendFacade +import org.jetbrains.kotlin.test.builders.CompilerStepsNames.CLASSIC_FRONTEND_HANDLERS_STEP_NAME +import org.jetbrains.kotlin.test.builders.CompilerStepsNames.FIR_HANDLERS_STEP_NAME +import org.jetbrains.kotlin.test.builders.CompilerStepsNames.JVM_ARTIFACTS_HANDLERS_STEP_NAME +import org.jetbrains.kotlin.test.builders.CompilerStepsNames.RAW_IR_HANDLERS_STEP_NAME +import org.jetbrains.kotlin.test.frontend.classic.ClassicFrontend2ClassicBackendConverter +import org.jetbrains.kotlin.test.frontend.classic.ClassicFrontend2IrConverter +import org.jetbrains.kotlin.test.frontend.classic.ClassicFrontendFacade +import org.jetbrains.kotlin.test.frontend.classic.ClassicFrontendOutputArtifact +import org.jetbrains.kotlin.test.frontend.fir.Fir2IrResultsConverter +import org.jetbrains.kotlin.test.frontend.fir.FirFrontendFacade +import org.jetbrains.kotlin.test.frontend.fir.FirOutputArtifact +import org.jetbrains.kotlin.test.model.ArtifactKinds +import org.jetbrains.kotlin.test.model.BackendKinds +import org.jetbrains.kotlin.test.model.BinaryArtifacts +import org.jetbrains.kotlin.test.model.FrontendKinds + +object CompilerStepsNames { + const val FRONTEND_STEP_NAME = "frontend" + const val CLASSIC_FRONTEND_HANDLERS_STEP_NAME = "classic frontend handlers" + const val FIR_HANDLERS_STEP_NAME = "FIR frontend handlers" + + const val CONVERTER_STEP_NAME = "converter" + const val RAW_IR_HANDLERS_STEP_NAME = "raw IR handlers" + + const val JVM_BACKEND_STEP_NAME = "jvm backend" + const val JVM_ARTIFACTS_HANDLERS_STEP_NAME = "jvm artifacts handlers" + +} + +// --------------------- default compiler steps --------------------- + +fun TestConfigurationBuilder.classicFrontendStep() { + facadeStep(::ClassicFrontendFacade) +} + +fun TestConfigurationBuilder.firFrontendStep() { + facadeStep(::FirFrontendFacade) +} + +fun TestConfigurationBuilder.psi2ClassicBackendStep() { + facadeStep(::ClassicFrontend2ClassicBackendConverter) +} + +fun TestConfigurationBuilder.psi2IrStep() { + facadeStep(::ClassicFrontend2IrConverter) +} + +fun TestConfigurationBuilder.fir2IrStep() { + facadeStep(::Fir2IrResultsConverter) +} + +fun TestConfigurationBuilder.classicJvmBackendStep() { + facadeStep(::ClassicJvmBackendFacade) +} + +fun TestConfigurationBuilder.jvmIrBackendStep() { + facadeStep(::JvmIrBackendFacade) +} + +// --------------------- default handlers steps --------------------- + +// use those ones to define new step +inline fun TestConfigurationBuilder.classicFrontendHandlersStep( + init: HandlersStepBuilder.() -> Unit = {} +) { + namedHandlersStep(CLASSIC_FRONTEND_HANDLERS_STEP_NAME, FrontendKinds.ClassicFrontend, init) +} + +inline fun TestConfigurationBuilder.firHandlersStep( + init: HandlersStepBuilder.() -> Unit = {} +) { + namedHandlersStep(FIR_HANDLERS_STEP_NAME, FrontendKinds.FIR, init) +} + +inline fun TestConfigurationBuilder.irHandlersStep( + init: HandlersStepBuilder.() -> Unit = {} +) { + namedHandlersStep(RAW_IR_HANDLERS_STEP_NAME, BackendKinds.IrBackend, init) +} + +inline fun TestConfigurationBuilder.jvmArtifactsHandlersStep( + init: HandlersStepBuilder.() -> Unit = {} +) { + namedHandlersStep(JVM_ARTIFACTS_HANDLERS_STEP_NAME, ArtifactKinds.Jvm, init) +} + +// and those ones to configure already defined step +inline fun TestConfigurationBuilder.configureClassicFrontendHandlersStep( + init: HandlersStepBuilder.() -> Unit = {} +) { + configureNamedHandlersStep(CLASSIC_FRONTEND_HANDLERS_STEP_NAME, FrontendKinds.ClassicFrontend, init) +} + +inline fun TestConfigurationBuilder.configureFirHandlersStep( + init: HandlersStepBuilder.() -> Unit = {} +) { + configureNamedHandlersStep(FIR_HANDLERS_STEP_NAME, FrontendKinds.FIR, init) +} + +inline fun TestConfigurationBuilder.configureIrHandlersStep( + init: HandlersStepBuilder.() -> Unit = {} +) { + configureNamedHandlersStep(RAW_IR_HANDLERS_STEP_NAME, BackendKinds.IrBackend, init) +} + +inline fun TestConfigurationBuilder.configureJvmArtifactsHandlersStep( + init: HandlersStepBuilder.() -> Unit = {} +) { + configureNamedHandlersStep(JVM_ARTIFACTS_HANDLERS_STEP_NAME, ArtifactKinds.Jvm, init) +} 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 a2fbaf1865d..a223fe66091 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 @@ -6,9 +6,8 @@ package org.jetbrains.kotlin.test.builders 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.fir.PrivateForInline +import org.jetbrains.kotlin.test.* import org.jetbrains.kotlin.test.directives.model.DirectivesContainer import org.jetbrains.kotlin.test.impl.TestConfigurationImpl import org.jetbrains.kotlin.test.model.* @@ -16,14 +15,16 @@ import org.jetbrains.kotlin.test.services.* import kotlin.io.path.Path @DefaultsDsl -@OptIn(TestInfrastructureInternals::class) +@OptIn(TestInfrastructureInternals::class, PrivateForInline::class) class TestConfigurationBuilder { val defaultsProviderBuilder: DefaultsProviderBuilder = DefaultsProviderBuilder() lateinit var assertions: AssertionsService - private val facades: MutableList>> = mutableListOf() + @PrivateForInline + val steps: MutableList> = mutableListOf() - private val handlers: MutableList>> = mutableListOf() + @PrivateForInline + val namedSteps: MutableMap> = mutableMapOf() private val sourcePreprocessors: MutableList> = mutableListOf() private val additionalMetaInfoProcessors: MutableList> = mutableListOf() @@ -50,6 +51,8 @@ class TestConfigurationBuilder { lateinit var testInfo: KotlinTestInfo + lateinit var startingArtifactFactory: (TestModule) -> ResultingArtifact<*> + inline fun useAdditionalService(noinline serviceConstructor: (TestServices) -> T) { useAdditionalService(service(serviceConstructor)) } @@ -89,32 +92,47 @@ class TestConfigurationBuilder { defaultsProviderBuilder.apply(init) } - fun unregisterAllFacades() { - facades.clear() + fun , O : ResultingArtifact> facadeStep( + facade: Constructor>, + ): FacadeStepBuilder { + return FacadeStepBuilder(facade).also { + steps += it + } } - fun useFrontendFacades(vararg constructor: Constructor>) { - facades += constructor + inline fun > handlersStep( + artifactKind: TestArtifactKind, + init: HandlersStepBuilder.() -> Unit + ): HandlersStepBuilder { + return HandlersStepBuilder(artifactKind).also { + it.init() + steps += it + } } - fun useBackendFacades(vararg constructor: Constructor>) { - facades += constructor + inline fun > namedHandlersStep( + name: String, + artifactKind: TestArtifactKind, + init: HandlersStepBuilder.() -> Unit + ): HandlersStepBuilder { + val step = handlersStep(artifactKind, init) + val previouslyContainedStep = namedSteps.put(name, step) + if (previouslyContainedStep != null) { + error { "Step with name \"$name\" already registered" } + } + return step } - fun useFrontend2BackendConverters(vararg constructor: Constructor>) { - facades += constructor - } - - fun useFrontendHandlers(vararg constructor: Constructor>) { - handlers += constructor - } - - fun useBackendHandlers(vararg constructor: Constructor>) { - handlers += constructor - } - - fun useArtifactsHandlers(vararg constructor: Constructor>) { - handlers += constructor + inline fun > configureNamedHandlersStep( + name: String, + artifactKind: TestArtifactKind, + init: HandlersStepBuilder.() -> Unit + ) { + val step = namedSteps[name] ?: error { "Step \"$name\" not found" } + require(step is HandlersStepBuilder<*>) { "Step '$name' is not a handlers step" } + require(step.artifactKind == artifactKind) { "Step kind: ${step.artifactKind}, passed kind is $artifactKind" } + @Suppress("UNCHECKED_CAST") + (step as HandlersStepBuilder).apply(init) } fun useSourcePreprocessor(vararg preprocessors: Constructor, needToPrepend: Boolean = false) { @@ -145,6 +163,11 @@ class TestConfigurationBuilder { additionalSourceProviders += providers } + @TestInfrastructureInternals + fun resetModuleStructureTransformers() { + moduleStructureTransformers.clear() + } + @TestInfrastructureInternals fun useModuleStructureTransformers(vararg transformers: ModuleStructureTransformer) { moduleStructureTransformers += transformers @@ -193,8 +216,7 @@ class TestConfigurationBuilder { testInfo, defaultsProviderBuilder.build(), assertions, - facades, - handlers, + steps, sourcePreprocessors, additionalMetaInfoProcessors, environmentConfigurators, @@ -208,6 +230,7 @@ class TestConfigurationBuilder { metaInfoHandlerEnabled, directives, defaultRegisteredDirectivesBuilder.build(), + startingArtifactFactory, additionalServices ) } diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/builders/TestPathMatcher.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/builders/TestPathMatcher.kt deleted file mode 100644 index c9d4830ed09..00000000000 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/builders/TestPathMatcher.kt +++ /dev/null @@ -1,7 +0,0 @@ -/* - * Copyright 2010-2020 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.builders - diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/frontend/fir/FirFailingTestSuppressor.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/frontend/fir/FirFailingTestSuppressor.kt index e9be7252693..7d0068353ea 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/frontend/fir/FirFailingTestSuppressor.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/frontend/fir/FirFailingTestSuppressor.kt @@ -7,6 +7,7 @@ package org.jetbrains.kotlin.test.frontend.fir import org.jetbrains.kotlin.test.WrappedException import org.jetbrains.kotlin.test.model.AfterAnalysisChecker +import org.jetbrains.kotlin.test.model.FrontendKinds import org.jetbrains.kotlin.test.services.TestServices import org.jetbrains.kotlin.test.services.moduleStructure @@ -15,7 +16,13 @@ class FirFailingTestSuppressor(testServices: TestServices) : AfterAnalysisChecke val testFile = testServices.moduleStructure.originalTestDataFiles.first() val failFile = testFile.parentFile.resolve("${testFile.nameWithoutExtension}.fail") val exceptionFromFir = - failedAssertions.firstOrNull { it is WrappedException.FromFacade.Frontend || it is WrappedException.FromFrontendHandler } + failedAssertions.firstOrNull { + when (it) { + is WrappedException.FromFacade -> it.facade is FirFrontendFacade + is WrappedException.FromHandler -> it.handler.artifactKind == FrontendKinds.FIR + else -> false + } + } return when { failFile.exists() && exceptionFromFir != null -> emptyList() failFile.exists() && exceptionFromFir == null -> { 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 715da881693..8ec4e0f274e 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 @@ -1,18 +1,19 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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.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.* import org.jetbrains.kotlin.test.directives.model.ComposedDirectivesContainer import org.jetbrains.kotlin.test.directives.model.DirectivesContainer import org.jetbrains.kotlin.test.directives.model.RegisteredDirectives -import org.jetbrains.kotlin.test.model.* +import org.jetbrains.kotlin.test.model.AfterAnalysisChecker +import org.jetbrains.kotlin.test.model.ResultingArtifact +import org.jetbrains.kotlin.test.model.ServicesAndDirectivesContainer +import org.jetbrains.kotlin.test.model.TestModule import org.jetbrains.kotlin.test.services.* import org.jetbrains.kotlin.test.services.impl.ModuleStructureExtractorImpl import org.jetbrains.kotlin.test.utils.TestDisposable @@ -24,9 +25,7 @@ class TestConfigurationImpl( defaultsProvider: DefaultsProvider, assertions: AssertionsService, - facades: List>>, - - analysisHandlers: List>>, + steps: List>, sourcePreprocessors: List>, additionalMetaInfoProcessors: List>, @@ -45,6 +44,7 @@ class TestConfigurationImpl( directives: List, override val defaultRegisteredDirectives: RegisteredDirectives, + override val startingArtifactFactory: (TestModule) -> ResultingArtifact<*>, additionalServices: List ) : TestConfiguration() { override val rootDisposable: Disposable = TestDisposable() @@ -67,35 +67,28 @@ class TestConfigurationImpl( } private val environmentConfigurators: List = - environmentConfigurators.map { it.invoke(testServices) }.also { configurators -> - configurators.flatMapTo(allDirectives) { it.directiveContainers } - for (configurator in configurators) { - configurator.additionalServices.forEach { testServices.register(it) } - } - } + environmentConfigurators + .map { it.invoke(testServices) } + .also { it.registerDirectivesAndServices() } override val preAnalysisHandlers: List = preAnalysisHandlers.map { it.invoke(testServices) } override val moduleStructureExtractor: ModuleStructureExtractor = ModuleStructureExtractorImpl( testServices, - additionalSourceProviders.map { it.invoke(testServices) }.also { - it.flatMapTo(allDirectives) { provider -> provider.directiveContainers } - }, + additionalSourceProviders + .map { it.invoke(testServices) } + .also { it.registerDirectivesAndServices() }, moduleStructureTransformers, this.environmentConfigurators ) - override val metaTestConfigurators: List = metaTestConfigurators.map { - it.invoke(testServices).also { configurator -> - allDirectives += configurator.directiveContainers - } + override val metaTestConfigurators: List = metaTestConfigurators.map { constructor -> + constructor.invoke(testServices).also { it.registerDirectivesAndServices() } } - override val afterAnalysisCheckers: List = afterAnalysisCheckers.map { - it.invoke(testServices).also { checker -> - allDirectives += checker.directiveContainers - } + override val afterAnalysisCheckers: List = afterAnalysisCheckers.map { constructor -> + constructor.invoke(testServices).also { it.registerDirectivesAndServices() } } init { @@ -120,61 +113,23 @@ class TestConfigurationImpl( } } - private val facades: Map, Map, AbstractTestFacade<*, *>>> = - facades - .map { it.invoke(testServices) } - .groupBy { it.inputKind } - .mapValues { (frontendKind, converters) -> - converters.groupBy { it.outputKind }.mapValues { - it.value.singleOrNull() ?: manyFacadesError("converters", "$frontendKind -> ${it.key}") - } - } - - - private val analysisHandlers: Map, List>> = - analysisHandlers.map { it.invoke(testServices).also(this::registerDirectivesAndServices) } - .groupBy { it.artifactKind } - .withDefault { emptyList() } - - private fun manyFacadesError(name: String, kinds: String): Nothing { - error("Too many $name passed for $kinds configuration") - } - - private fun registerDirectivesAndServices(handler: AnalysisHandler<*>) { - allDirectives += handler.directiveContainers - testServices.register(handler.additionalServices) - } - - init { - testServices.apply { - this@TestConfigurationImpl.facades.values.forEach { - it.values.forEach { facade -> - register(facade.additionalServices) - allDirectives += facade.directiveContainers - } + override val steps: List> = steps + .map { it.createTestStep(testServices) } + .onEach { step -> + when (step) { + is TestStep.FacadeStep<*, *> -> step.facade.registerDirectivesAndServices() + is TestStep.HandlersStep<*> -> step.handlers.registerDirectivesAndServices() } } + + // ---------------------------------- utils ---------------------------------- + + private fun ServicesAndDirectivesContainer.registerDirectivesAndServices() { + allDirectives += directiveContainers + testServices.register(additionalServices) } - override fun , O : ResultingArtifact> getFacade( - inputKind: TestArtifactKind, - outputKind: TestArtifactKind - ): AbstractTestFacade { - @Suppress("UNCHECKED_CAST") - return facades[inputKind]?.get(outputKind) as AbstractTestFacade? - ?: facadeNotFoundError(inputKind, outputKind) - } - - private fun facadeNotFoundError(from: Any, to: Any): Nothing { - error("Facade for converting '$from' to '$to' not found") - } - - override fun > getHandlers(artifactKind: TestArtifactKind): List> { - @Suppress("UNCHECKED_CAST") - return analysisHandlers.getValue(artifactKind) as List> - } - - override fun getAllHandlers(): List> { - return analysisHandlers.values.flatten() + private fun List.registerDirectivesAndServices() { + this.forEach { it.registerDirectivesAndServices() } } } diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/AbstractDiagnosticTest.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/AbstractDiagnosticTest.kt index 166c8266eac..49b19a78a40 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/AbstractDiagnosticTest.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/AbstractDiagnosticTest.kt @@ -9,6 +9,8 @@ import org.jetbrains.kotlin.config.ExplicitApiMode import org.jetbrains.kotlin.platform.jvm.JvmPlatforms import org.jetbrains.kotlin.test.TestJdkKind import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder +import org.jetbrains.kotlin.test.builders.classicFrontendHandlersStep +import org.jetbrains.kotlin.test.builders.classicFrontendStep import org.jetbrains.kotlin.test.directives.DiagnosticsDirectives.CHECK_COMPILE_TIME_VALUES import org.jetbrains.kotlin.test.directives.DiagnosticsDirectives.DIAGNOSTICS import org.jetbrains.kotlin.test.directives.DiagnosticsDirectives.REPORT_JVM_DIAGNOSTICS_ON_FRONTEND @@ -24,10 +26,10 @@ import org.jetbrains.kotlin.test.frontend.classic.handlers.* import org.jetbrains.kotlin.test.model.DependencyKind import org.jetbrains.kotlin.test.model.FrontendKinds import org.jetbrains.kotlin.test.services.configuration.CommonEnvironmentConfigurator -import org.jetbrains.kotlin.test.services.sourceProviders.AdditionalDiagnosticsSourceFilesProvider -import org.jetbrains.kotlin.test.services.sourceProviders.CoroutineHelpersSourceFilesProvider import org.jetbrains.kotlin.test.services.configuration.JvmEnvironmentConfigurator import org.jetbrains.kotlin.test.services.configuration.ScriptingEnvironmentConfigurator +import org.jetbrains.kotlin.test.services.sourceProviders.AdditionalDiagnosticsSourceFilesProvider +import org.jetbrains.kotlin.test.services.sourceProviders.CoroutineHelpersSourceFilesProvider abstract class AbstractDiagnosticTest : AbstractKotlinCompilerTest() { companion object { @@ -70,12 +72,15 @@ abstract class AbstractDiagnosticTest : AbstractKotlinCompilerTest() { ::CoroutineHelpersSourceFilesProvider, ) - useFrontendFacades(::ClassicFrontendFacade) - useFrontendHandlers( - ::DeclarationsDumpHandler, - ::ClassicDiagnosticsHandler, - ::ConstantValuesHandler - ) + classicFrontendStep() + + classicFrontendHandlersStep { + useHandlers( + ::DeclarationsDumpHandler, + ::ClassicDiagnosticsHandler, + ::ConstantValuesHandler + ) + } useAfterAnalysisCheckers(::FirTestDataConsistencyHandler) diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/AbstractDiagnosticsNativeTest.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/AbstractDiagnosticsNativeTest.kt index 62f92b74c13..0b86c5b92e1 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/AbstractDiagnosticsNativeTest.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/AbstractDiagnosticsNativeTest.kt @@ -7,6 +7,8 @@ package org.jetbrains.kotlin.test.runners import org.jetbrains.kotlin.platform.konan.NativePlatforms import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder +import org.jetbrains.kotlin.test.builders.classicFrontendHandlersStep +import org.jetbrains.kotlin.test.builders.classicFrontendStep import org.jetbrains.kotlin.test.directives.JvmEnvironmentConfigurationDirectives import org.jetbrains.kotlin.test.frontend.classic.ClassicFrontendFacade import org.jetbrains.kotlin.test.frontend.classic.handlers.ClassicDiagnosticsHandler @@ -40,10 +42,12 @@ abstract class AbstractDiagnosticsNativeTest : AbstractKotlinCompilerTest() { ::CoroutineHelpersSourceFilesProvider, ) - useFrontendFacades(::ClassicFrontendFacade) - useFrontendHandlers( - ::DeclarationsDumpHandler, - ::ClassicDiagnosticsHandler, - ) + classicFrontendStep() + classicFrontendHandlersStep { + useHandlers( + ::DeclarationsDumpHandler, + ::ClassicDiagnosticsHandler, + ) + } } } diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/AbstractDiagnosticsTestWithJsStdLib.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/AbstractDiagnosticsTestWithJsStdLib.kt index 93951f4f378..ed39ffcb1c1 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/AbstractDiagnosticsTestWithJsStdLib.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/AbstractDiagnosticsTestWithJsStdLib.kt @@ -7,6 +7,8 @@ package org.jetbrains.kotlin.test.runners import org.jetbrains.kotlin.platform.js.JsPlatforms import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder +import org.jetbrains.kotlin.test.builders.classicFrontendHandlersStep +import org.jetbrains.kotlin.test.builders.classicFrontendStep import org.jetbrains.kotlin.test.directives.JvmEnvironmentConfigurationDirectives import org.jetbrains.kotlin.test.frontend.classic.ClassicFrontendFacade import org.jetbrains.kotlin.test.frontend.classic.handlers.ClassicDiagnosticsHandler @@ -45,11 +47,13 @@ abstract class AbstractDiagnosticsTestWithJsStdLib : AbstractKotlinCompilerTest( ::CoroutineHelpersSourceFilesProvider, ) - useFrontendFacades(::ClassicFrontendFacade) - useFrontendHandlers( - ::DeclarationsDumpHandler, - ::ClassicDiagnosticsHandler, - ::DynamicCallsDumpHandler, - ) + classicFrontendStep() + classicFrontendHandlersStep { + useHandlers( + ::DeclarationsDumpHandler, + ::ClassicDiagnosticsHandler, + ::DynamicCallsDumpHandler, + ) + } } } diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/AbstractDiagnosticsTestWithJvmBackend.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/AbstractDiagnosticsTestWithJvmBackend.kt index fe39987c1fb..3babec53890 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/AbstractDiagnosticsTestWithJvmBackend.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/AbstractDiagnosticsTestWithJvmBackend.kt @@ -6,27 +6,35 @@ package org.jetbrains.kotlin.test.runners import org.jetbrains.kotlin.platform.jvm.JvmPlatforms +import org.jetbrains.kotlin.test.Constructor import org.jetbrains.kotlin.test.TargetBackend +import org.jetbrains.kotlin.test.backend.classic.ClassicBackendInput import org.jetbrains.kotlin.test.backend.classic.ClassicJvmBackendFacade import org.jetbrains.kotlin.test.backend.handlers.JvmBackendDiagnosticsHandler +import org.jetbrains.kotlin.test.backend.ir.IrBackendInput import org.jetbrains.kotlin.test.backend.ir.JvmIrBackendFacade import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder +import org.jetbrains.kotlin.test.builders.classicFrontendHandlersStep +import org.jetbrains.kotlin.test.builders.classicFrontendStep +import org.jetbrains.kotlin.test.builders.jvmArtifactsHandlersStep import org.jetbrains.kotlin.test.directives.JvmEnvironmentConfigurationDirectives import org.jetbrains.kotlin.test.frontend.classic.ClassicFrontend2ClassicBackendConverter import org.jetbrains.kotlin.test.frontend.classic.ClassicFrontend2IrConverter import org.jetbrains.kotlin.test.frontend.classic.ClassicFrontendFacade +import org.jetbrains.kotlin.test.frontend.classic.ClassicFrontendOutputArtifact import org.jetbrains.kotlin.test.frontend.classic.handlers.ClassicDiagnosticsHandler import org.jetbrains.kotlin.test.frontend.classic.handlers.DeclarationsDumpHandler import org.jetbrains.kotlin.test.frontend.classic.handlers.OldNewInferenceMetaInfoProcessor -import org.jetbrains.kotlin.test.model.DependencyKind -import org.jetbrains.kotlin.test.model.FrontendKinds +import org.jetbrains.kotlin.test.model.* import org.jetbrains.kotlin.test.services.configuration.CommonEnvironmentConfigurator import org.jetbrains.kotlin.test.services.sourceProviders.AdditionalDiagnosticsSourceFilesProvider import org.jetbrains.kotlin.test.services.sourceProviders.CoroutineHelpersSourceFilesProvider import org.jetbrains.kotlin.test.services.configuration.JvmEnvironmentConfigurator -abstract class AbstractDiagnosticsTestWithJvmBackend : AbstractKotlinCompilerTest() { +abstract class AbstractDiagnosticsTestWithJvmBackend> : AbstractKotlinCompilerTest() { abstract val targetBackend: TargetBackend + abstract val converter: Constructor> + abstract val backendFacade: Constructor> override fun TestConfigurationBuilder.configuration() { globalDefaults { @@ -53,35 +61,43 @@ abstract class AbstractDiagnosticsTestWithJvmBackend : AbstractKotlinCompilerTes ::CoroutineHelpersSourceFilesProvider, ) - useFrontendFacades(::ClassicFrontendFacade) + classicFrontendStep() + classicFrontendHandlersStep { + useHandlers( + ::DeclarationsDumpHandler, + ::ClassicDiagnosticsHandler, + ) + } - useFrontendHandlers( - ::DeclarationsDumpHandler, - ::ClassicDiagnosticsHandler, - ) + facadeStep(converter) + facadeStep(backendFacade) - useFrontend2BackendConverters( - ::ClassicFrontend2ClassicBackendConverter, - ::ClassicFrontend2IrConverter - ) - - useBackendFacades( - ::ClassicJvmBackendFacade, - ::JvmIrBackendFacade - ) - - useArtifactsHandlers( - ::JvmBackendDiagnosticsHandler - ) + jvmArtifactsHandlersStep { + useHandlers( + ::JvmBackendDiagnosticsHandler + ) + } } } -abstract class AbstractDiagnosticsTestWithOldJvmBackend : AbstractDiagnosticsTestWithJvmBackend() { +abstract class AbstractDiagnosticsTestWithOldJvmBackend : AbstractDiagnosticsTestWithJvmBackend() { override val targetBackend: TargetBackend get() = TargetBackend.JVM_OLD + + override val converter: Constructor> + get() = ::ClassicFrontend2ClassicBackendConverter + + override val backendFacade: Constructor> + get() = ::ClassicJvmBackendFacade } -abstract class AbstractDiagnosticsTestWithJvmIrBackend : AbstractDiagnosticsTestWithJvmBackend() { +abstract class AbstractDiagnosticsTestWithJvmIrBackend : AbstractDiagnosticsTestWithJvmBackend() { override val targetBackend: TargetBackend get() = TargetBackend.JVM_IR + + override val converter: Constructor> + get() = ::ClassicFrontend2IrConverter + + override val backendFacade: Constructor> + get() = ::JvmIrBackendFacade } diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/AbstractFirDiagnosticTest.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/AbstractFirDiagnosticTest.kt index df2c805a04c..e7b09ec0978 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/AbstractFirDiagnosticTest.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/AbstractFirDiagnosticTest.kt @@ -6,10 +6,11 @@ package org.jetbrains.kotlin.test.runners import org.jetbrains.kotlin.platform.jvm.JvmPlatforms +import org.jetbrains.kotlin.test.Constructor import org.jetbrains.kotlin.test.TestJdkKind import org.jetbrains.kotlin.test.bind import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder -import org.jetbrains.kotlin.test.directives.FirDiagnosticsDirectives.COMPARE_WITH_LIGHT_TREE +import org.jetbrains.kotlin.test.builders.firHandlersStep import org.jetbrains.kotlin.test.directives.FirDiagnosticsDirectives.FIR_DUMP import org.jetbrains.kotlin.test.directives.FirDiagnosticsDirectives.USE_LIGHT_TREE import org.jetbrains.kotlin.test.directives.FirDiagnosticsDirectives.WITH_EXTENDED_CHECKERS @@ -18,8 +19,10 @@ import org.jetbrains.kotlin.test.directives.JvmEnvironmentConfigurationDirective import org.jetbrains.kotlin.test.directives.JvmEnvironmentConfigurationDirectives.WITH_STDLIB import org.jetbrains.kotlin.test.frontend.fir.FirFailingTestSuppressor import org.jetbrains.kotlin.test.frontend.fir.FirFrontendFacade +import org.jetbrains.kotlin.test.frontend.fir.FirOutputArtifact import org.jetbrains.kotlin.test.frontend.fir.handlers.* import org.jetbrains.kotlin.test.model.DependencyKind +import org.jetbrains.kotlin.test.model.FrontendFacade import org.jetbrains.kotlin.test.model.FrontendKinds import org.jetbrains.kotlin.test.services.configuration.CommonEnvironmentConfigurator import org.jetbrains.kotlin.test.services.sourceProviders.AdditionalDiagnosticsSourceFilesProvider @@ -44,9 +47,11 @@ abstract class AbstractFirDiagnosticsWithLightTreeTest : AbstractFirDiagnosticTe } } - // `baseDir` is used in Kotlin plugin from IJ infra -fun TestConfigurationBuilder.baseFirDiagnosticTestConfiguration(baseDir: String = ".") { +fun TestConfigurationBuilder.baseFirDiagnosticTestConfiguration( + baseDir: String = ".", + frontendFacade: Constructor> = ::FirFrontendFacade +) { globalDefaults { frontend = FrontendKinds.FIR targetPlatform = JvmPlatforms.defaultJvmPlatform @@ -64,14 +69,17 @@ fun TestConfigurationBuilder.baseFirDiagnosticTestConfiguration(baseDir: String ::AdditionalDiagnosticsSourceFilesProvider.bind(baseDir), ::CoroutineHelpersSourceFilesProvider.bind(baseDir), ) - useFrontendFacades(::FirFrontendFacade) - useFrontendHandlers( - ::FirDiagnosticsHandler, - ::FirDumpHandler, - ::FirCfgDumpHandler, - ::FirCfgConsistencyHandler, - ::FirNoImplicitTypesHandler, - ) + + facadeStep(frontendFacade) + firHandlersStep { + useHandlers( + ::FirDiagnosticsHandler, + ::FirDumpHandler, + ::FirCfgDumpHandler, + ::FirCfgConsistencyHandler, + ::FirNoImplicitTypesHandler, + ) + } useMetaInfoProcessors(::PsiLightTreeMetaInfoProcessor) diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/AbstractForeignAnnotationsTest.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/AbstractForeignAnnotationsTest.kt index 2df9675052d..b121b079c95 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/AbstractForeignAnnotationsTest.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/AbstractForeignAnnotationsTest.kt @@ -6,10 +6,12 @@ package org.jetbrains.kotlin.test.runners import org.jetbrains.kotlin.platform.jvm.JvmPlatforms -import org.jetbrains.kotlin.test.Constructor import org.jetbrains.kotlin.test.TestJavacVersion import org.jetbrains.kotlin.test.TestJdkKind import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder +import org.jetbrains.kotlin.test.builders.classicFrontendHandlersStep +import org.jetbrains.kotlin.test.builders.classicFrontendStep +import org.jetbrains.kotlin.test.builders.configureClassicFrontendHandlersStep import org.jetbrains.kotlin.test.directives.DiagnosticsDirectives.REPORT_JVM_DIAGNOSTICS_ON_FRONTEND import org.jetbrains.kotlin.test.directives.DiagnosticsDirectives.SKIP_TXT import org.jetbrains.kotlin.test.directives.ForeignAnnotationsDirectives.ANNOTATIONS_PATH @@ -60,11 +62,13 @@ abstract class AbstractForeignAnnotationsTestBase : AbstractKotlinCompilerTest() ::CoroutineHelpersSourceFilesProvider, ) - useFrontendFacades(::ClassicFrontendFacade) - useFrontendHandlers( - ::DeclarationsDumpHandler, - ::ClassicDiagnosticsHandler, - ) + classicFrontendStep() + classicFrontendHandlersStep { + useHandlers( + ::DeclarationsDumpHandler, + ::ClassicDiagnosticsHandler, + ) + } forTestsMatching("compiler/testData/diagnostics/foreignAnnotationsTests/tests/*") { defaultDirectives { @@ -88,7 +92,9 @@ abstract class AbstractForeignAnnotationsTestBase : AbstractKotlinCompilerTest() } forTestsMatching("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/*") { - useFrontendHandlers(::JspecifyDiagnosticComplianceHandler) + configureClassicFrontendHandlersStep { + useHandlers(::JspecifyDiagnosticComplianceHandler) + } useSourcePreprocessor(::JspecifyMarksCleanupPreprocessor) } } diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/AbstractKotlinCompilerTest.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/AbstractKotlinCompilerTest.kt index 89f2dcf0ea4..86d1d16cbe2 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/AbstractKotlinCompilerTest.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/AbstractKotlinCompilerTest.kt @@ -11,6 +11,7 @@ import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder import org.jetbrains.kotlin.test.builders.testRunner import org.jetbrains.kotlin.test.directives.ConfigurationDirectives import org.jetbrains.kotlin.test.directives.LanguageSettingsDirectives +import org.jetbrains.kotlin.test.model.ResultingArtifact import org.jetbrains.kotlin.test.preprocessors.MetaInfosCleanupPreprocessor import org.jetbrains.kotlin.test.services.* import org.jetbrains.kotlin.test.services.impl.TemporaryDirectoryManagerImpl @@ -46,6 +47,7 @@ abstract class AbstractKotlinCompilerTest { useSourcePreprocessor(*defaultPreprocessors.toTypedArray()) useDirectives(*defaultDirectiveContainers.toTypedArray()) configureDebugFlags() + startingArtifactFactory = { ResultingArtifact.Source() } } } diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/codegen/AbstractBlackBoxCodegenTest.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/codegen/AbstractBlackBoxCodegenTest.kt index 537d8481600..cbf526bea77 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/codegen/AbstractBlackBoxCodegenTest.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/codegen/AbstractBlackBoxCodegenTest.kt @@ -7,22 +7,23 @@ package org.jetbrains.kotlin.test.runners.codegen import org.jetbrains.kotlin.test.Constructor import org.jetbrains.kotlin.test.TargetBackend +import org.jetbrains.kotlin.test.backend.classic.ClassicBackendInput import org.jetbrains.kotlin.test.backend.classic.ClassicJvmBackendFacade import org.jetbrains.kotlin.test.frontend.classic.ClassicFrontend2ClassicBackendConverter import org.jetbrains.kotlin.test.frontend.classic.ClassicFrontendFacade import org.jetbrains.kotlin.test.frontend.classic.ClassicFrontendOutputArtifact import org.jetbrains.kotlin.test.model.* -open class AbstractBlackBoxCodegenTest : AbstractJvmBlackBoxCodegenTestBase( +open class AbstractBlackBoxCodegenTest : AbstractJvmBlackBoxCodegenTestBase( FrontendKinds.ClassicFrontend, TargetBackend.JVM ) { override val frontendFacade: Constructor> get() = ::ClassicFrontendFacade - override val frontendToBackendConverter: Constructor> + override val frontendToBackendConverter: Constructor> get() = ::ClassicFrontend2ClassicBackendConverter - override val backendFacade: Constructor> + override val backendFacade: Constructor> get() = ::ClassicJvmBackendFacade } diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/codegen/AbstractBytecodeListingTest.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/codegen/AbstractBytecodeListingTest.kt index d54fb6379c7..023cade4255 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/codegen/AbstractBytecodeListingTest.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/codegen/AbstractBytecodeListingTest.kt @@ -8,56 +8,64 @@ package org.jetbrains.kotlin.test.runners.codegen import org.jetbrains.kotlin.test.Constructor import org.jetbrains.kotlin.test.TargetBackend import org.jetbrains.kotlin.test.backend.BlackBoxCodegenSuppressor +import org.jetbrains.kotlin.test.backend.classic.ClassicBackendInput import org.jetbrains.kotlin.test.backend.classic.ClassicJvmBackendFacade import org.jetbrains.kotlin.test.backend.handlers.BytecodeListingHandler +import org.jetbrains.kotlin.test.backend.ir.IrBackendInput import org.jetbrains.kotlin.test.backend.ir.JvmIrBackendFacade import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder +import org.jetbrains.kotlin.test.builders.configureJvmArtifactsHandlersStep import org.jetbrains.kotlin.test.directives.CodegenTestDirectives import org.jetbrains.kotlin.test.runners.AbstractKotlinCompilerWithTargetBackendTest import org.jetbrains.kotlin.test.frontend.classic.* import org.jetbrains.kotlin.test.model.* -abstract class AbstractBytecodeListingTestBase>( +abstract class AbstractBytecodeListingTestBase, I : ResultingArtifact.BackendInput>( targetBackend: TargetBackend, - val targetFrontend: FrontendKind<*> + val targetFrontend: FrontendKind ) : AbstractKotlinCompilerWithTargetBackendTest(targetBackend) { abstract val frontendFacade: Constructor> - abstract val frontendToBackendConverter: Constructor> - abstract val backendFacade: Constructor> + abstract val frontendToBackendConverter: Constructor> + abstract val backendFacade: Constructor> override fun TestConfigurationBuilder.configuration() { - commonConfigurationForCodegenTest(targetFrontend, frontendFacade, frontendToBackendConverter, backendFacade) - commonHandlersForCodegenTest() defaultDirectives { +CodegenTestDirectives.CHECK_BYTECODE_LISTING } - useArtifactsHandlers(::BytecodeListingHandler) + + commonConfigurationForCodegenTest(targetFrontend, frontendFacade, frontendToBackendConverter, backendFacade) + commonHandlersForCodegenTest() + + configureJvmArtifactsHandlersStep { + useHandlers(::BytecodeListingHandler) + } + useAfterAnalysisCheckers(::BlackBoxCodegenSuppressor) } } -open class AbstractBytecodeListingTest : AbstractBytecodeListingTestBase( +open class AbstractBytecodeListingTest : AbstractBytecodeListingTestBase( TargetBackend.JVM, FrontendKinds.ClassicFrontend ) { override val frontendFacade: Constructor> get() = ::ClassicFrontendFacade - override val frontendToBackendConverter: Constructor> + override val frontendToBackendConverter: Constructor> get() = ::ClassicFrontend2ClassicBackendConverter - override val backendFacade: Constructor> + override val backendFacade: Constructor> get() = ::ClassicJvmBackendFacade } -open class AbstractIrBytecodeListingTest : AbstractBytecodeListingTestBase( +open class AbstractIrBytecodeListingTest : AbstractBytecodeListingTestBase( TargetBackend.JVM_IR, FrontendKinds.ClassicFrontend ) { override val frontendFacade: Constructor> get() = ::ClassicFrontendFacade - override val frontendToBackendConverter: Constructor> + override val frontendToBackendConverter: Constructor> get() = ::ClassicFrontend2IrConverter - override val backendFacade: Constructor> + override val backendFacade: Constructor> get() = ::JvmIrBackendFacade } diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/codegen/AbstractBytecodeTextTest.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/codegen/AbstractBytecodeTextTest.kt index ec6fd084665..ba50bd2499e 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/codegen/AbstractBytecodeTextTest.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/codegen/AbstractBytecodeTextTest.kt @@ -8,10 +8,13 @@ package org.jetbrains.kotlin.test.runners.codegen import org.jetbrains.kotlin.test.Constructor import org.jetbrains.kotlin.test.TargetBackend import org.jetbrains.kotlin.test.backend.BlackBoxCodegenSuppressor +import org.jetbrains.kotlin.test.backend.classic.ClassicBackendInput import org.jetbrains.kotlin.test.backend.classic.ClassicJvmBackendFacade import org.jetbrains.kotlin.test.backend.handlers.BytecodeTextHandler +import org.jetbrains.kotlin.test.backend.ir.IrBackendInput import org.jetbrains.kotlin.test.backend.ir.JvmIrBackendFacade import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder +import org.jetbrains.kotlin.test.builders.configureJvmArtifactsHandlersStep import org.jetbrains.kotlin.test.directives.JvmEnvironmentConfigurationDirectives.USE_PSI_CLASS_FILES_READING import org.jetbrains.kotlin.test.directives.JvmEnvironmentConfigurationDirectives.WITH_REFLECT import org.jetbrains.kotlin.test.directives.JvmEnvironmentConfigurationDirectives.WITH_STDLIB @@ -25,69 +28,71 @@ import org.jetbrains.kotlin.test.frontend.fir.FirOutputArtifact import org.jetbrains.kotlin.test.model.* import org.jetbrains.kotlin.test.runners.AbstractKotlinCompilerWithTargetBackendTest -abstract class AbstractBytecodeTextTestBase>( +abstract class AbstractBytecodeTextTestBase, I : ResultingArtifact.BackendInput>( targetBackend: TargetBackend, - val targetFrontend: FrontendKind<*> + val targetFrontend: FrontendKind ) : AbstractKotlinCompilerWithTargetBackendTest(targetBackend) { abstract val frontendFacade: Constructor> - abstract val frontendToBackendConverter: Constructor> - abstract val backendFacade: Constructor> + abstract val frontendToBackendConverter: Constructor> + abstract val backendFacade: Constructor> override fun TestConfigurationBuilder.configuration() { - commonConfigurationForCodegenTest(targetFrontend, frontendFacade, frontendToBackendConverter, backendFacade) - defaultDirectives { +WITH_STDLIB +WITH_REFLECT } + commonConfigurationForCodegenTest(targetFrontend, frontendFacade, frontendToBackendConverter, backendFacade) + commonHandlersForCodegenTest() - useArtifactsHandlers(::BytecodeTextHandler) + configureJvmArtifactsHandlersStep { + useHandlers(::BytecodeTextHandler) + } useAfterAnalysisCheckers(::BlackBoxCodegenSuppressor) } } -open class AbstractBytecodeTextTest : AbstractBytecodeTextTestBase( +open class AbstractBytecodeTextTest : AbstractBytecodeTextTestBase( targetBackend = TargetBackend.JVM, targetFrontend = FrontendKinds.ClassicFrontend ) { override val frontendFacade: Constructor> get() = ::ClassicFrontendFacade - override val frontendToBackendConverter: Constructor> + override val frontendToBackendConverter: Constructor> get() = ::ClassicFrontend2ClassicBackendConverter - override val backendFacade: Constructor> + override val backendFacade: Constructor> get() = ::ClassicJvmBackendFacade } -open class AbstractIrBytecodeTextTest : AbstractBytecodeTextTestBase( +open class AbstractIrBytecodeTextTest : AbstractBytecodeTextTestBase( targetBackend = TargetBackend.JVM_IR, targetFrontend = FrontendKinds.ClassicFrontend ) { override val frontendFacade: Constructor> get() = ::ClassicFrontendFacade - override val frontendToBackendConverter: Constructor> + override val frontendToBackendConverter: Constructor> get() = ::ClassicFrontend2IrConverter - override val backendFacade: Constructor> + override val backendFacade: Constructor> get() = ::JvmIrBackendFacade } -open class AbstractFirBytecodeTextTest : AbstractBytecodeTextTestBase( +open class AbstractFirBytecodeTextTest : AbstractBytecodeTextTestBase( targetBackend = TargetBackend.JVM_IR, targetFrontend = FrontendKinds.FIR ) { override val frontendFacade: Constructor> get() = ::FirFrontendFacade - override val frontendToBackendConverter: Constructor> + override val frontendToBackendConverter: Constructor> get() = ::Fir2IrResultsConverter - override val backendFacade: Constructor> + override val backendFacade: Constructor> get() = ::JvmIrBackendFacade override fun configure(builder: TestConfigurationBuilder) { diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/codegen/AbstractCompileKotlinAgainstInlineKotlinTest.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/codegen/AbstractCompileKotlinAgainstInlineKotlinTest.kt index 01049bedebd..4953d73bed9 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/codegen/AbstractCompileKotlinAgainstInlineKotlinTest.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/codegen/AbstractCompileKotlinAgainstInlineKotlinTest.kt @@ -26,6 +26,7 @@ import org.jetbrains.kotlin.test.backend.ir.IrBackendInput import org.jetbrains.kotlin.test.backend.ir.JvmIrBackendFacade import org.jetbrains.kotlin.test.bind import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder +import org.jetbrains.kotlin.test.builders.configureIrHandlersStep import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.IGNORE_BACKEND_MULTI_MODULE import org.jetbrains.kotlin.test.frontend.classic.ClassicFrontend2ClassicBackendConverter import org.jetbrains.kotlin.test.frontend.classic.ClassicFrontend2IrConverter @@ -45,9 +46,7 @@ abstract class AbstractCompileKotlinAgainstInlineKotlinTestBase> abstract val backendFacade: Constructor> - override fun TestConfigurationBuilder.configuration() = configurationImpl() - - protected fun TestConfigurationBuilder.configurationImpl() { + override fun TestConfigurationBuilder.configuration() { commonConfigurationForCodegenTest( FrontendKinds.ClassicFrontend, ::ClassicFrontendFacade, @@ -55,7 +54,7 @@ abstract class AbstractCompileKotlinAgainstInlineKotlinTestBase( +open class AbstractFirBlackBoxCodegenTest : AbstractJvmBlackBoxCodegenTestBase( FrontendKinds.FIR, TargetBackend.JVM_IR ) { override val frontendFacade: Constructor> get() = ::FirFrontendFacade - override val frontendToBackendConverter: Constructor> + override val frontendToBackendConverter: Constructor> get() = ::Fir2IrResultsConverter - override val backendFacade: Constructor> + override val backendFacade: Constructor> get() = ::JvmIrBackendFacade override fun configure(builder: TestConfigurationBuilder) { @@ -41,18 +42,21 @@ open class AbstractFirBlackBoxCodegenTest : AbstractJvmBlackBoxCodegenTestBase( +open class AbstractIrBlackBoxCodegenTest : AbstractJvmBlackBoxCodegenTestBase( FrontendKinds.ClassicFrontend, TargetBackend.JVM_IR ) { override val frontendFacade: Constructor> get() = ::ClassicFrontendFacade - override val frontendToBackendConverter: Constructor> + override val frontendToBackendConverter: Constructor> get() = ::ClassicFrontend2IrConverter - override val backendFacade: Constructor> + override val backendFacade: Constructor> get() = ::JvmIrBackendFacade override fun configure(builder: TestConfigurationBuilder) { super.configure(builder) - builder.dumpHandlersForCodegenTest() + builder.configureDumpHandlersForCodegenTest() } } diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/codegen/AbstractJvmBlackBoxCodegenTestBase.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/codegen/AbstractJvmBlackBoxCodegenTestBase.kt index e29fcc61287..7642594a8e0 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/codegen/AbstractJvmBlackBoxCodegenTestBase.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/codegen/AbstractJvmBlackBoxCodegenTestBase.kt @@ -14,10 +14,13 @@ import org.jetbrains.kotlin.test.backend.handlers.BytecodeListingHandler import org.jetbrains.kotlin.test.backend.handlers.BytecodeTextHandler import org.jetbrains.kotlin.test.bind import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder -import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.IGNORE_DEXING -import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.USE_JAVAC_BASED_ON_JVM_TARGET +import org.jetbrains.kotlin.test.builders.configureClassicFrontendHandlersStep +import org.jetbrains.kotlin.test.builders.configureFirHandlersStep +import org.jetbrains.kotlin.test.builders.configureJvmArtifactsHandlersStep import org.jetbrains.kotlin.test.directives.DiagnosticsDirectives.DIAGNOSTICS +import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.IGNORE_DEXING import org.jetbrains.kotlin.test.directives.DiagnosticsDirectives.REPORT_ONLY_EXPLICITLY_DEFINED_DEBUG_INFO +import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.USE_JAVAC_BASED_ON_JVM_TARGET import org.jetbrains.kotlin.test.directives.JvmEnvironmentConfigurationDirectives.JDK_KIND import org.jetbrains.kotlin.test.directives.JvmEnvironmentConfigurationDirectives.JVM_TARGET import org.jetbrains.kotlin.test.directives.JvmEnvironmentConfigurationDirectives.WITH_STDLIB @@ -26,24 +29,38 @@ import org.jetbrains.kotlin.test.frontend.fir.handlers.FirDiagnosticsHandler import org.jetbrains.kotlin.test.model.* import org.jetbrains.kotlin.test.runners.AbstractKotlinCompilerWithTargetBackendTest -abstract class AbstractJvmBlackBoxCodegenTestBase>( +abstract class AbstractJvmBlackBoxCodegenTestBase, I : ResultingArtifact.BackendInput>( val targetFrontend: FrontendKind, targetBackend: TargetBackend ) : AbstractKotlinCompilerWithTargetBackendTest(targetBackend) { abstract val frontendFacade: Constructor> - abstract val frontendToBackendConverter: Constructor> - abstract val backendFacade: Constructor> + abstract val frontendToBackendConverter: Constructor> + abstract val backendFacade: Constructor> override fun TestConfigurationBuilder.configuration() { commonConfigurationForCodegenTest(targetFrontend, frontendFacade, frontendToBackendConverter, backendFacade) - useFrontendHandlers( - ::ClassicDiagnosticsHandler, - ::FirDiagnosticsHandler - ) - commonHandlersForBoxTest() - useArtifactsHandlers(::BytecodeListingHandler) - useArtifactsHandlers(::BytecodeTextHandler.bind(true)) + configureClassicFrontendHandlersStep { + useHandlers( + ::ClassicDiagnosticsHandler + ) + } + + configureFirHandlersStep { + useHandlers( + ::FirDiagnosticsHandler + ) + } + + configureCommonHandlersForBoxTest() + + configureJvmArtifactsHandlersStep { + useHandlers( + ::BytecodeListingHandler, + ::BytecodeTextHandler.bind(true) + ) + } + useAfterAnalysisCheckers(::BlackBoxCodegenSuppressor) defaultDirectives { diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/codegen/AbstractJvmIrAgainstOldBoxTest.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/codegen/AbstractJvmIrAgainstOldBoxTest.kt index 27918a5c6a8..b1b79ffc17f 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/codegen/AbstractJvmIrAgainstOldBoxTest.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/codegen/AbstractJvmIrAgainstOldBoxTest.kt @@ -7,55 +7,42 @@ package org.jetbrains.kotlin.test.runners.codegen import org.jetbrains.kotlin.test.TargetBackend import org.jetbrains.kotlin.test.TestInfrastructureInternals -import org.jetbrains.kotlin.test.backend.BlackBoxCodegenSuppressor -import org.jetbrains.kotlin.test.backend.classic.ClassicJvmBackendFacade -import org.jetbrains.kotlin.test.backend.ir.JvmIrBackendFacade -import org.jetbrains.kotlin.test.bind import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder -import org.jetbrains.kotlin.test.directives.CodegenTestDirectives -import org.jetbrains.kotlin.test.frontend.classic.ClassicFrontend2ClassicBackendConverter -import org.jetbrains.kotlin.test.frontend.classic.ClassicFrontend2IrConverter -import org.jetbrains.kotlin.test.frontend.classic.ClassicFrontendFacade -import org.jetbrains.kotlin.test.model.FrontendKinds -import org.jetbrains.kotlin.test.runners.AbstractKotlinCompilerWithTargetBackendTest +import org.jetbrains.kotlin.test.builders.configureJvmArtifactsHandlersStep import org.jetbrains.kotlin.test.services.ModuleTransformerForSwitchingBackend import org.jetbrains.kotlin.test.services.ModuleTransformerForTwoFilesBoxTests @OptIn(TestInfrastructureInternals::class) -open class AbstractBackendAgainstBackendBoxTestBase( +abstract class AbstractBoxInlineWithDifferentBackendsTest( targetBackend: TargetBackend, - val backendForLib: TargetBackend, - val backendForMain: TargetBackend -) : AbstractKotlinCompilerWithTargetBackendTest(targetBackend) { - override fun TestConfigurationBuilder.configuration() { - commonConfigurationForCodegenTest( - FrontendKinds.ClassicFrontend, - ::ClassicFrontendFacade, - ::ClassicFrontend2ClassicBackendConverter, - ::ClassicJvmBackendFacade - ) - useFrontend2BackendConverters(::ClassicFrontend2IrConverter) - useBackendFacades(::JvmIrBackendFacade) + backendForLib: TargetBackend, + backendForMain: TargetBackend +) : AbstractBoxWithDifferentBackendsTest(targetBackend, backendForLib, backendForMain) { + override fun configure(builder: TestConfigurationBuilder) { + super.configure(builder) + builder.apply { + applyDumpSmapDirective() - commonHandlersForBoxTest() - useInlineHandlers() + resetModuleStructureTransformers() + useModuleStructureTransformers( + ModuleTransformerForTwoFilesBoxTests(), + ModuleTransformerForSwitchingBackend(backendForLib, backendForMain) + ) - useAfterAnalysisCheckers(::BlackBoxCodegenSuppressor.bind(CodegenTestDirectives.IGNORE_BACKEND_MULTI_MODULE)) - - useModuleStructureTransformers( - ModuleTransformerForTwoFilesBoxTests(), - ModuleTransformerForSwitchingBackend(backendForLib, backendForMain) - ) + configureJvmArtifactsHandlersStep { + inlineHandlers() + } + } } } -open class AbstractJvmIrAgainstOldBoxInlineTest : AbstractBackendAgainstBackendBoxTestBase( +open class AbstractJvmIrAgainstOldBoxInlineTest : AbstractBoxInlineWithDifferentBackendsTest( targetBackend = TargetBackend.JVM_MULTI_MODULE_IR_AGAINST_OLD, backendForLib = TargetBackend.JVM, backendForMain = TargetBackend.JVM_IR ) -open class AbstractJvmOldAgainstIrBoxInlineTest : AbstractBackendAgainstBackendBoxTestBase( +open class AbstractJvmOldAgainstIrBoxInlineTest : AbstractBoxInlineWithDifferentBackendsTest( targetBackend = TargetBackend.JVM_MULTI_MODULE_OLD_AGAINST_IR, backendForLib = TargetBackend.JVM_IR, backendForMain = TargetBackend.JVM_OLD diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/codegen/BaseCodegenConfiguration.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/codegen/BaseCodegenConfiguration.kt index cb478e3d13a..30cd4d53c86 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/codegen/BaseCodegenConfiguration.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/codegen/BaseCodegenConfiguration.kt @@ -7,10 +7,14 @@ package org.jetbrains.kotlin.test.runners.codegen import org.jetbrains.kotlin.platform.jvm.JvmPlatforms import org.jetbrains.kotlin.test.Constructor +import org.jetbrains.kotlin.test.HandlersStepBuilder import org.jetbrains.kotlin.test.backend.handlers.* -import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder +import org.jetbrains.kotlin.test.backend.ir.IrBackendInput +import org.jetbrains.kotlin.test.builders.* import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.DUMP_SMAP import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.RUN_DEX_CHECKER +import org.jetbrains.kotlin.test.frontend.classic.ClassicFrontendOutputArtifact +import org.jetbrains.kotlin.test.frontend.fir.FirOutputArtifact import org.jetbrains.kotlin.test.model.* import org.jetbrains.kotlin.test.services.configuration.CommonEnvironmentConfigurator import org.jetbrains.kotlin.test.services.configuration.JvmEnvironmentConfigurator @@ -20,12 +24,25 @@ import org.jetbrains.kotlin.test.services.sourceProviders.CodegenHelpersSourceFi import org.jetbrains.kotlin.test.services.sourceProviders.CoroutineHelpersSourceFilesProvider import org.jetbrains.kotlin.test.services.sourceProviders.MainFunctionForBlackBoxTestsSourceProvider -fun > TestConfigurationBuilder.commonConfigurationForCodegenTest( - targetFrontend: FrontendKind<*>, - frontendFacade: Constructor>, - frontendToBackendConverter: Constructor>, - backendFacade: Constructor> +fun , B : ResultingArtifact.BackendInput> TestConfigurationBuilder.commonConfigurationForCodegenTest( + targetFrontend: FrontendKind, + frontendFacade: Constructor>, + frontendToBackendConverter: Constructor>, + backendFacade: Constructor>, ) { + commonServicesConfigurationForCodegenTest(targetFrontend) + facadeStep(frontendFacade) + classicFrontendHandlersStep() + firHandlersStep() + commonBackendStepsConfiguration( + frontendToBackendConverter, + irHandlersInit = {}, + backendFacade, + jvmHandlersInit = {} + ) +} + +fun TestConfigurationBuilder.commonServicesConfigurationForCodegenTest(targetFrontend: FrontendKind<*>) { globalDefaults { frontend = targetFrontend targetPlatform = JvmPlatforms.defaultJvmPlatform @@ -48,45 +65,99 @@ fun > TestConfigurationBuilder.commonCon ::CodegenHelpersSourceFilesProvider, ::MainFunctionForBlackBoxTestsSourceProvider, ) - - useFrontendFacades(frontendFacade) - useFrontend2BackendConverters(frontendToBackendConverter) - useBackendFacades(backendFacade) } -fun TestConfigurationBuilder.dumpHandlersForCodegenTest() { - useBackendHandlers(::IrTreeVerifierHandler, ::IrTextDumpHandler) - useArtifactsHandlers(::BytecodeListingHandler) -} - -fun TestConfigurationBuilder.commonHandlersForBoxTest() { - commonHandlersForCodegenTest() - useArtifactsHandlers( - ::JvmBoxRunner - ) -} - -fun TestConfigurationBuilder.commonHandlersForCodegenTest() { - useFrontendHandlers( - ::NoCompilationErrorsHandler, - ::NoFirCompilationErrorsHandler, - ) - - useArtifactsHandlers( - ::NoJvmSpecificCompilationErrorsHandler, - ::DxCheckerHandler, - ) +inline fun , F : ResultingArtifact.FrontendOutput> TestConfigurationBuilder.commonBackendStepsConfiguration( + noinline frontendToBackendConverter: Constructor>, + irHandlersInit: HandlersStepBuilder.() -> Unit, + noinline backendFacade: Constructor>, + jvmHandlersInit: HandlersStepBuilder.() -> Unit, +) { + facadeStep(frontendToBackendConverter) + irHandlersStep(irHandlersInit) + facadeStep(backendFacade) + jvmArtifactsHandlersStep(jvmHandlersInit) } fun TestConfigurationBuilder.useInlineHandlers() { - useArtifactsHandlers( - ::BytecodeInliningHandler, - ::SMAPDumpHandler - ) + configureJvmArtifactsHandlersStep { + inlineHandlers() + } + applyDumpSmapDirective() +} + +fun TestConfigurationBuilder.applyDumpSmapDirective() { forTestsMatching("compiler/testData/codegen/boxInline/smap/*") { defaultDirectives { +DUMP_SMAP } } } + +fun TestConfigurationBuilder.configureDumpHandlersForCodegenTest() { + configureIrHandlersStep { + dumpHandlersForConverterStep() + } + configureJvmArtifactsHandlersStep { + dumpHandlersForBackendStep() + } +} + +fun TestConfigurationBuilder.configureCommonHandlersForBoxTest() { + commonHandlersForCodegenTest() + configureJvmArtifactsHandlersStep { + boxHandlersForBackendStep() + } +} + +fun TestConfigurationBuilder.commonHandlersForCodegenTest() { + configureClassicFrontendHandlersStep { + commonClassicFrontendHandlersForCodegenTest() + } + + configureFirHandlersStep { + commonFirHandlersForCodegenTest() + } + configureJvmArtifactsHandlersStep { + commonBackendHandlersForCodegenTest() + } +} + +fun HandlersStepBuilder.dumpHandlersForConverterStep() { + useHandlers(::IrTreeVerifierHandler, ::IrTextDumpHandler) +} + +fun HandlersStepBuilder.dumpHandlersForBackendStep() { + useHandlers(::BytecodeListingHandler) +} + +fun HandlersStepBuilder.boxHandlersForBackendStep() { + useHandlers(::JvmBoxRunner) +} + +fun HandlersStepBuilder.commonClassicFrontendHandlersForCodegenTest() { + useHandlers( + ::NoCompilationErrorsHandler, + ) +} + +fun HandlersStepBuilder.commonFirHandlersForCodegenTest() { + useHandlers( + ::NoFirCompilationErrorsHandler, + ) +} + +fun HandlersStepBuilder.commonBackendHandlersForCodegenTest() { + useHandlers( + ::NoJvmSpecificCompilationErrorsHandler, + ::DxCheckerHandler, + ) +} + +fun HandlersStepBuilder.inlineHandlers() { + useHandlers( + ::BytecodeInliningHandler, + ::SMAPDumpHandler + ) +} diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/ir/AbstractIrTextTest.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/ir/AbstractIrTextTest.kt index cad464d5b32..2cfbef65d25 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/ir/AbstractIrTextTest.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/ir/AbstractIrTextTest.kt @@ -6,16 +6,23 @@ package org.jetbrains.kotlin.test.runners.ir import org.jetbrains.kotlin.platform.jvm.JvmPlatforms +import org.jetbrains.kotlin.test.Constructor import org.jetbrains.kotlin.test.TargetBackend import org.jetbrains.kotlin.test.backend.BlackBoxCodegenSuppressor import org.jetbrains.kotlin.test.backend.handlers.* +import org.jetbrains.kotlin.test.backend.ir.IrBackendInput import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder +import org.jetbrains.kotlin.test.builders.classicFrontendHandlersStep +import org.jetbrains.kotlin.test.builders.firHandlersStep +import org.jetbrains.kotlin.test.builders.irHandlersStep import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.DUMP_IR import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.DUMP_KT_IR import org.jetbrains.kotlin.test.frontend.classic.ClassicFrontend2IrConverter import org.jetbrains.kotlin.test.frontend.classic.ClassicFrontendFacade +import org.jetbrains.kotlin.test.frontend.classic.ClassicFrontendOutputArtifact import org.jetbrains.kotlin.test.frontend.fir.Fir2IrResultsConverter import org.jetbrains.kotlin.test.frontend.fir.FirFrontendFacade +import org.jetbrains.kotlin.test.frontend.fir.FirOutputArtifact import org.jetbrains.kotlin.test.model.* import org.jetbrains.kotlin.test.runners.AbstractKotlinCompilerWithTargetBackendTest import org.jetbrains.kotlin.test.services.configuration.CommonEnvironmentConfigurator @@ -24,9 +31,13 @@ import org.jetbrains.kotlin.test.services.sourceProviders.AdditionalDiagnosticsS import org.jetbrains.kotlin.test.services.sourceProviders.CodegenHelpersSourceFilesProvider import org.jetbrains.kotlin.test.services.sourceProviders.CoroutineHelpersSourceFilesProvider -abstract class AbstractIrTextTestBase( - private val frontend: FrontendKind<*> -) : AbstractKotlinCompilerWithTargetBackendTest(TargetBackend.JVM_IR) { +abstract class AbstractIrTextTestBase> : + AbstractKotlinCompilerWithTargetBackendTest(TargetBackend.JVM_IR) +{ + abstract val frontend: FrontendKind<*> + abstract val frontendFacade: Constructor> + abstract val converter: Constructor> + override fun TestConfigurationBuilder.configuration() { globalDefaults { frontend = this@AbstractIrTextTestBase.frontend @@ -52,32 +63,48 @@ abstract class AbstractIrTextTestBase( ::CodegenHelpersSourceFilesProvider, ) - useFrontendFacades( - ::ClassicFrontendFacade, - ::FirFrontendFacade - ) + facadeStep(frontendFacade) + classicFrontendHandlersStep { + useHandlers( + ::NoCompilationErrorsHandler + ) + } - useFrontendHandlers( - ::NoCompilationErrorsHandler, - ::NoFirCompilationErrorsHandler, - ) + firHandlersStep { + useHandlers( + ::NoFirCompilationErrorsHandler + ) + } - useFrontend2BackendConverters( - ::ClassicFrontend2IrConverter, - ::Fir2IrResultsConverter - ) + facadeStep(converter) - useBackendHandlers( - ::IrTextDumpHandler, - ::IrTreeVerifierHandler, - ::IrPrettyKotlinDumpHandler - ) + irHandlersStep { + useHandlers( + ::IrTextDumpHandler, + ::IrTreeVerifierHandler, + ::IrPrettyKotlinDumpHandler + ) + } } } -open class AbstractIrTextTest : AbstractIrTextTestBase(FrontendKinds.ClassicFrontend) +open class AbstractIrTextTest : AbstractIrTextTestBase() { + override val frontend: FrontendKind<*> + get() = FrontendKinds.ClassicFrontend + override val frontendFacade: Constructor> + get() = ::ClassicFrontendFacade + override val converter: Constructor> + get() = ::ClassicFrontend2IrConverter +} + +open class AbstractFir2IrTextTest : AbstractIrTextTestBase() { + override val frontend: FrontendKind<*> + get() = FrontendKinds.FIR + override val frontendFacade: Constructor> + get() = ::FirFrontendFacade + override val converter: Constructor> + get() = ::Fir2IrResultsConverter -open class AbstractFir2IrTextTest : AbstractIrTextTestBase(FrontendKinds.FIR) { override fun configure(builder: TestConfigurationBuilder) { super.configure(builder) with(builder) { diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/ir/interpreter/AbstractIrInterpreterAfterFir2IrTest.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/ir/interpreter/AbstractIrInterpreterAfterFir2IrTest.kt index 5da0245c656..7c7e3197d89 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/ir/interpreter/AbstractIrInterpreterAfterFir2IrTest.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/ir/interpreter/AbstractIrInterpreterAfterFir2IrTest.kt @@ -12,14 +12,14 @@ import org.jetbrains.kotlin.platform.jvm.JvmPlatforms import org.jetbrains.kotlin.test.TargetBackend import org.jetbrains.kotlin.test.backend.BlackBoxCodegenSuppressor import org.jetbrains.kotlin.test.backend.handlers.IrInterpreterBackendHandler -import org.jetbrains.kotlin.test.backend.ir.JvmIrBackendFacade -import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder +import org.jetbrains.kotlin.test.backend.handlers.NoFirCompilationErrorsHandler +import org.jetbrains.kotlin.test.builders.* import org.jetbrains.kotlin.test.directives.JvmEnvironmentConfigurationDirectives -import org.jetbrains.kotlin.test.directives.model.RegisteredDirectives import org.jetbrains.kotlin.test.directives.LanguageSettingsDirectives -import org.jetbrains.kotlin.test.frontend.fir.Fir2IrResultsConverter -import org.jetbrains.kotlin.test.frontend.fir.FirFrontendFacade -import org.jetbrains.kotlin.test.model.* +import org.jetbrains.kotlin.test.directives.model.RegisteredDirectives +import org.jetbrains.kotlin.test.model.BinaryKind +import org.jetbrains.kotlin.test.model.DependencyKind +import org.jetbrains.kotlin.test.model.FrontendKinds import org.jetbrains.kotlin.test.preprocessors.IrInterpreterImplicitKotlinImports import org.jetbrains.kotlin.test.runners.AbstractKotlinCompilerWithTargetBackendTest import org.jetbrains.kotlin.test.services.EnvironmentConfigurator @@ -50,15 +50,19 @@ open class AbstractIrInterpreterAfterFir2IrTest : AbstractKotlinCompilerWithTarg ::JvmEnvironmentConfigurator, ) + firFrontendStep() + fir2IrStep() + + irHandlersStep { + useHandlers(::IrInterpreterBackendHandler) + } + + useAdditionalSourceProviders(::IrInterpreterHelpersSourceFilesProvider) useSourcePreprocessor(::IrInterpreterImplicitKotlinImports) - useFrontendFacades(::FirFrontendFacade) - useFrontend2BackendConverters(::Fir2IrResultsConverter) - useBackendFacades(::JvmIrBackendFacade) useAfterAnalysisCheckers(::BlackBoxCodegenSuppressor) - useBackendHandlers(::IrInterpreterBackendHandler) enableMetaInfoHandler() } } @@ -68,6 +72,6 @@ class IrInterpreterEnvironmentConfigurator(testServices: TestServices) : Environ directives: RegisteredDirectives, languageVersion: LanguageVersion ): Map, Any?> { - return super.provideAdditionalAnalysisFlags(directives, languageVersion) + (AnalysisFlags.builtInsFromSources to true) + return mapOf(AnalysisFlags.builtInsFromSources to true) } -} \ No newline at end of file +} diff --git a/compiler/visualizer/tests/org/jetbrains/kotlin/visualizer/AbstractVisualizerBlackBoxTest.kt b/compiler/visualizer/tests/org/jetbrains/kotlin/visualizer/AbstractVisualizerBlackBoxTest.kt index 0605a1cadf6..de421e6c844 100644 --- a/compiler/visualizer/tests/org/jetbrains/kotlin/visualizer/AbstractVisualizerBlackBoxTest.kt +++ b/compiler/visualizer/tests/org/jetbrains/kotlin/visualizer/AbstractVisualizerBlackBoxTest.kt @@ -8,8 +8,9 @@ package org.jetbrains.kotlin.visualizer import org.jetbrains.kotlin.compiler.visualizer.FirVisualizer import org.jetbrains.kotlin.compiler.visualizer.PsiVisualizer import org.jetbrains.kotlin.platform.jvm.JvmPlatforms +import org.jetbrains.kotlin.test.Constructor +import org.jetbrains.kotlin.test.TestConfiguration import org.jetbrains.kotlin.test.TestRunner -import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder import org.jetbrains.kotlin.test.builders.testConfiguration import org.jetbrains.kotlin.test.directives.JvmEnvironmentConfigurationDirectives import org.jetbrains.kotlin.test.frontend.classic.ClassicFrontendFacade @@ -26,9 +27,14 @@ import org.jetbrains.kotlin.test.services.sourceProviders.CodegenHelpersSourceFi import org.jetbrains.kotlin.test.services.sourceProviders.CoroutineHelpersSourceFilesProvider abstract class AbstractVisualizerBlackBoxTest { - private val commonConfiguration: TestConfigurationBuilder.() -> Unit = { + private fun > createConfiguration( + filePath: String, + frontendKind: FrontendKind, + frontendFacade: Constructor> + ): TestConfiguration = testConfiguration(filePath) { assertions = JUnit5Assertions testInfo = KotlinTestInfo("_undefined_", "_testUndefined_", setOf()) + startingArtifactFactory = { ResultingArtifact.Source() } useAdditionalService(::TemporaryDirectoryManagerImpl) useAdditionalService(::BackendKindExtractorImpl) @@ -38,6 +44,7 @@ abstract class AbstractVisualizerBlackBoxTest { globalDefaults { targetPlatform = JvmPlatforms.defaultJvmPlatform dependencyKind = DependencyKind.Source + frontend = frontendKind } defaultDirectives { @@ -49,28 +56,20 @@ abstract class AbstractVisualizerBlackBoxTest { ::JvmEnvironmentConfigurator, ) - useFrontendFacades( - ::ClassicFrontendFacade, - ::FirFrontendFacade - ) - useAdditionalSourceProviders( ::AdditionalDiagnosticsSourceFilesProvider, ::CoroutineHelpersSourceFilesProvider, ::CodegenHelpersSourceFilesProvider ) - } - private fun createConfiguration(filePath: String, frontend: FrontendKind<*>) = testConfiguration(filePath) { - commonConfiguration() - globalDefaults { this.frontend = frontend } + facadeStep(frontendFacade) } fun runTest(filePath: String) { lateinit var psiRenderResult: String lateinit var firRenderResult: String - val psiConfiguration = createConfiguration(filePath, FrontendKinds.ClassicFrontend) + val psiConfiguration = createConfiguration(filePath, FrontendKinds.ClassicFrontend, ::ClassicFrontendFacade) TestRunner(psiConfiguration).runTest(filePath) { testConfiguration -> testConfiguration.testServices.moduleStructure.modules.forEach { psiModule -> val psiArtifact = testConfiguration.testServices.dependencyProvider.getArtifact(psiModule, FrontendKinds.ClassicFrontend) @@ -79,7 +78,7 @@ abstract class AbstractVisualizerBlackBoxTest { } } - val firConfiguration = createConfiguration(filePath, FrontendKinds.FIR) + val firConfiguration = createConfiguration(filePath, FrontendKinds.FIR, ::FirFrontendFacade) TestRunner(firConfiguration).runTest(filePath) { testConfiguration -> testConfiguration.testServices.moduleStructure.modules.forEach { firModule -> val firArtifact = testConfiguration.testServices.dependencyProvider.getArtifact(firModule, FrontendKinds.FIR) diff --git a/compiler/visualizer/tests/org/jetbrains/kotlin/visualizer/AbstractVisualizerTest.kt b/compiler/visualizer/tests/org/jetbrains/kotlin/visualizer/AbstractVisualizerTest.kt index 6df6863cc42..0c9943962d1 100644 --- a/compiler/visualizer/tests/org/jetbrains/kotlin/visualizer/AbstractVisualizerTest.kt +++ b/compiler/visualizer/tests/org/jetbrains/kotlin/visualizer/AbstractVisualizerTest.kt @@ -33,11 +33,12 @@ abstract class AbstractVisualizerTest : AbstractKotlinCompilerTest() { ::CommonEnvironmentConfigurator, ::JvmEnvironmentConfigurator, ) - useFrontendFacades( - ::FirFrontendFacade, - ::ClassicFrontendFacade - ) - useFrontendHandlers(handler) + // TODO +// useFrontendFacades( +// ::FirFrontendFacade, +// ::ClassicFrontendFacade +// ) +// useFrontendHandlers(handler) defaultDirectives { +JvmEnvironmentConfigurationDirectives.WITH_STDLIB diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/compiler/based/AbstractCompilerBasedTest.kt b/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/compiler/based/AbstractCompilerBasedTest.kt index c0ad9ecb8d7..3bdce7ff338 100644 --- a/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/compiler/based/AbstractCompilerBasedTest.kt +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/compiler/based/AbstractCompilerBasedTest.kt @@ -83,10 +83,9 @@ abstract class AbstractCompilerBasedTest : AbstractKotlinCompilerTest() { configureTest() defaultConfiguration(this) - unregisterAllFacades() + useAdditionalService(::TestModuleInfoProvider) usePreAnalysisHandlers(::ModuleRegistrarPreAnalysisHandler.bind(disposable)) - useFrontendFacades(::LowLevelFirFrontendFacade) } open fun TestConfigurationBuilder.configureTest() {} diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/AbstractDiagnosisCompilerTestDataSpecTest.kt b/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/AbstractDiagnosisCompilerTestDataSpecTest.kt index 8493aada9da..8257d87f1b0 100644 --- a/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/AbstractDiagnosisCompilerTestDataSpecTest.kt +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/AbstractDiagnosisCompilerTestDataSpecTest.kt @@ -13,8 +13,8 @@ import org.jetbrains.kotlin.test.runners.baseFirSpecDiagnosticTestConfiguration abstract class AbstractDiagnosisCompilerTestDataSpecTest : AbstractCompilerBasedTest() { override fun TestConfigurationBuilder.configureTest() { - baseFirDiagnosticTestConfiguration() + baseFirDiagnosticTestConfiguration(frontendFacade = ::LowLevelFirFrontendFacade) baseFirSpecDiagnosticTestConfiguration() addIdeTestIgnoreHandler() } -} \ No newline at end of file +} diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/AbstractDiagnosisCompilerTestDataTest.kt b/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/AbstractDiagnosisCompilerTestDataTest.kt index 25ab7c6a4d5..52b2cf8937f 100644 --- a/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/AbstractDiagnosisCompilerTestDataTest.kt +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/AbstractDiagnosisCompilerTestDataTest.kt @@ -12,7 +12,7 @@ import org.jetbrains.kotlin.test.runners.baseFirDiagnosticTestConfiguration abstract class AbstractDiagnosisCompilerTestDataTest : AbstractCompilerBasedTest() { override fun TestConfigurationBuilder.configureTest() { - baseFirDiagnosticTestConfiguration() + baseFirDiagnosticTestConfiguration(frontendFacade = ::LowLevelFirFrontendFacade) addIdeTestIgnoreHandler() } -} \ No newline at end of file +} diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/test/base/AbstractLowLevelApiTest.kt b/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/test/base/AbstractLowLevelApiTest.kt index 972deab237f..6582bd9847e 100644 --- a/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/test/base/AbstractLowLevelApiTest.kt +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/test/base/AbstractLowLevelApiTest.kt @@ -24,6 +24,7 @@ import org.jetbrains.kotlin.test.builders.testConfiguration import org.jetbrains.kotlin.test.directives.JvmEnvironmentConfigurationDirectives import org.jetbrains.kotlin.test.model.DependencyKind import org.jetbrains.kotlin.test.model.FrontendKinds +import org.jetbrains.kotlin.test.model.ResultingArtifact import org.jetbrains.kotlin.test.runners.AbstractKotlinCompilerTest import org.jetbrains.kotlin.test.services.* import org.jetbrains.kotlin.test.services.configuration.CommonEnvironmentConfigurator @@ -61,6 +62,7 @@ abstract class AbstractLowLevelApiTest : TestWithDisposable() { usePreAnalysisHandlers(::ModuleRegistrarPreAnalysisHandler.bind(disposable)) configureTest(this) + startingArtifactFactory = { ResultingArtifact.Source() } this.testInfo = this@AbstractLowLevelApiTest.testInfo } @@ -136,4 +138,4 @@ fun String.indexOfOrNull(substring: String) = indexOf(substring).takeIf { it >= 0 } private fun String.indexOfOrNull(substring: String, startingIndex: Int) = - indexOf(substring, startingIndex).takeIf { it >= 0 } \ No newline at end of file + indexOf(substring, startingIndex).takeIf { it >= 0 }