Allow to auto-mute tests with file
This commit is contained in:
@@ -31,7 +31,9 @@ import junit.framework.TestCase;
|
|||||||
import kotlin.Unit;
|
import kotlin.Unit;
|
||||||
import kotlin.collections.CollectionsKt;
|
import kotlin.collections.CollectionsKt;
|
||||||
import kotlin.collections.SetsKt;
|
import kotlin.collections.SetsKt;
|
||||||
|
import kotlin.io.FilesKt;
|
||||||
import kotlin.jvm.functions.Function1;
|
import kotlin.jvm.functions.Function1;
|
||||||
|
import kotlin.text.Charsets;
|
||||||
import kotlin.text.StringsKt;
|
import kotlin.text.StringsKt;
|
||||||
import org.jetbrains.annotations.NonNls;
|
import org.jetbrains.annotations.NonNls;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@@ -110,6 +112,7 @@ public class KotlinTestUtils {
|
|||||||
|
|
||||||
private static final boolean AUTOMATICALLY_UNMUTE_PASSED_TESTS = false;
|
private static final boolean AUTOMATICALLY_UNMUTE_PASSED_TESTS = false;
|
||||||
private static final boolean AUTOMATICALLY_MUTE_FAILED_TESTS = false;
|
private static final boolean AUTOMATICALLY_MUTE_FAILED_TESTS = false;
|
||||||
|
private static final String AUTOMATICALLY_MUTE_FAILED_TESTS_WITH_CONTENT = null;
|
||||||
|
|
||||||
private static final List<File> filesToDelete = new ArrayList<>();
|
private static final List<File> filesToDelete = new ArrayList<>();
|
||||||
|
|
||||||
@@ -1077,7 +1080,9 @@ public class KotlinTestUtils {
|
|||||||
private static void testWithMuteInFile(DoTest test, String testDataFilePath) throws Exception {
|
private static void testWithMuteInFile(DoTest test, String testDataFilePath) throws Exception {
|
||||||
File testDataFile = new File(testDataFilePath);
|
File testDataFile = new File(testDataFilePath);
|
||||||
|
|
||||||
if (isMutedWithFile(testDataFile)) {
|
boolean isMutedWithFile = isMutedWithFile(testDataFile);
|
||||||
|
if (isMutedWithFile && !RUN_IGNORED_TESTS_AS_REGULAR) {
|
||||||
|
System.err.println("IGNORED TEST: " + testDataFilePath);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1085,8 +1090,16 @@ public class KotlinTestUtils {
|
|||||||
test.invoke(testDataFilePath);
|
test.invoke(testDataFilePath);
|
||||||
}
|
}
|
||||||
catch (Throwable e) {
|
catch (Throwable e) {
|
||||||
if (checkFailFile(e, testDataFile)) {
|
boolean hasFailFile = hasFailFile(testDataFile);
|
||||||
return;
|
if (hasFailFile) {
|
||||||
|
if (checkFailFile(e, testDataFile)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//noinspection ConstantConditions
|
||||||
|
if (!isMutedWithFile && !hasFailFile && AUTOMATICALLY_MUTE_FAILED_TESTS_WITH_CONTENT != null) {
|
||||||
|
createMuteFile(testDataFile, AUTOMATICALLY_MUTE_FAILED_TESTS_WITH_CONTENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw e;
|
throw e;
|
||||||
@@ -1179,6 +1192,13 @@ public class KotlinTestUtils {
|
|||||||
return muteFile.exists() && muteFile.isFile();
|
return muteFile.exists() && muteFile.isFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void createMuteFile(@NotNull File testDataFile, @NotNull String text) throws IOException {
|
||||||
|
if (text.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("Mute text must not be empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
FilesKt.writeText(new File(testDataFile.getPath() + ".mute"), text, Charsets.UTF_8);
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private static File failFile(@NotNull File testDataFile) {
|
private static File failFile(@NotNull File testDataFile) {
|
||||||
@@ -1194,6 +1214,10 @@ public class KotlinTestUtils {
|
|||||||
return failFile;
|
return failFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean hasFailFile(@NotNull File testDataFile) {
|
||||||
|
return failFile(testDataFile) != null;
|
||||||
|
}
|
||||||
|
|
||||||
private static boolean checkFailFile(@NotNull Throwable failure, @NotNull File testDataFile) {
|
private static boolean checkFailFile(@NotNull Throwable failure, @NotNull File testDataFile) {
|
||||||
File failFile = failFile(testDataFile);
|
File failFile = failFile(testDataFile);
|
||||||
if (failFile == null) {
|
if (failFile == null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user