Allow to setup additional extension for mute with annotation
This commit is contained in:
@@ -709,7 +709,7 @@ public class KotlinTestUtils {
|
|||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public static void runTest(@NotNull DoTest test, @NotNull TestCase testCase, @TestDataFile String testDataFile) throws Exception {
|
public static void runTest(@NotNull DoTest test, @NotNull TestCase testCase, @TestDataFile String testDataFile) throws Exception {
|
||||||
runTest(test, TargetBackend.ANY, testDataFile);
|
runTestImpl(testWithCustomIgnoreDirective(test, TargetBackend.ANY, IGNORE_BACKEND_DIRECTIVE_PREFIX), testCase, testDataFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
// In this test runner version the `testDataFile` parameter is annotated by `TestDataFile`.
|
// In this test runner version the `testDataFile` parameter is annotated by `TestDataFile`.
|
||||||
@@ -719,7 +719,7 @@ public class KotlinTestUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void runTestWithCustomIgnoreDirective(DoTest test, TargetBackend targetBackend, @TestDataFile String testDataFile, String ignoreDirective) throws Exception {
|
public static void runTestWithCustomIgnoreDirective(DoTest test, TargetBackend targetBackend, @TestDataFile String testDataFile, String ignoreDirective) throws Exception {
|
||||||
runTest(testWithCustomIgnoreDirective(test, targetBackend, ignoreDirective), testDataFile);
|
runTestImpl(testWithCustomIgnoreDirective(test, targetBackend, ignoreDirective), null, testDataFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
// In this test runner version, NONE of the parameters are annotated by `TestDataFile`.
|
// In this test runner version, NONE of the parameters are annotated by `TestDataFile`.
|
||||||
@@ -731,11 +731,14 @@ public class KotlinTestUtils {
|
|||||||
// * sometimes, for too common/general names, it shows many variants to navigate
|
// * sometimes, for too common/general names, it shows many variants to navigate
|
||||||
// * it adds an additional step for navigation -- you must choose an exact file to navigate
|
// * it adds an additional step for navigation -- you must choose an exact file to navigate
|
||||||
public static void runTest0(DoTest test, TargetBackend targetBackend, String testDataFilePath) throws Exception {
|
public static void runTest0(DoTest test, TargetBackend targetBackend, String testDataFilePath) throws Exception {
|
||||||
runTest(testWithCustomIgnoreDirective(test, targetBackend, IGNORE_BACKEND_DIRECTIVE_PREFIX), testDataFilePath);
|
runTestImpl(testWithCustomIgnoreDirective(test, targetBackend, IGNORE_BACKEND_DIRECTIVE_PREFIX), null, testDataFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void runTest(DoTest test, String testDataFilePath) throws Exception {
|
private static void runTestImpl(@NotNull DoTest test, @Nullable TestCase testCase, String testDataFilePath) throws Exception {
|
||||||
MuteWithFileKt.testWithMuteInFile(test).invoke(testDataFilePath);
|
DoTest wrappedTest = testCase != null ?
|
||||||
|
MuteWithFileKt.testWithMuteInFile(test, testCase) :
|
||||||
|
MuteWithFileKt.testWithMuteInFile(test, "");
|
||||||
|
wrappedTest.invoke(testDataFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static DoTest testWithCustomIgnoreDirective(DoTest test, TargetBackend targetBackend, String ignoreDirective) throws Exception {
|
private static DoTest testWithCustomIgnoreDirective(DoTest test, TargetBackend targetBackend, String ignoreDirective) throws Exception {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.test
|
package org.jetbrains.kotlin.test
|
||||||
|
|
||||||
|
import junit.framework.TestCase
|
||||||
import org.jetbrains.kotlin.test.KotlinTestUtils.DoTest
|
import org.jetbrains.kotlin.test.KotlinTestUtils.DoTest
|
||||||
import org.junit.Assert
|
import org.junit.Assert
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@@ -12,30 +13,38 @@ import java.io.File
|
|||||||
private val RUN_MUTED_TESTS = java.lang.Boolean.getBoolean("org.jetbrains.kotlin.run.muted.tests")
|
private val RUN_MUTED_TESTS = java.lang.Boolean.getBoolean("org.jetbrains.kotlin.run.muted.tests")
|
||||||
private val AUTOMATICALLY_MUTE_FAILED_TESTS_WITH_CONTENT: String? = null
|
private val AUTOMATICALLY_MUTE_FAILED_TESTS_WITH_CONTENT: String? = null
|
||||||
|
|
||||||
|
annotation class MuteExtraSuffix(val value: String = "")
|
||||||
|
|
||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
fun testWithMuteInFile(test: DoTest): DoTest {
|
fun testWithMuteInFile(test: DoTest, testCase: TestCase): DoTest {
|
||||||
|
val extraSuffix = testCase.javaClass.getAnnotation(MuteExtraSuffix::class.java)?.value ?: ""
|
||||||
|
return testWithMuteInFile(test, extraSuffix)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Throws(Exception::class)
|
||||||
|
fun testWithMuteInFile(test: DoTest, extraSuffix: String): DoTest {
|
||||||
return object : DoTest {
|
return object : DoTest {
|
||||||
override fun invoke(filePath: String) {
|
override fun invoke(filePath: String) {
|
||||||
val testDataFile = File(filePath)
|
val testDataFile = File(filePath)
|
||||||
|
|
||||||
val isMutedWithFile = isMutedWithFile(testDataFile)
|
val isMutedWithFile = isMutedWithFile(testDataFile, extraSuffix)
|
||||||
if (isMutedWithFile && !RUN_MUTED_TESTS) {
|
if (isMutedWithFile && !RUN_MUTED_TESTS) {
|
||||||
System.err.println("IGNORED TEST: $filePath")
|
System.err.println("IGNORED TEST: $filePath")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val failFile = failFile(testDataFile)
|
val failFile = failFile(testDataFile, extraSuffix)
|
||||||
val hasFailFile = failFile != null
|
val hasFailFile = failFile != null
|
||||||
|
|
||||||
try {
|
try {
|
||||||
test.invoke(filePath)
|
test.invoke(filePath)
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
if (checkFailFile(e, testDataFile)) {
|
if (checkFailFile(e, testDataFile, extraSuffix)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isMutedWithFile && !hasFailFile && AUTOMATICALLY_MUTE_FAILED_TESTS_WITH_CONTENT != null) {
|
if (!isMutedWithFile && !hasFailFile && AUTOMATICALLY_MUTE_FAILED_TESTS_WITH_CONTENT != null) {
|
||||||
createMuteFile(testDataFile, AUTOMATICALLY_MUTE_FAILED_TESTS_WITH_CONTENT)
|
createMuteFile(testDataFile, extraSuffix, AUTOMATICALLY_MUTE_FAILED_TESTS_WITH_CONTENT)
|
||||||
}
|
}
|
||||||
throw e
|
throw e
|
||||||
}
|
}
|
||||||
@@ -45,24 +54,38 @@ fun testWithMuteInFile(test: DoTest): DoTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isMutedWithFile(testDataFile: File): Boolean {
|
private fun isMutedWithFile(testPathFile: File, extraSuffix: String): Boolean {
|
||||||
if (!testDataFile.isFile) {
|
if (!testPathFile.isFile) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
val muteFile = File("${testDataFile.path}.mute")
|
|
||||||
return muteFile.exists() && muteFile.isFile
|
return muteFile(testPathFile, extraSuffix) != null
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createMuteFile(testDataFile: File, text: String) {
|
private fun createMuteFile(testDataFile: File, extraSuffix: String, text: String) {
|
||||||
require(text.isNotEmpty()) { "Mute text must not be empty" }
|
require(text.isNotEmpty()) { "Mute text must not be empty" }
|
||||||
|
|
||||||
File("${testDataFile.path}.mute").writeText(text)
|
muteFileNoCheck(testDataFile, extraSuffix).writeText(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun failFile(testDataFile: File): File? {
|
private fun muteFileNoCheck(testPathFile: File, extraSuffix: String): File {
|
||||||
|
return File("${testPathFile.path}$extraSuffix.mute")
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun muteFile(testPathFile: File, extraSuffix: String): File? {
|
||||||
|
val muteFile = muteFileNoCheck(testPathFile, extraSuffix)
|
||||||
|
|
||||||
|
if (muteFile.exists() && muteFile.isFile) {
|
||||||
|
return muteFile
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun failFile(testDataFile: File, extraSuffix: String): File? {
|
||||||
if (!testDataFile.isFile) return null
|
if (!testDataFile.isFile) return null
|
||||||
|
|
||||||
val failFile = File("${testDataFile.path}.fail")
|
val failFile = File("${testDataFile.path}$extraSuffix.fail")
|
||||||
if (!failFile.exists() || !failFile.isFile) {
|
if (!failFile.exists() || !failFile.isFile) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
@@ -70,8 +93,8 @@ private fun failFile(testDataFile: File): File? {
|
|||||||
return failFile
|
return failFile
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkFailFile(failure: Throwable, testDataFile: File): Boolean {
|
private fun checkFailFile(failure: Throwable, testDataFile: File, extraSuffix: String): Boolean {
|
||||||
val failFile = failFile(testDataFile) ?: return false
|
val failFile = failFile(testDataFile, extraSuffix) ?: return false
|
||||||
val cause = failure.cause
|
val cause = failure.cause
|
||||||
val muteMessage = failure.message +
|
val muteMessage = failure.message +
|
||||||
if (cause != null) {
|
if (cause != null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user