Ignore files with incompatible target when check that all test are presented
This commit is contained in:
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.test;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import kotlin.text.StringsKt;
|
||||
@@ -26,12 +27,15 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.junit.Assert;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.util.*;
|
||||
|
||||
public final class InTextDirectivesUtils {
|
||||
|
||||
private static final String DIRECTIVES_FILE_NAME = "directives.txt";
|
||||
|
||||
private InTextDirectivesUtils() {
|
||||
}
|
||||
|
||||
@@ -203,4 +207,36 @@ public final class InTextDirectivesUtils {
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static String textWithDirectives(File file) {
|
||||
try {
|
||||
String fileText;
|
||||
if (file.isDirectory()) {
|
||||
File directivesFile = new File(file, DIRECTIVES_FILE_NAME);
|
||||
if (!directivesFile.exists()) return "";
|
||||
|
||||
fileText = FileUtil.loadFile(directivesFile);
|
||||
}
|
||||
else {
|
||||
fileText = FileUtil.loadFile(file);
|
||||
}
|
||||
return fileText;
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isCompatibleTarget(TargetBackend targetBackend, File file) {
|
||||
if (targetBackend == TargetBackend.ANY) return true;
|
||||
|
||||
List<String> backends = findLinesWithPrefixesRemoved(textWithDirectives(file), "// TARGET_BACKEND: ");
|
||||
return backends.isEmpty() || backends.contains(targetBackend.name());
|
||||
}
|
||||
|
||||
public static boolean isIgnoredTarget(TargetBackend targetBackend, File file) {
|
||||
if (targetBackend == TargetBackend.ANY) return false;
|
||||
|
||||
List<String> ignoredBackends = findLinesWithPrefixesRemoved(textWithDirectives(file), "// IGNORE_BACKEND: ");
|
||||
return ignoredBackends.contains(targetBackend.name());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -830,6 +830,7 @@ public class KotlinTestUtils {
|
||||
@NotNull Class<?> testCaseClass,
|
||||
@NotNull File testDataDir,
|
||||
@NotNull Pattern filenamePattern,
|
||||
@NotNull TargetBackend targetBackend,
|
||||
boolean recursive,
|
||||
@NotNull String... excludeDirs
|
||||
) {
|
||||
@@ -846,7 +847,7 @@ public class KotlinTestUtils {
|
||||
assertTestClassPresentByMetadata(testCaseClass, file);
|
||||
}
|
||||
}
|
||||
else if (filenamePattern.matcher(file.getName()).matches()) {
|
||||
else if (filenamePattern.matcher(file.getName()).matches() && InTextDirectivesUtils.isCompatibleTarget(targetBackend, file)) {
|
||||
assertFilePathPresent(file, rootFile, filePaths);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -218,8 +218,8 @@ public class SimpleTestClassModel implements TestClassModel {
|
||||
exclude.append("\"");
|
||||
}
|
||||
String assertTestsPresentStr = String.format(
|
||||
"KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File(\"%s\"), Pattern.compile(\"%s\"), %s%s);",
|
||||
KotlinTestUtils.getFilePath(rootFile), StringUtil.escapeStringCharacters(filenamePattern.pattern()), recursive, exclude
|
||||
"KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File(\"%s\"), Pattern.compile(\"%s\"), %s.%s, %s%s);",
|
||||
KotlinTestUtils.getFilePath(rootFile), StringUtil.escapeStringCharacters(filenamePattern.pattern()), TargetBackend.class.getSimpleName(), targetBackend.toString(), recursive, exclude
|
||||
);
|
||||
p.println(assertTestsPresentStr);
|
||||
}
|
||||
|
||||
+5
-34
@@ -26,13 +26,12 @@ import org.jetbrains.kotlin.test.TargetBackend;
|
||||
import org.jetbrains.kotlin.utils.Printer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.jetbrains.kotlin.test.InTextDirectivesUtils.isIgnoredTarget;
|
||||
|
||||
public class SimpleTestMethodModel implements TestMethodModel {
|
||||
private static final String DIRECTIVES_FILE_NAME = "directives.txt";
|
||||
|
||||
@NotNull
|
||||
private final File rootDir;
|
||||
@@ -75,14 +74,14 @@ public class SimpleTestMethodModel implements TestMethodModel {
|
||||
String filePath = KotlinTestUtils.getFilePath(file) + (file.isDirectory() ? "/" : "");
|
||||
p.println("String fileName = KotlinTestUtils.navigationMetadata(\"", filePath, "\");");
|
||||
|
||||
if (isIgnored()) {
|
||||
if (isIgnoredTarget(targetBackend, file)) {
|
||||
p.println("try {");
|
||||
p.pushIndent();
|
||||
}
|
||||
|
||||
p.println(doTestMethodName, "(fileName);");
|
||||
|
||||
if (isIgnored()) {
|
||||
if (isIgnoredTarget(targetBackend, file)) {
|
||||
p.println("throw new AssertionError(\"Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that.\");");
|
||||
p.popIndent();
|
||||
p.println("}");
|
||||
@@ -98,37 +97,9 @@ public class SimpleTestMethodModel implements TestMethodModel {
|
||||
return KotlinTestUtils.getFilePath(new File(path));
|
||||
}
|
||||
|
||||
private String textWithDirectives() {
|
||||
try {
|
||||
String fileText;
|
||||
if (file.isDirectory()) {
|
||||
File directivesFile = new File(file, DIRECTIVES_FILE_NAME);
|
||||
if (!directivesFile.exists()) return "";
|
||||
|
||||
fileText = FileUtil.loadFile(directivesFile);
|
||||
}
|
||||
else {
|
||||
fileText = FileUtil.loadFile(file);
|
||||
}
|
||||
return fileText;
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldBeGenerated() {
|
||||
if (targetBackend == TargetBackend.ANY) return true;
|
||||
|
||||
List<String> backends = InTextDirectivesUtils.findLinesWithPrefixesRemoved(textWithDirectives(), "// TARGET_BACKEND: ");
|
||||
return backends.isEmpty() || backends.contains(targetBackend.name());
|
||||
}
|
||||
|
||||
private boolean isIgnored() {
|
||||
if (targetBackend == TargetBackend.ANY) return false;
|
||||
|
||||
List<String> ignoredBackends = InTextDirectivesUtils.findLinesWithPrefixesRemoved(textWithDirectives(), "// IGNORE_BACKEND: ");
|
||||
return ignoredBackends.contains(targetBackend.name());
|
||||
return InTextDirectivesUtils.isCompatibleTarget(targetBackend, file);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
Reference in New Issue
Block a user