diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/test/muteWithDatabase.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/test/muteWithDatabase.kt index 248c5d8b8da..ba0cccbd466 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/test/muteWithDatabase.kt +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/test/muteWithDatabase.kt @@ -7,6 +7,9 @@ package org.jetbrains.kotlin.test import junit.framework.TestCase import org.junit.runner.Runner +import org.junit.runner.notification.Failure +import org.junit.runner.notification.RunListener +import org.junit.runner.notification.RunNotifier import org.junit.runners.BlockJUnit4ClassRunner import org.junit.runners.model.FrameworkMethod import org.junit.runners.parameterized.BlockJUnit4ClassRunnerWithParameters @@ -32,6 +35,16 @@ private val DO_AUTO_MUTE: AutoMute? by lazy { } } +private fun AutoMute.muteTest(testKey: String) { + val file = File(file) + val lines = file.readLines() + val firstLine = lines[0] // Drop file header + val muted = lines.drop(1).toMutableList() + muted.add("$testKey, $issue") + val newMuted: List = mutableListOf() + firstLine + muted.sorted() + file.writeText(newMuted.joinToString("\n")) +} + private class MutedTest( val key: String, @Suppress("unused") val issue: String?, @@ -161,14 +174,7 @@ internal fun wrapWithMuteInDatabase(testCase: TestCase, f: () -> Unit): (() -> U try { f() } catch (e: Throwable) { - val file = File(doAutoMute.file) - val lines = file.readLines() - val firstLine = lines[0] - val muted = lines.drop(1).toMutableList() - muted.add("${testKey(testCase)}, ${doAutoMute.issue}") - val newMuted: List = mutableListOf() + firstLine + muted.sorted() - file.writeText(newMuted.joinToString("\n")) - + doAutoMute.muteTest(testKey(testCase)) throw e } } @@ -193,6 +199,28 @@ class RunnerWithIgnoreInDatabase(klass: Class<*>?) : BlockJUnit4ClassRunner(klas override fun isIgnored(child: FrameworkMethod): Boolean { return super.isIgnored(child) || isIgnoredInDatabaseWithLog(child) } + + override fun runChild(method: FrameworkMethod, notifier: RunNotifier) { + val doAutoMute = DO_AUTO_MUTE + if (doAutoMute == null) { + super.runChild(method, notifier) + return + } + + val muteFailureListener = object : RunListener() { + override fun testFailure(failure: Failure) { + doAutoMute.muteTest(testKey(method.declaringClass, method.name)) + super.testFailure(failure) + } + } + + try { + notifier.addListener(muteFailureListener) + super.runChild(method, notifier) + } finally { + notifier.removeListener(muteFailureListener) + } + } } fun isIgnoredInDatabaseWithLog(child: FrameworkMethod): Boolean {