[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
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.assertions
@@ -14,6 +15,9 @@ abstract class AnalysisHandler<A : ResultingArtifact<A>>(
val failureDisablesNextSteps: Boolean,
val doNotRunIfThereWerePreviousFailures: Boolean
) : ServicesAndDirectivesContainer {
open val additionalAfterAnalysisCheckers: List<Constructor<AfterAnalysisChecker>>
get() = emptyList()
protected val assertions: 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.DirectivesContainer
import org.jetbrains.kotlin.test.directives.model.RegisteredDirectives
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.model.*
import org.jetbrains.kotlin.test.services.*
import org.jetbrains.kotlin.test.services.impl.ModuleStructureExtractorImpl
import org.jetbrains.kotlin.test.utils.TestDisposable
@@ -93,14 +90,12 @@ class TestConfigurationImpl(
constructor.invoke(testServices).also { it.registerDirectivesAndServices() }
}
override val afterAnalysisCheckers: List<AfterAnalysisChecker> = afterAnalysisCheckers.map { constructor ->
constructor.invoke(testServices).also { it.registerDirectivesAndServices() }
}
init {
testServices.apply {
register(EnvironmentConfiguratorsProvider::class, EnvironmentConfiguratorsProvider(this@TestConfigurationImpl.environmentConfigurators))
@OptIn(ExperimentalStdlibApi::class)
register(
EnvironmentConfiguratorsProvider::class,
EnvironmentConfiguratorsProvider(this@TestConfigurationImpl.environmentConfigurators)
)
val sourceFilePreprocessors = sourcePreprocessors.map { it.invoke(this@apply) }
val sourceFileProvider = SourceFileProviderImpl(this, sourceFilePreprocessors)
register(SourceFileProvider::class, sourceFileProvider)
@@ -120,14 +115,28 @@ class TestConfigurationImpl(
}
}
override val steps: List<TestStep<*, *>> = steps
.map { it.createTestStep(testServices) }
.onEach { step ->
when (step) {
is TestStep.FacadeStep<*, *> -> step.facade.registerDirectivesAndServices()
is TestStep.HandlersStep<*> -> step.handlers.registerDirectivesAndServices()
override val steps: List<TestStep<*, *>>
override val afterAnalysisCheckers: List<AfterAnalysisChecker>
init {
val afterAnalysisCheckerConstructors = mutableSetOf<Constructor<AfterAnalysisChecker>>()
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 ----------------------------------