Refactoring: extract mute with file to the separate method

This commit is contained in:
Nikolay Krasko
2019-10-17 13:48:39 +03:00
parent 55acc296a2
commit e4436c80c4
@@ -1055,7 +1055,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 {
runTest0WithCustomIgnoreDirective(test, targetBackend, testDataFile, ignoreDirective); runTest(testWithCustomIgnoreDirective(test, targetBackend, ignoreDirective), 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`.
@@ -1067,16 +1067,42 @@ 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 {
runTest0WithCustomIgnoreDirective(test, targetBackend, testDataFilePath, IGNORE_BACKEND_DIRECTIVE_PREFIX); runTest(testWithCustomIgnoreDirective(test, targetBackend, IGNORE_BACKEND_DIRECTIVE_PREFIX), testDataFilePath);
} }
private static void runTest0WithCustomIgnoreDirective(DoTest test, TargetBackend targetBackend, String testDataFilePath, String ignoreDirective) throws Exception { private static void runTest(DoTest test, String testDataFilePath) throws Exception {
testWithMuteInFile(test, testDataFilePath);
}
private static void testWithMuteInFile(DoTest test, String testDataFilePath) throws Exception {
File testDataFile = new File(testDataFilePath); File testDataFile = new File(testDataFilePath);
if (isMutedWithFile(testDataFile)) { if (isMutedWithFile(testDataFile)) {
return; return;
} }
try {
test.invoke(testDataFilePath);
}
catch (Throwable e) {
if (checkFailFile(e, testDataFile)) {
return;
}
throw e;
}
Assert.assertNull("Test is good but there is a fail file", failFile(testDataFile));
}
private static DoTest testWithCustomIgnoreDirective(DoTest test, TargetBackend targetBackend, String ignoreDirective) throws Exception {
if (targetBackend == TargetBackend.ANY && !AUTOMATICALLY_MUTE_FAILED_TESTS) {
return test;
}
return filePath -> {
File testDataFile = new File(filePath);
boolean isIgnored = isIgnoredTarget(targetBackend, testDataFile, ignoreDirective); boolean isIgnored = isIgnoredTarget(targetBackend, testDataFile, ignoreDirective);
if (DONT_IGNORE_TESTS_WORKING_ON_COMPATIBLE_BACKEND) { if (DONT_IGNORE_TESTS_WORKING_ON_COMPATIBLE_BACKEND) {
@@ -1087,13 +1113,9 @@ public class KotlinTestUtils {
} }
try { try {
test.invoke(testDataFilePath); test.invoke(filePath);
} }
catch (Throwable e) { catch (Throwable e) {
if (checkFailFile(e, testDataFile)) {
return;
}
if (!isIgnored && AUTOMATICALLY_MUTE_FAILED_TESTS) { if (!isIgnored && AUTOMATICALLY_MUTE_FAILED_TESTS) {
String text = doLoadFile(testDataFile); String text = doLoadFile(testDataFile);
String directive = InTextDirectivesUtils.IGNORE_BACKEND_DIRECTIVE_PREFIX + targetBackend.name() + "\n"; String directive = InTextDirectivesUtils.IGNORE_BACKEND_DIRECTIVE_PREFIX + targetBackend.name() + "\n";
@@ -1132,8 +1154,6 @@ public class KotlinTestUtils {
return; return;
} }
Assert.assertNull("Test is good but there is a fail file", failFile(testDataFile));
if (isIgnored) { if (isIgnored) {
if (AUTOMATICALLY_UNMUTE_PASSED_TESTS) { if (AUTOMATICALLY_UNMUTE_PASSED_TESTS) {
String text = doLoadFile(testDataFile); String text = doLoadFile(testDataFile);
@@ -1147,6 +1167,7 @@ public class KotlinTestUtils {
throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive."); throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive.");
} }
};
} }
private static boolean isMutedWithFile(@NotNull File testDataFile) { private static boolean isMutedWithFile(@NotNull File testDataFile) {