[Test] Add ability to disable specific handler if there was an error from previous one

This commit is contained in:
Dmitriy Novozhilov
2021-01-22 12:52:52 +03:00
parent 42f9442728
commit 5490689fea
8 changed files with 74 additions and 24 deletions
@@ -60,8 +60,14 @@ class TestRunner(private val testConfiguration: TestConfiguration) {
} catch (e: Throwable) {
failedException = e
}
for (handler in testConfiguration.getAllHandlers()) {
withAssertionCatching { handler.processAfterAllModules(failedAssertions.isNotEmpty()) }
withAssertionCatching {
val thereWasAnException = failedException != null || failedAssertions.isNotEmpty()
if (handler.shouldRun(thereWasAnException)) {
handler.processAfterAllModules(thereWasAnException)
}
}
}
if (testConfiguration.metaInfoHandlerEnabled) {
withAssertionCatching(insertExceptionInStart = true) {
@@ -103,7 +109,9 @@ class TestRunner(private val testConfiguration: TestConfiguration) {
val frontendHandlers: List<AnalysisHandler<*>> = testConfiguration.getHandlers(frontendKind)
for (frontendHandler in frontendHandlers) {
withAssertionCatching {
frontendHandler.hackyProcess(module, frontendArtifacts)
if (frontendHandler.shouldRun(failedAssertions.isNotEmpty())) {
frontendHandler.hackyProcess(module, frontendArtifacts)
}
}
}
@@ -115,7 +123,11 @@ class TestRunner(private val testConfiguration: TestConfiguration) {
val backendHandlers: List<AnalysisHandler<*>> = testConfiguration.getHandlers(backendKind)
for (backendHandler in backendHandlers) {
withAssertionCatching { backendHandler.hackyProcess(module, backendInputInfo) }
withAssertionCatching {
if (backendHandler.shouldRun(failedAssertions.isNotEmpty())) {
backendHandler.hackyProcess(module, backendInputInfo)
}
}
}
for (artifactKind in moduleStructure.getTargetArtifactKinds(module)) {
@@ -127,7 +139,11 @@ class TestRunner(private val testConfiguration: TestConfiguration) {
val binaryHandlers: List<AnalysisHandler<*>> = testConfiguration.getHandlers(artifactKind)
for (binaryHandler in binaryHandlers) {
withAssertionCatching { binaryHandler.hackyProcess(module, binaryArtifact) }
withAssertionCatching {
if (binaryHandler.shouldRun(failedAssertions.isNotEmpty())) {
binaryHandler.hackyProcess(module, binaryArtifact)
}
}
}
}
}
@@ -143,6 +159,10 @@ class TestRunner(private val testConfiguration: TestConfiguration) {
}
}
}
private fun AnalysisHandler<*>.shouldRun(thereWasAnException: Boolean): Boolean {
return !(doNotRunIfThereWerePreviousFailures && thereWasAnException)
}
}
// ----------------------------------------------------------------------------------------------------------------
@@ -11,7 +11,10 @@ import org.jetbrains.kotlin.test.services.ServiceRegistrationData
import org.jetbrains.kotlin.test.services.TestServices
import org.jetbrains.kotlin.test.services.assertions
abstract class AnalysisHandler<A : ResultingArtifact<A>>(val testServices: TestServices) {
abstract class AnalysisHandler<A : ResultingArtifact<A>>(
val testServices: TestServices,
val doNotRunIfThereWerePreviousFailures: Boolean
) {
protected val assertions: Assertions
get() = testServices.assertions
@@ -30,15 +33,18 @@ abstract class AnalysisHandler<A : ResultingArtifact<A>>(val testServices: TestS
abstract class FrontendOutputHandler<R : ResultingArtifact.FrontendOutput<R>>(
testServices: TestServices,
override val artifactKind: FrontendKind<R>
) : AnalysisHandler<R>(testServices)
override val artifactKind: FrontendKind<R>,
doNotRunIfThereWerePreviousFailures: Boolean
) : AnalysisHandler<R>(testServices, doNotRunIfThereWerePreviousFailures)
abstract class BackendInputHandler<I : ResultingArtifact.BackendInput<I>>(
testServices: TestServices,
override val artifactKind: BackendKind<I>
) : AnalysisHandler<I>(testServices)
override val artifactKind: BackendKind<I>,
doNotRunIfThereWerePreviousFailures: Boolean
) : AnalysisHandler<I>(testServices, doNotRunIfThereWerePreviousFailures)
abstract class BinaryArtifactHandler<A : ResultingArtifact.Binary<A>>(
testServices: TestServices,
override val artifactKind: BinaryKind<A>
) : AnalysisHandler<A>(testServices)
override val artifactKind: BinaryKind<A>,
doNotRunIfThereWerePreviousFailures: Boolean
) : AnalysisHandler<A>(testServices, doNotRunIfThereWerePreviousFailures)