Fail when ignored test success in generated tests

#KT-14618 Fixed
This commit is contained in:
Zalim Bashorov
2016-11-03 22:58:45 +03:00
parent afe6ec92a4
commit f382f938c7
3 changed files with 8853 additions and 3854 deletions
@@ -75,7 +75,21 @@ public class SimpleTestMethodModel implements TestMethodModel {
public void generateBody(@NotNull Printer p) {
String filePath = KotlinTestUtils.getFilePath(file) + (file.isDirectory() ? "/" : "");
p.println("String fileName = KotlinTestUtils.navigationMetadata(\"", filePath, "\");");
if (isIgnored()) {
p.println("try {");
p.pushIndent();
}
p.println(doTestMethodName, "(fileName);");
if (isIgnored()) {
p.println("throw new AssertionError(\"Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that.\");");
p.popIndent();
p.println("}");
p.println("catch (Throwable ignore) {");
p.println("}");
}
}
@Override
@@ -85,28 +99,38 @@ public class SimpleTestMethodModel implements TestMethodModel {
return KotlinTestUtils.getFilePath(new File(path));
}
private boolean isIgnored() {
if (targetBackend == TargetBackend.ANY) return false;
private String textWithDirectives() {
try {
String fileText;
if (file.isDirectory()) {
File directivesFile = new File(file, DIRECTIVES_FILE_NAME);
if (!directivesFile.exists()) return false;
if (!directivesFile.exists()) return "";
fileText = FileUtil.loadFile(directivesFile);
}
else {
fileText = FileUtil.loadFile(file);
}
List<String> backends = InTextDirectivesUtils.findLinesWithPrefixesRemoved(fileText, "// TARGET_BACKEND: ");
List<String> ignoredBackends = InTextDirectivesUtils.findLinesWithPrefixesRemoved(fileText, "// IGNORE_BACKEND: ");
return (!backends.isEmpty() && !backends.contains(targetBackend.name())) || ignoredBackends.contains(targetBackend.name());
return fileText;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
private 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());
}
@NotNull
@Override
public String getName() {
@@ -125,7 +149,7 @@ public class SimpleTestMethodModel implements TestMethodModel {
String relativePath = FileUtil.getRelativePath(rootDir, file.getParentFile());
unescapedName = relativePath + "-" + StringUtil.capitalize(extractedName);
}
return (isIgnored() ? "ignored" : "test") + StringUtil.capitalize(TestGeneratorUtil.escapeForJavaIdentifier(unescapedName));
return (!shouldBeGenerated() ? "ignored" : "test") + StringUtil.capitalize(TestGeneratorUtil.escapeForJavaIdentifier(unescapedName));
}
@Override
@@ -37,18 +37,6 @@ public class CommonDecompiledTextFromJsMetadataTestGenerated extends AbstractCom
doTest(fileName);
}
@TestMetadata("LocalClassAsTypeWithArgument")
public void ignoredLocalClassAsTypeWithArgument() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/decompiler/decompiledText/LocalClassAsTypeWithArgument/");
doTest(fileName);
}
@TestMetadata("SecondaryConstructors")
public void ignoredSecondaryConstructors() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/decompiler/decompiledText/SecondaryConstructors/");
doTest(fileName);
}
public void testAllFilesPresentInDecompiledText() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/decompiler/decompiledText"), Pattern.compile("^([^\\.]+)$"), true);
}
@@ -125,6 +113,17 @@ public class CommonDecompiledTextFromJsMetadataTestGenerated extends AbstractCom
doTest(fileName);
}
@TestMetadata("LocalClassAsTypeWithArgument")
public void testLocalClassAsTypeWithArgument() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/decompiler/decompiledText/LocalClassAsTypeWithArgument/");
try {
doTest(fileName);
throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that.");
}
catch (Throwable ignore) {
}
}
@TestMetadata("Modifiers")
public void testModifiers() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/decompiler/decompiledText/Modifiers/");
@@ -143,6 +142,17 @@ public class CommonDecompiledTextFromJsMetadataTestGenerated extends AbstractCom
doTest(fileName);
}
@TestMetadata("SecondaryConstructors")
public void testSecondaryConstructors() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/decompiler/decompiledText/SecondaryConstructors/");
try {
doTest(fileName);
throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that.");
}
catch (Throwable ignore) {
}
}
@TestMetadata("SimpleClass")
public void testSimpleClass() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/decompiler/decompiledText/SimpleClass/");
File diff suppressed because it is too large Load Diff