[Test] Add an ability for AnalysisHandler automatically register AfterAnalysisCheckers

This is needed for cases like dump handlers to register corresponding
  checkers, which compares identity of dumps for different configurations,
  like `IrTextDumpHandler` and `FirIrDumpIdenticalChecker`
This commit is contained in:
Dmitriy Novozhilov
2024-02-16 09:57:55 +02:00
committed by Space Team
parent 60bf15d654
commit ad27d04e68
2 changed files with 29 additions and 16 deletions
@@ -6,6 +6,7 @@
package org.jetbrains.kotlin.test.model package org.jetbrains.kotlin.test.model
import org.jetbrains.kotlin.test.Assertions import org.jetbrains.kotlin.test.Assertions
import org.jetbrains.kotlin.test.Constructor
import org.jetbrains.kotlin.test.services.TestServices import org.jetbrains.kotlin.test.services.TestServices
import org.jetbrains.kotlin.test.services.assertions import org.jetbrains.kotlin.test.services.assertions
@@ -14,6 +15,9 @@ abstract class AnalysisHandler<A : ResultingArtifact<A>>(
val failureDisablesNextSteps: Boolean, val failureDisablesNextSteps: Boolean,
val doNotRunIfThereWerePreviousFailures: Boolean val doNotRunIfThereWerePreviousFailures: Boolean
) : ServicesAndDirectivesContainer { ) : ServicesAndDirectivesContainer {
open val additionalAfterAnalysisCheckers: List<Constructor<AfterAnalysisChecker>>
get() = emptyList()
protected val assertions: Assertions protected val assertions: Assertions
get() = testServices.assertions get() = testServices.assertions
@@ -11,10 +11,7 @@ import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder
import org.jetbrains.kotlin.test.directives.model.ComposedDirectivesContainer import org.jetbrains.kotlin.test.directives.model.ComposedDirectivesContainer
import org.jetbrains.kotlin.test.directives.model.DirectivesContainer import org.jetbrains.kotlin.test.directives.model.DirectivesContainer
import org.jetbrains.kotlin.test.directives.model.RegisteredDirectives import org.jetbrains.kotlin.test.directives.model.RegisteredDirectives
import org.jetbrains.kotlin.test.model.AfterAnalysisChecker import org.jetbrains.kotlin.test.model.*
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.*
import org.jetbrains.kotlin.test.services.impl.ModuleStructureExtractorImpl import org.jetbrains.kotlin.test.services.impl.ModuleStructureExtractorImpl
import org.jetbrains.kotlin.test.utils.TestDisposable import org.jetbrains.kotlin.test.utils.TestDisposable
@@ -93,14 +90,12 @@ class TestConfigurationImpl(
constructor.invoke(testServices).also { it.registerDirectivesAndServices() } constructor.invoke(testServices).also { it.registerDirectivesAndServices() }
} }
override val afterAnalysisCheckers: List<AfterAnalysisChecker> = afterAnalysisCheckers.map { constructor ->
constructor.invoke(testServices).also { it.registerDirectivesAndServices() }
}
init { init {
testServices.apply { testServices.apply {
register(EnvironmentConfiguratorsProvider::class, EnvironmentConfiguratorsProvider(this@TestConfigurationImpl.environmentConfigurators)) register(
@OptIn(ExperimentalStdlibApi::class) EnvironmentConfiguratorsProvider::class,
EnvironmentConfiguratorsProvider(this@TestConfigurationImpl.environmentConfigurators)
)
val sourceFilePreprocessors = sourcePreprocessors.map { it.invoke(this@apply) } val sourceFilePreprocessors = sourcePreprocessors.map { it.invoke(this@apply) }
val sourceFileProvider = SourceFileProviderImpl(this, sourceFilePreprocessors) val sourceFileProvider = SourceFileProviderImpl(this, sourceFilePreprocessors)
register(SourceFileProvider::class, sourceFileProvider) register(SourceFileProvider::class, sourceFileProvider)
@@ -120,14 +115,28 @@ class TestConfigurationImpl(
} }
} }
override val steps: List<TestStep<*, *>> = steps override val steps: List<TestStep<*, *>>
.map { it.createTestStep(testServices) } override val afterAnalysisCheckers: List<AfterAnalysisChecker>
.onEach { step ->
when (step) { init {
is TestStep.FacadeStep<*, *> -> step.facade.registerDirectivesAndServices() val afterAnalysisCheckerConstructors = mutableSetOf<Constructor<AfterAnalysisChecker>>()
is TestStep.HandlersStep<*> -> step.handlers.registerDirectivesAndServices()
this.steps = steps
.map { it.createTestStep(testServices) }
.onEach { step ->
when (step) {
is TestStep.FacadeStep<*, *> -> step.facade.registerDirectivesAndServices()
is TestStep.HandlersStep<*> -> {
step.handlers.registerDirectivesAndServices()
step.handlers.flatMapTo(afterAnalysisCheckerConstructors) { it.additionalAfterAnalysisCheckers }
}
}
} }
afterAnalysisCheckerConstructors.addAll(afterAnalysisCheckers)
this.afterAnalysisCheckers = afterAnalysisCheckerConstructors.map { constructor ->
constructor.invoke(testServices).also { it.registerDirectivesAndServices() }
} }
}
// ---------------------------------- utils ---------------------------------- // ---------------------------------- utils ----------------------------------