Allow to auto-mute failed tests in RunnerWithIgnoreInDatabase
This commit is contained in:
@@ -7,6 +7,9 @@ package org.jetbrains.kotlin.test
|
|||||||
|
|
||||||
import junit.framework.TestCase
|
import junit.framework.TestCase
|
||||||
import org.junit.runner.Runner
|
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.BlockJUnit4ClassRunner
|
||||||
import org.junit.runners.model.FrameworkMethod
|
import org.junit.runners.model.FrameworkMethod
|
||||||
import org.junit.runners.parameterized.BlockJUnit4ClassRunnerWithParameters
|
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<String> = mutableListOf<String>() + firstLine + muted.sorted()
|
||||||
|
file.writeText(newMuted.joinToString("\n"))
|
||||||
|
}
|
||||||
|
|
||||||
private class MutedTest(
|
private class MutedTest(
|
||||||
val key: String,
|
val key: String,
|
||||||
@Suppress("unused") val issue: String?,
|
@Suppress("unused") val issue: String?,
|
||||||
@@ -161,14 +174,7 @@ internal fun wrapWithMuteInDatabase(testCase: TestCase, f: () -> Unit): (() -> U
|
|||||||
try {
|
try {
|
||||||
f()
|
f()
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
val file = File(doAutoMute.file)
|
doAutoMute.muteTest(testKey(testCase))
|
||||||
val lines = file.readLines()
|
|
||||||
val firstLine = lines[0]
|
|
||||||
val muted = lines.drop(1).toMutableList()
|
|
||||||
muted.add("${testKey(testCase)}, ${doAutoMute.issue}")
|
|
||||||
val newMuted: List<String> = mutableListOf<String>() + firstLine + muted.sorted()
|
|
||||||
file.writeText(newMuted.joinToString("\n"))
|
|
||||||
|
|
||||||
throw e
|
throw e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -193,6 +199,28 @@ class RunnerWithIgnoreInDatabase(klass: Class<*>?) : BlockJUnit4ClassRunner(klas
|
|||||||
override fun isIgnored(child: FrameworkMethod): Boolean {
|
override fun isIgnored(child: FrameworkMethod): Boolean {
|
||||||
return super.isIgnored(child) || isIgnoredInDatabaseWithLog(child)
|
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 {
|
fun isIgnoredInDatabaseWithLog(child: FrameworkMethod): Boolean {
|
||||||
|
|||||||
Reference in New Issue
Block a user