Support mute tests in kotlin-gradle-plugin-integration-tests (KTI-234)
#KTI-234 Fixed
This commit is contained in:
@@ -6,10 +6,13 @@
|
||||
package org.jetbrains.kotlin.test
|
||||
|
||||
import junit.framework.TestCase
|
||||
import org.jetbrains.kotlin.test.mutes.*
|
||||
import org.jetbrains.kotlin.test.mutes.MutedTest
|
||||
import org.jetbrains.kotlin.test.mutes.getMutedTest
|
||||
import org.jetbrains.kotlin.test.mutes.mutedSet
|
||||
import org.junit.internal.runners.statements.InvokeMethod
|
||||
import org.junit.runner.Runner
|
||||
import org.junit.runner.notification.RunNotifier
|
||||
import org.junit.runners.BlockJUnit4ClassRunner
|
||||
import org.junit.runners.model.FrameworkMethod
|
||||
import org.junit.runners.model.Statement
|
||||
import org.junit.runners.parameterized.BlockJUnit4ClassRunnerWithParameters
|
||||
@@ -84,24 +87,7 @@ class RunnerFactoryWithMuteInDatabase : ParametersRunnerFactory {
|
||||
}
|
||||
|
||||
override fun methodInvoker(method: FrameworkMethod, test: Any?): Statement {
|
||||
return object : InvokeMethod(method, test) {
|
||||
override fun evaluate() {
|
||||
val methodClass = method.declaringClass
|
||||
val methodKey = parametrizedMethodKey(method, name)
|
||||
val mutedTest = getMutedTest(methodClass, methodKey) ?: getMutedTest(methodClass, method.method.name)
|
||||
if (isPresentedInDatabaseWithoutFailMarker(mutedTest)) {
|
||||
if (mutedTest?.isFlaky == true) {
|
||||
super.evaluate()
|
||||
return
|
||||
} else {
|
||||
val testKey = testKey(methodClass, methodKey)
|
||||
invertMutedTestResultWithLog({ super.evaluate() }, testKey)
|
||||
return
|
||||
}
|
||||
}
|
||||
super.evaluate()
|
||||
}
|
||||
}
|
||||
return MethodInvokerWithMutedTests(method, test, mainMethodKey = parametrizedMethodKey(method, name))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -109,6 +95,44 @@ class RunnerFactoryWithMuteInDatabase : ParametersRunnerFactory {
|
||||
private fun parametrizedMethodKey(child: FrameworkMethod, parametersName: String) = "${child.method.name}$parametersName"
|
||||
}
|
||||
|
||||
class MethodInvokerWithMutedTests(val method: FrameworkMethod, val test: Any?, val mainMethodKey: String? = null) : InvokeMethod(method, test) {
|
||||
override fun evaluate() {
|
||||
val methodClass = method.declaringClass
|
||||
val mutedTest =
|
||||
mainMethodKey?.let { getMutedTest(methodClass, it) }
|
||||
?: getMutedTest(methodClass, method.method.name)
|
||||
|
||||
if (mutedTest != null && isPresentedInDatabaseWithoutFailMarker(mutedTest)) {
|
||||
if (mutedTest.isFlaky) {
|
||||
super.evaluate()
|
||||
return
|
||||
} else {
|
||||
val testKey = testKey(methodClass, mutedTest.methodKey)
|
||||
invertMutedTestResultWithLog({ super.evaluate() }, testKey)
|
||||
return
|
||||
}
|
||||
}
|
||||
super.evaluate()
|
||||
}
|
||||
}
|
||||
|
||||
class RunnerWithMuteInDatabase(klass: Class<*>?) : BlockJUnit4ClassRunner(klass) {
|
||||
override fun isIgnored(child: FrameworkMethod): Boolean {
|
||||
return super.isIgnored(child) || isMutedInDatabaseWithLog(child.declaringClass, child.name)
|
||||
}
|
||||
|
||||
override fun runChild(method: FrameworkMethod, notifier: RunNotifier) {
|
||||
val testKey = testKey(method.declaringClass, method.name)
|
||||
notifier.withAutoMuteListener(testKey) {
|
||||
super.runChild(method, notifier)
|
||||
}
|
||||
}
|
||||
|
||||
override fun methodInvoker(method: FrameworkMethod, test: Any?): Statement {
|
||||
return MethodInvokerWithMutedTests(method, test)
|
||||
}
|
||||
}
|
||||
|
||||
private fun invertMutedTestResultWithLog(f: () -> Unit, testKey: String) {
|
||||
var isTestGreen = true
|
||||
try {
|
||||
|
||||
@@ -28,10 +28,22 @@ private fun loadMutedSet(files: List<File>): MutedSet {
|
||||
}
|
||||
|
||||
val mutedSet by lazy {
|
||||
val currentRootDir = File("")
|
||||
val projectRootDir =
|
||||
(currentRootDir.goUp("libraries/tools/kotlin-gradle-plugin-integration-tests") ?: currentRootDir).absoluteFile
|
||||
|
||||
loadMutedSet(
|
||||
listOf(
|
||||
File("tests/mute-common.csv"),
|
||||
File("tests/mute-platform.csv")
|
||||
)
|
||||
"tests/mute-common.csv",
|
||||
"tests/mute-platform.csv"
|
||||
).map { File(projectRootDir, it) }
|
||||
)
|
||||
}
|
||||
|
||||
private tailrec fun File.goUp(path: String): File? {
|
||||
if (!isAbsolute) return absoluteFile.goUp(path)
|
||||
if (path.isEmpty()) return this
|
||||
val dirName = path.substringAfterLast('/')
|
||||
val parentPath = path.substringBeforeLast('/', "")
|
||||
return if (dirName.isEmpty() || name == dirName) parentFile.goUp(parentPath) else null
|
||||
}
|
||||
@@ -39,6 +39,7 @@ dependencies {
|
||||
testCompile(gradleApi())
|
||||
|
||||
testRuntime(projectRuntimeJar(":kotlin-android-extensions"))
|
||||
testRuntime(project(":compiler:tests-mutes"))
|
||||
|
||||
// Workaround for missing transitive import of the common(project `kotlin-test-common`
|
||||
// for `kotlin-test-jvm` into the IDE:
|
||||
|
||||
+4
-2
@@ -13,18 +13,20 @@ import org.jetbrains.kotlin.gradle.model.ModelContainer
|
||||
import org.jetbrains.kotlin.gradle.model.ModelFetcherBuildAction
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType
|
||||
import org.jetbrains.kotlin.gradle.util.*
|
||||
import org.jetbrains.kotlin.test.RunnerWithMuteInDatabase
|
||||
import org.jetbrains.kotlin.test.util.trimTrailingWhitespaces
|
||||
import org.junit.After
|
||||
import org.junit.AfterClass
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.runner.RunWith
|
||||
import java.io.File
|
||||
import java.util.regex.Pattern
|
||||
import kotlin.test.*
|
||||
|
||||
import org.jetbrains.kotlin.test.util.trimTrailingWhitespaces
|
||||
|
||||
val SYSTEM_LINE_SEPARATOR: String = System.getProperty("line.separator")
|
||||
|
||||
@RunWith(value = RunnerWithMuteInDatabase::class)
|
||||
abstract class BaseGradleIT {
|
||||
|
||||
protected var workingDir = File(".")
|
||||
|
||||
Reference in New Issue
Block a user