Fail when ignored test success in generated tests
#KT-14618 Fixed
This commit is contained in:
+32
-8
@@ -75,7 +75,21 @@ public class SimpleTestMethodModel implements TestMethodModel {
|
|||||||
public void generateBody(@NotNull Printer p) {
|
public void generateBody(@NotNull Printer p) {
|
||||||
String filePath = KotlinTestUtils.getFilePath(file) + (file.isDirectory() ? "/" : "");
|
String filePath = KotlinTestUtils.getFilePath(file) + (file.isDirectory() ? "/" : "");
|
||||||
p.println("String fileName = KotlinTestUtils.navigationMetadata(\"", filePath, "\");");
|
p.println("String fileName = KotlinTestUtils.navigationMetadata(\"", filePath, "\");");
|
||||||
|
|
||||||
|
if (isIgnored()) {
|
||||||
|
p.println("try {");
|
||||||
|
p.pushIndent();
|
||||||
|
}
|
||||||
|
|
||||||
p.println(doTestMethodName, "(fileName);");
|
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
|
@Override
|
||||||
@@ -85,28 +99,38 @@ public class SimpleTestMethodModel implements TestMethodModel {
|
|||||||
return KotlinTestUtils.getFilePath(new File(path));
|
return KotlinTestUtils.getFilePath(new File(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isIgnored() {
|
private String textWithDirectives() {
|
||||||
if (targetBackend == TargetBackend.ANY) return false;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String fileText;
|
String fileText;
|
||||||
if (file.isDirectory()) {
|
if (file.isDirectory()) {
|
||||||
File directivesFile = new File(file, DIRECTIVES_FILE_NAME);
|
File directivesFile = new File(file, DIRECTIVES_FILE_NAME);
|
||||||
if (!directivesFile.exists()) return false;
|
if (!directivesFile.exists()) return "";
|
||||||
|
|
||||||
fileText = FileUtil.loadFile(directivesFile);
|
fileText = FileUtil.loadFile(directivesFile);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fileText = FileUtil.loadFile(file);
|
fileText = FileUtil.loadFile(file);
|
||||||
}
|
}
|
||||||
List<String> backends = InTextDirectivesUtils.findLinesWithPrefixesRemoved(fileText, "// TARGET_BACKEND: ");
|
return fileText;
|
||||||
List<String> ignoredBackends = InTextDirectivesUtils.findLinesWithPrefixesRemoved(fileText, "// IGNORE_BACKEND: ");
|
|
||||||
return (!backends.isEmpty() && !backends.contains(targetBackend.name())) || ignoredBackends.contains(targetBackend.name());
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(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
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
@@ -125,7 +149,7 @@ public class SimpleTestMethodModel implements TestMethodModel {
|
|||||||
String relativePath = FileUtil.getRelativePath(rootDir, file.getParentFile());
|
String relativePath = FileUtil.getRelativePath(rootDir, file.getParentFile());
|
||||||
unescapedName = relativePath + "-" + StringUtil.capitalize(extractedName);
|
unescapedName = relativePath + "-" + StringUtil.capitalize(extractedName);
|
||||||
}
|
}
|
||||||
return (isIgnored() ? "ignored" : "test") + StringUtil.capitalize(TestGeneratorUtil.escapeForJavaIdentifier(unescapedName));
|
return (!shouldBeGenerated() ? "ignored" : "test") + StringUtil.capitalize(TestGeneratorUtil.escapeForJavaIdentifier(unescapedName));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+22
-12
@@ -37,18 +37,6 @@ public class CommonDecompiledTextFromJsMetadataTestGenerated extends AbstractCom
|
|||||||
doTest(fileName);
|
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 {
|
public void testAllFilesPresentInDecompiledText() throws Exception {
|
||||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/decompiler/decompiledText"), Pattern.compile("^([^\\.]+)$"), true);
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/decompiler/decompiledText"), Pattern.compile("^([^\\.]+)$"), true);
|
||||||
}
|
}
|
||||||
@@ -125,6 +113,17 @@ public class CommonDecompiledTextFromJsMetadataTestGenerated extends AbstractCom
|
|||||||
doTest(fileName);
|
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")
|
@TestMetadata("Modifiers")
|
||||||
public void testModifiers() throws Exception {
|
public void testModifiers() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/decompiler/decompiledText/Modifiers/");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/decompiler/decompiledText/Modifiers/");
|
||||||
@@ -143,6 +142,17 @@ public class CommonDecompiledTextFromJsMetadataTestGenerated extends AbstractCom
|
|||||||
doTest(fileName);
|
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")
|
@TestMetadata("SimpleClass")
|
||||||
public void testSimpleClass() throws Exception {
|
public void testSimpleClass() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/decompiler/decompiledText/SimpleClass/");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/decompiler/decompiledText/SimpleClass/");
|
||||||
|
|||||||
+8799
-3834
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user