[TEST] Drop mechanism for muting tests with .mute files

This mechanism is deprecated and replaced with muting in database (.csv files)
This commit is contained in:
Dmitriy Novozhilov
2020-12-14 12:27:46 +03:00
parent f8ad096abb
commit 64ce307f7f
10 changed files with 12 additions and 161 deletions
@@ -8,7 +8,6 @@ package org.jetbrains.kotlin.incremental;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
import org.jetbrains.kotlin.test.KotlinTestUtils;
import org.jetbrains.kotlin.test.MuteExtraSuffix;
import org.jetbrains.kotlin.test.TestMetadata;
import org.junit.runner.RunWith;
@@ -21,7 +20,6 @@ import java.util.regex.Pattern;
public class IncrementalJsKlibCompilerRunnerTestGenerated extends AbstractIncrementalJsKlibCompilerRunnerTest {
@TestMetadata("jps-plugin/testData/incremental/pureKotlin")
@TestDataPath("$PROJECT_ROOT")
@MuteExtraSuffix(".jsklib")
@RunWith(JUnit3RunnerWithInners.class)
public static class PureKotlin extends AbstractIncrementalJsKlibCompilerRunnerTest {
private void runTest(String testDataFilePath) throws Exception {
@@ -630,7 +628,6 @@ public class IncrementalJsKlibCompilerRunnerTestGenerated extends AbstractIncrem
@TestMetadata("jps-plugin/testData/incremental/classHierarchyAffected")
@TestDataPath("$PROJECT_ROOT")
@MuteExtraSuffix(".jsklib")
@RunWith(JUnit3RunnerWithInners.class)
public static class ClassHierarchyAffected extends AbstractIncrementalJsKlibCompilerRunnerTest {
private void runTest(String testDataFilePath) throws Exception {
@@ -844,7 +841,6 @@ public class IncrementalJsKlibCompilerRunnerTestGenerated extends AbstractIncrem
@TestMetadata("jps-plugin/testData/incremental/js")
@TestDataPath("$PROJECT_ROOT")
@MuteExtraSuffix(".jsklib")
@RunWith(JUnit3RunnerWithInners.class)
public static class Js extends AbstractIncrementalJsKlibCompilerRunnerTest {
private void runTest(String testDataFilePath) throws Exception {
@@ -862,7 +858,6 @@ public class IncrementalJsKlibCompilerRunnerTestGenerated extends AbstractIncrem
@TestMetadata("jps-plugin/testData/incremental/js/friendsModuleDisabled")
@TestDataPath("$PROJECT_ROOT")
@MuteExtraSuffix(".jsklib")
@RunWith(JUnit3RunnerWithInners.class)
public static class FriendsModuleDisabled extends AbstractIncrementalJsKlibCompilerRunnerTest {
private void runTest(String testDataFilePath) throws Exception {
@@ -880,7 +875,6 @@ public class IncrementalJsKlibCompilerRunnerTestGenerated extends AbstractIncrem
@TestMetadata("jps-plugin/testData/incremental/js/friendsModuleDisabled/internalInlineFunctionIsChanged")
@TestDataPath("$PROJECT_ROOT")
@MuteExtraSuffix(".jsklib")
@RunWith(JUnit3RunnerWithInners.class)
public static class InternalInlineFunctionIsChanged extends AbstractIncrementalJsKlibCompilerRunnerTest {
private void runTest(String testDataFilePath) throws Exception {
@@ -895,7 +889,6 @@ public class IncrementalJsKlibCompilerRunnerTestGenerated extends AbstractIncrem
@TestMetadata("jps-plugin/testData/incremental/js/inlineFunctionLocalDeclarationChanges")
@TestDataPath("$PROJECT_ROOT")
@MuteExtraSuffix(".jsklib")
@RunWith(JUnit3RunnerWithInners.class)
public static class InlineFunctionLocalDeclarationChanges extends AbstractIncrementalJsKlibCompilerRunnerTest {
private void runTest(String testDataFilePath) throws Exception {
@@ -599,7 +599,7 @@ public class KotlinTestUtils {
return;
}
}
MuteWithFileKt.testWithMuteInFile(test, testCase).invoke(testDataFilePath);
test.invoke(testDataFilePath);
}
private static boolean isRunTestOverridden(TestCase testCase) {
@@ -1,129 +0,0 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.test
import junit.framework.TestCase
import org.jetbrains.kotlin.test.KotlinTestUtils.DoTest
import org.junit.Assert
import java.io.File
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_GENERATE_FAIL_FILE_FOR_FAILED_TESTS: Boolean = false
annotation class MuteExtraSuffix(val value: String = "")
@Throws(Exception::class)
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 {
override fun invoke(filePath: String) {
val testDataFile = File(filePath)
val isMutedWithFile = isMutedWithFile(testDataFile, extraSuffix)
if (isMutedWithFile && !RUN_MUTED_TESTS) {
System.err.println("MUTED TEST: $filePath")
return
}
val failFile = failFile(testDataFile, extraSuffix)
val hasFailFile = failFile != null
try {
test.invoke(filePath)
} catch (e: Throwable) {
if (checkFailFile(e, testDataFile, extraSuffix)) {
System.err.println("MUTED TEST (FAIL): $filePath")
return
}
if (!isMutedWithFile && !hasFailFile && AUTOMATICALLY_MUTE_FAILED_TESTS_WITH_CONTENT != null) {
createMuteFile(testDataFile, extraSuffix, AUTOMATICALLY_MUTE_FAILED_TESTS_WITH_CONTENT)
}
throw e
}
Assert.assertNull("Test is good but there is a fail file", failFile)
}
}
}
private fun isMutedWithFile(testPathFile: File, extraSuffix: String): Boolean {
return muteFile(testPathFile, extraSuffix) != null
}
private fun createMuteFile(testDataFile: File, extraSuffix: String, text: String) {
require(text.isNotEmpty()) { "Mute text must not be empty" }
muteFileNoCheck(testDataFile, extraSuffix).writeText(text)
}
private fun rawFileNoChecks(testPathFile: File, extraSuffix: String, suffix: String): File {
return when {
testPathFile.isDirectory ->
File(testPathFile, "${testPathFile.name}$extraSuffix$suffix")
else ->
File("${testPathFile.path}$extraSuffix$suffix")
}
}
private fun muteFileNoCheck(testPathFile: File, extraSuffix: String): File {
return rawFileNoChecks(testPathFile, extraSuffix, ".mute")
}
private fun failFileNoCheck(testPathFile: File, extraSuffix: String): File {
return rawFileNoChecks(testPathFile, extraSuffix, ".fail")
}
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? {
val failFile = failFileNoCheck(testDataFile, extraSuffix)
if (!failFile.exists() || !failFile.isFile) {
return null
}
return failFile
}
private fun failMessage(failure: Throwable): String {
val cause = failure.cause
return failure.message +
if (cause != null) {
"\n" + cause
} else {
""
}
}
private fun checkFailFile(failure: Throwable, testDataFile: File, extraSuffix: String): Boolean {
val failFile = failFile(testDataFile, extraSuffix)
if (failFile == null) {
if (AUTOMATICALLY_GENERATE_FAIL_FILE_FOR_FAILED_TESTS) {
failFileNoCheck(testDataFile, extraSuffix).writeText(failMessage(failure))
}
return false
}
KotlinTestUtils.assertEqualsToFile(failFile, failMessage(failure))
return true
}
@@ -5,7 +5,6 @@
package org.jetbrains.kotlin.generators.model
import org.jetbrains.kotlin.test.MuteExtraSuffix
import org.jetbrains.kotlin.utils.Printer
class AnnotationModel(
@@ -17,6 +16,3 @@ class AnnotationModel(
p.print("@${annotation.simpleName}($argumentsString)")
}
}
fun muteExtraSuffix(suffix: String) = AnnotationModel(MuteExtraSuffix::class.java, arguments = listOf(suffix))
@@ -26,7 +26,6 @@ import org.jetbrains.kotlin.formatter.AbstractFormatterTest
import org.jetbrains.kotlin.formatter.AbstractTypingIndentationTestBase
import org.jetbrains.kotlin.generators.TestGroup
import org.jetbrains.kotlin.generators.generateTestGroupSuite
import org.jetbrains.kotlin.generators.model.muteExtraSuffix
import org.jetbrains.kotlin.generators.util.TestGeneratorUtil.KT_OR_KTS
import org.jetbrains.kotlin.generators.util.TestGeneratorUtil.KT_OR_KTS_WITHOUT_DOTS_IN_NAME
import org.jetbrains.kotlin.generators.util.TestGeneratorUtil.KT_WITHOUT_DOTS_IN_NAME
@@ -384,15 +383,15 @@ fun main(args: Array<String>) {
model("navigation/gotoSymbol", testMethod = "doSymbolTest")
}
testClass<AbstractNavigateToLibrarySourceTest>(annotations = listOf(muteExtraSuffix(".libsrc"))) {
testClass<AbstractNavigateToLibrarySourceTest>() {
model("decompiler/navigation/usercode")
}
testClass<AbstractNavigateJavaToLibrarySourceTest>(annotations = listOf(muteExtraSuffix(".libsrc"))) {
testClass<AbstractNavigateJavaToLibrarySourceTest>() {
model("decompiler/navigation/userJavaCode", pattern = "^(.+)\\.java$")
}
testClass<AbstractNavigateToLibrarySourceTestWithJS>(annotations = listOf(muteExtraSuffix(".libsrcjs"))) {
testClass<AbstractNavigateToLibrarySourceTestWithJS>() {
model("decompiler/navigation/usercode", testClassName = "UsercodeWithJSModule")
}
@@ -1528,7 +1527,7 @@ fun main(args: Array<String>) {
model("incremental/js", extension = null, excludeParentDirs = true)
}
testClass<AbstractIncrementalJsKlibCompilerRunnerTest>(annotations = listOf(muteExtraSuffix(".jsklib"))) {
testClass<AbstractIncrementalJsKlibCompilerRunnerTest>() {
// IC of sealed interfaces are not supported in JS
model("incremental/pureKotlin", extension = null, recursive = false, excludedPattern = "^sealed.*")
model("incremental/classHierarchyAffected", extension = null, recursive = false)
@@ -31,7 +31,6 @@ import org.jetbrains.kotlin.formatter.AbstractFormatterTest
import org.jetbrains.kotlin.formatter.AbstractTypingIndentationTestBase
import org.jetbrains.kotlin.generators.TestGroup
import org.jetbrains.kotlin.generators.generateTestGroupSuite
import org.jetbrains.kotlin.generators.model.muteExtraSuffix
import org.jetbrains.kotlin.generators.util.TestGeneratorUtil.KT_OR_KTS
import org.jetbrains.kotlin.generators.util.TestGeneratorUtil.KT_OR_KTS_WITHOUT_DOTS_IN_NAME
import org.jetbrains.kotlin.generators.util.TestGeneratorUtil.KT_WITHOUT_DOTS_IN_NAME
@@ -306,16 +305,16 @@ fun main(args: Array<String>) {
model("navigation/gotoSymbol", testMethod = "doSymbolTest")
}
testClass<AbstractNavigateToLibrarySourceTest>(annotations = listOf(muteExtraSuffix(".libsrc"))) {
testClass<AbstractNavigateToLibrarySourceTest>() {
model("decompiler/navigation/usercode")
}
testClass<AbstractNavigateJavaToLibrarySourceTest>(annotations = listOf(muteExtraSuffix(".libsrc"))) {
testClass<AbstractNavigateJavaToLibrarySourceTest>() {
model("decompiler/navigation/userJavaCode", pattern = "^(.+)\\.java$")
}
testClass<AbstractNavigateToLibrarySourceTestWithJS>(annotations = listOf(muteExtraSuffix(".libsrcjs"))) {
model("decompiler/navigation/usercode", testClassName ="UsercodeWithJSModule")
testClass<AbstractNavigateToLibrarySourceTestWithJS>() {
model("decompiler/navigation/usercode", testClassName = "UsercodeWithJSModule")
}
testClass<AbstractNavigateToDecompiledLibraryTest> {
@@ -31,7 +31,6 @@ import org.jetbrains.kotlin.formatter.AbstractFormatterTest
import org.jetbrains.kotlin.formatter.AbstractTypingIndentationTestBase
import org.jetbrains.kotlin.generators.TestGroup
import org.jetbrains.kotlin.generators.generateTestGroupSuite
import org.jetbrains.kotlin.generators.model.muteExtraSuffix
import org.jetbrains.kotlin.generators.util.TestGeneratorUtil.KT_OR_KTS
import org.jetbrains.kotlin.generators.util.TestGeneratorUtil.KT_OR_KTS_WITHOUT_DOTS_IN_NAME
import org.jetbrains.kotlin.generators.util.TestGeneratorUtil.KT_WITHOUT_DOTS_IN_NAME
@@ -302,15 +301,15 @@ fun main(args: Array<String>) {
model("navigation/gotoSymbol", testMethod = "doSymbolTest")
}
testClass<AbstractNavigateToLibrarySourceTest>(annotations = listOf(muteExtraSuffix(".libsrc"))) {
testClass<AbstractNavigateToLibrarySourceTest>() {
model("decompiler/navigation/usercode")
}
testClass<AbstractNavigateJavaToLibrarySourceTest>(annotations = listOf(muteExtraSuffix(".libsrc"))) {
testClass<AbstractNavigateJavaToLibrarySourceTest>() {
model("decompiler/navigation/userJavaCode", pattern = "^(.+)\\.java$")
}
testClass<AbstractNavigateToLibrarySourceTestWithJS>(annotations = listOf(muteExtraSuffix(".libsrcjs"))) {
testClass<AbstractNavigateToLibrarySourceTestWithJS>() {
model("decompiler/navigation/usercode", testClassName ="UsercodeWithJSModule")
}
@@ -8,7 +8,6 @@ package org.jetbrains.kotlin.idea.decompiler.navigation;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
import org.jetbrains.kotlin.test.KotlinTestUtils;
import org.jetbrains.kotlin.test.MuteExtraSuffix;
import org.jetbrains.kotlin.test.TestMetadata;
import org.junit.runner.RunWith;
@@ -19,7 +18,6 @@ import java.util.regex.Pattern;
@SuppressWarnings("all")
@TestMetadata("idea/testData/decompiler/navigation/userJavaCode")
@TestDataPath("$PROJECT_ROOT")
@MuteExtraSuffix(".libsrc")
@RunWith(JUnit3RunnerWithInners.class)
public class NavigateJavaToLibrarySourceTestGenerated extends AbstractNavigateJavaToLibrarySourceTest {
private void runTest(String testDataFilePath) throws Exception {
@@ -8,7 +8,6 @@ package org.jetbrains.kotlin.idea.decompiler.navigation;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
import org.jetbrains.kotlin.test.KotlinTestUtils;
import org.jetbrains.kotlin.test.MuteExtraSuffix;
import org.jetbrains.kotlin.test.TestMetadata;
import org.junit.runner.RunWith;
@@ -19,7 +18,6 @@ import java.util.regex.Pattern;
@SuppressWarnings("all")
@TestMetadata("idea/testData/decompiler/navigation/usercode")
@TestDataPath("$PROJECT_ROOT")
@MuteExtraSuffix(".libsrc")
@RunWith(JUnit3RunnerWithInners.class)
public class NavigateToLibrarySourceTestGenerated extends AbstractNavigateToLibrarySourceTest {
private void runTest(String testDataFilePath) throws Exception {
@@ -8,7 +8,6 @@ package org.jetbrains.kotlin.idea.decompiler.navigation;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
import org.jetbrains.kotlin.test.KotlinTestUtils;
import org.jetbrains.kotlin.test.MuteExtraSuffix;
import org.jetbrains.kotlin.test.TestMetadata;
import org.junit.runner.RunWith;
@@ -19,7 +18,6 @@ import java.util.regex.Pattern;
@SuppressWarnings("all")
@TestMetadata("idea/testData/decompiler/navigation/usercode")
@TestDataPath("$PROJECT_ROOT")
@MuteExtraSuffix(".libsrcjs")
@RunWith(JUnit3RunnerWithInners.class)
public class NavigateToLibrarySourceTestWithJSGenerated extends AbstractNavigateToLibrarySourceTestWithJS {
private void runTest(String testDataFilePath) throws Exception {