[Test] Handle any Throwable from test instead of AssertionError

This commit is contained in:
Dmitriy Novozhilov
2021-01-22 12:34:56 +03:00
parent c111c33950
commit 42f9442728
11 changed files with 21 additions and 17 deletions
@@ -8,4 +8,7 @@ package org.jetbrains.kotlin.test
class ExceptionFromTestError(cause: Throwable) : AssertionError(cause) {
override val message: String
get() = "Exception was thrown"
override val cause: Throwable
get() = super.cause!!
}
@@ -12,7 +12,7 @@ import org.jetbrains.kotlin.test.services.*
import java.io.IOException
class TestRunner(private val testConfiguration: TestConfiguration) {
private val failedAssertions = mutableListOf<AssertionError>()
private val failedAssertions = mutableListOf<Throwable>()
fun runTest(@TestDataFile testDataFileName: String) {
try {
@@ -79,9 +79,10 @@ class TestRunner(private val testConfiguration: TestConfiguration) {
}
val filteredFailedAssertions = testConfiguration.afterAnalysisCheckers
.fold<AfterAnalysisChecker, List<AssertionError>>(failedAssertions) { assertions, checker ->
.fold<AfterAnalysisChecker, List<Throwable>>(failedAssertions) { assertions, checker ->
checker.suppressIfNeeded(assertions)
}
.map { if (it is ExceptionFromTestError) it.cause else it }
services.assertions.assertAll(filteredFailedAssertions)
}
@@ -134,7 +135,7 @@ class TestRunner(private val testConfiguration: TestConfiguration) {
private inline fun withAssertionCatching(insertExceptionInStart: Boolean = false, block: () -> Unit) {
try {
block()
} catch (e: AssertionError) {
} catch (e: Throwable) {
if (insertExceptionInStart) {
failedAssertions.add(0, e)
} else {
@@ -12,7 +12,7 @@ abstract class AfterAnalysisChecker(protected val testServices: TestServices) {
open val directives: List<DirectivesContainer>
get() = emptyList()
open fun check(failedAssertions: List<AssertionError>) {}
open fun check(failedAssertions: List<Throwable>) {}
open fun suppressIfNeeded(failedAssertions: List<AssertionError>): List<AssertionError> = failedAssertions
open fun suppressIfNeeded(failedAssertions: List<Throwable>): List<Throwable> = failedAssertions
}