[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) { } catch (e: Throwable) {
failedException = e failedException = e
} }
for (handler in testConfiguration.getAllHandlers()) { 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) { if (testConfiguration.metaInfoHandlerEnabled) {
withAssertionCatching(insertExceptionInStart = true) { withAssertionCatching(insertExceptionInStart = true) {
@@ -103,7 +109,9 @@ class TestRunner(private val testConfiguration: TestConfiguration) {
val frontendHandlers: List<AnalysisHandler<*>> = testConfiguration.getHandlers(frontendKind) val frontendHandlers: List<AnalysisHandler<*>> = testConfiguration.getHandlers(frontendKind)
for (frontendHandler in frontendHandlers) { for (frontendHandler in frontendHandlers) {
withAssertionCatching { 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) val backendHandlers: List<AnalysisHandler<*>> = testConfiguration.getHandlers(backendKind)
for (backendHandler in backendHandlers) { 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)) { for (artifactKind in moduleStructure.getTargetArtifactKinds(module)) {
@@ -127,7 +139,11 @@ class TestRunner(private val testConfiguration: TestConfiguration) {
val binaryHandlers: List<AnalysisHandler<*>> = testConfiguration.getHandlers(artifactKind) val binaryHandlers: List<AnalysisHandler<*>> = testConfiguration.getHandlers(artifactKind)
for (binaryHandler in binaryHandlers) { 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.TestServices
import org.jetbrains.kotlin.test.services.assertions 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 protected val assertions: Assertions
get() = testServices.assertions get() = testServices.assertions
@@ -30,15 +33,18 @@ abstract class AnalysisHandler<A : ResultingArtifact<A>>(val testServices: TestS
abstract class FrontendOutputHandler<R : ResultingArtifact.FrontendOutput<R>>( abstract class FrontendOutputHandler<R : ResultingArtifact.FrontendOutput<R>>(
testServices: TestServices, testServices: TestServices,
override val artifactKind: FrontendKind<R> override val artifactKind: FrontendKind<R>,
) : AnalysisHandler<R>(testServices) doNotRunIfThereWerePreviousFailures: Boolean
) : AnalysisHandler<R>(testServices, doNotRunIfThereWerePreviousFailures)
abstract class BackendInputHandler<I : ResultingArtifact.BackendInput<I>>( abstract class BackendInputHandler<I : ResultingArtifact.BackendInput<I>>(
testServices: TestServices, testServices: TestServices,
override val artifactKind: BackendKind<I> override val artifactKind: BackendKind<I>,
) : AnalysisHandler<I>(testServices) doNotRunIfThereWerePreviousFailures: Boolean
) : AnalysisHandler<I>(testServices, doNotRunIfThereWerePreviousFailures)
abstract class BinaryArtifactHandler<A : ResultingArtifact.Binary<A>>( abstract class BinaryArtifactHandler<A : ResultingArtifact.Binary<A>>(
testServices: TestServices, testServices: TestServices,
override val artifactKind: BinaryKind<A> override val artifactKind: BinaryKind<A>,
) : AnalysisHandler<A>(testServices) doNotRunIfThereWerePreviousFailures: Boolean
) : AnalysisHandler<A>(testServices, doNotRunIfThereWerePreviousFailures)
@@ -10,4 +10,7 @@ import org.jetbrains.kotlin.test.model.BackendInputHandler
import org.jetbrains.kotlin.test.model.BackendKinds import org.jetbrains.kotlin.test.model.BackendKinds
import org.jetbrains.kotlin.test.services.TestServices import org.jetbrains.kotlin.test.services.TestServices
abstract class AbstractIrHandler(testServices: TestServices) : BackendInputHandler<IrBackendInput>(testServices, BackendKinds.IrBackend) abstract class AbstractIrHandler(
testServices: TestServices,
doNotRunIfThereWerePreviousFailures: Boolean = false
) : BackendInputHandler<IrBackendInput>(testServices, BackendKinds.IrBackend, doNotRunIfThereWerePreviousFailures)
@@ -11,13 +11,28 @@ import org.jetbrains.kotlin.test.model.BinaryArtifacts
import org.jetbrains.kotlin.test.services.TestServices import org.jetbrains.kotlin.test.services.TestServices
abstract class JvmBinaryArtifactHandler( abstract class JvmBinaryArtifactHandler(
testServices: TestServices testServices: TestServices,
) : BinaryArtifactHandler<BinaryArtifacts.Jvm>(testServices, ArtifactKinds.Jvm) doNotRunIfThereWerePreviousFailures: Boolean = false
) : BinaryArtifactHandler<BinaryArtifacts.Jvm>(
testServices,
ArtifactKinds.Jvm,
doNotRunIfThereWerePreviousFailures
)
abstract class JsBinaryArtifactHandler( abstract class JsBinaryArtifactHandler(
testServices: TestServices testServices: TestServices,
) : BinaryArtifactHandler<BinaryArtifacts.Js>(testServices, ArtifactKinds.Js) doNotRunIfThereWerePreviousFailures: Boolean = false
) : BinaryArtifactHandler<BinaryArtifacts.Js>(
testServices,
ArtifactKinds.Js,
doNotRunIfThereWerePreviousFailures
)
abstract class NativeBinaryArtifactHandler( abstract class NativeBinaryArtifactHandler(
testServices: TestServices testServices: TestServices,
) : BinaryArtifactHandler<BinaryArtifacts.Native>(testServices, ArtifactKinds.Native) doNotRunIfThereWerePreviousFailures: Boolean = false
) : BinaryArtifactHandler<BinaryArtifacts.Native>(
testServices,
ArtifactKinds.Native,
doNotRunIfThereWerePreviousFailures
)
@@ -15,7 +15,7 @@ import org.jetbrains.kotlin.test.model.BinaryArtifacts
import org.jetbrains.kotlin.test.model.TestModule import org.jetbrains.kotlin.test.model.TestModule
import org.jetbrains.kotlin.test.services.TestServices import org.jetbrains.kotlin.test.services.TestServices
class DxCheckerHandler(testServices: TestServices) : JvmBinaryArtifactHandler(testServices) { class DxCheckerHandler(testServices: TestServices) : JvmBinaryArtifactHandler(testServices, doNotRunIfThereWerePreviousFailures = true) {
override val directivesContainers: List<DirectivesContainer> override val directivesContainers: List<DirectivesContainer>
get() = listOf(CodegenTestDirectives) get() = listOf(CodegenTestDirectives)
@@ -26,7 +26,7 @@ import org.jetbrains.kotlin.utils.addToStdlib.runIf
import java.lang.reflect.Method import java.lang.reflect.Method
import java.net.URLClassLoader import java.net.URLClassLoader
class JvmBoxRunner(testServices: TestServices) : JvmBinaryArtifactHandler(testServices) { class JvmBoxRunner(testServices: TestServices) : JvmBinaryArtifactHandler(testServices, doNotRunIfThereWerePreviousFailures = true) {
companion object { companion object {
private val BOX_IN_SEPARATE_PROCESS_PORT = System.getProperty("kotlin.test.box.in.separate.process.port") private val BOX_IN_SEPARATE_PROCESS_PORT = System.getProperty("kotlin.test.box.in.separate.process.port")
} }
@@ -11,7 +11,12 @@ import org.jetbrains.kotlin.test.model.FrontendOutputHandler
import org.jetbrains.kotlin.test.services.TestServices import org.jetbrains.kotlin.test.services.TestServices
abstract class ClassicFrontendAnalysisHandler( abstract class ClassicFrontendAnalysisHandler(
testServices: TestServices testServices: TestServices,
) : FrontendOutputHandler<ClassicFrontendOutputArtifact>(testServices, FrontendKinds.ClassicFrontend) doNotRunIfThereWerePreviousFailures: Boolean = false
) : FrontendOutputHandler<ClassicFrontendOutputArtifact>(
testServices,
FrontendKinds.ClassicFrontend,
doNotRunIfThereWerePreviousFailures
)
@@ -12,8 +12,9 @@ import org.jetbrains.kotlin.test.services.TestServices
import java.io.File import java.io.File
abstract class FirAnalysisHandler( abstract class FirAnalysisHandler(
testServices: TestServices testServices: TestServices,
) : FrontendOutputHandler<FirOutputArtifact>(testServices, FrontendKinds.FIR) { doNotRunIfThereWerePreviousFailures: Boolean = false
) : FrontendOutputHandler<FirOutputArtifact>(testServices, FrontendKinds.FIR, doNotRunIfThereWerePreviousFailures) {
protected val File.nameWithoutFirExtension: String protected val File.nameWithoutFirExtension: String
get() = nameWithoutExtension.removeSuffix(".fir") get() = nameWithoutExtension.removeSuffix(".fir")
} }