Added a check that all files in the file system are matched by the generated test
This commit is contained in:
+16
-11
@@ -19,13 +19,17 @@ import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/* This class is generated by LazyResolveComparingTestGenerator. DO NOT MODIFY MANUALLY */
|
||||
public class LazyResolveComparingTestGenerated extends AbstractLazyResolveComparingTest {
|
||||
@Test
|
||||
public void allTestsPresentInLazyResolve() throws Exception {
|
||||
allTestsPresent(new File("compiler/testData/lazyResolve"), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenericFunction() throws Exception {
|
||||
doTest("compiler/testData/lazyResolve/genericFunction.kt");
|
||||
@@ -36,24 +40,25 @@ public class LazyResolveComparingTestGenerated extends AbstractLazyResolveCompar
|
||||
doTest("compiler/testData/lazyResolve/simpleClass.kt");
|
||||
}
|
||||
|
||||
public void allTestsPresent(String testDataDir) {
|
||||
public static void allTestsPresent(File testDataDir, boolean recursive) {
|
||||
Set<String> methodNames = new HashSet<String>();
|
||||
for (Method method : LazyResolveComparingTestGenerated.class.getDeclaredMethods()) {
|
||||
if (method.isAnnotationPresent(Test.class)) {
|
||||
methodNames.add(method.getName().toLowerCase() + ".kt");
|
||||
}
|
||||
}
|
||||
File[] testDataFiles = new File("testDataDi").listFiles(new FileFilter() {
|
||||
@Override
|
||||
public boolean accept(File pathname) {
|
||||
return pathname.getName().endsWith(".kt");
|
||||
for (File file : testDataDir.listFiles()) {
|
||||
if (file.isDirectory()) {
|
||||
if (recursive) {
|
||||
allTestsPresent(file, recursive);
|
||||
}
|
||||
}
|
||||
});
|
||||
for (File testDataFile : testDataFiles) {
|
||||
if (!methodNames.contains("test" + testDataFile.getName().toLowerCase())) {
|
||||
Assert.fail("Test data file missing from the generated test class: " + testDataFile + "\nPlease re-run the generator: LazyResolveComparingTestGenerated");
|
||||
else {
|
||||
String name = file.getName();
|
||||
if (name.endsWith(".kt") && !methodNames.contains("test" + name.toLowerCase())) {
|
||||
Assert.fail("Test data file missing from the generated test class: " + file + "\nPlease re-run the generator: LazyResolveComparingTestGenerated");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+47
-24
@@ -68,14 +68,24 @@ public class LazyResolveComparingTestGenerator {
|
||||
|
||||
private void collectFiles(File current, List<File> result, boolean recursive) {
|
||||
for (File file : current.listFiles(filter)) {
|
||||
if (file.isDirectory() && recursive) {
|
||||
collectFiles(file, result, recursive);
|
||||
if (file.isDirectory()) {
|
||||
if (recursive) {
|
||||
collectFiles(file, result, recursive);
|
||||
}
|
||||
}
|
||||
else {
|
||||
result.add(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void getAllTestsPresentCheck(@NotNull Printer p) {
|
||||
p.println("allTestsPresent(new File(\"" + rootFile + "\"), " + recursive + ");");
|
||||
}
|
||||
|
||||
public String getAllTestsPresentMethodName() {
|
||||
return "allTestsPresentIn" + StringUtil.capitalize(rootFile.getName());
|
||||
}
|
||||
}
|
||||
|
||||
private static class TestDataFile {
|
||||
@@ -158,6 +168,16 @@ public class LazyResolveComparingTestGenerator {
|
||||
Collection<TestDataFile> files = Lists.newArrayList();
|
||||
for (TestDataSource testDataSource : testDataSources) {
|
||||
files.addAll(testDataSource.getFiles());
|
||||
|
||||
p.println("@Test");
|
||||
p.println("public void " + testDataSource.getAllTestsPresentMethodName() + "() throws Exception {");
|
||||
p.pushIndent();
|
||||
|
||||
testDataSource.getAllTestsPresentCheck(p);
|
||||
|
||||
p.popIndent();
|
||||
p.println("}");
|
||||
p.println();
|
||||
}
|
||||
|
||||
for (TestDataFile file : files) {
|
||||
@@ -182,29 +202,32 @@ public class LazyResolveComparingTestGenerator {
|
||||
}
|
||||
|
||||
private void generateAllTestsPresent(Printer p) {
|
||||
String methodText =
|
||||
//"@Test\n" +
|
||||
" public void allTestsPresent(String testDataDir) {\n" +
|
||||
" Set<String> methodNames = new HashSet<String>();\n" +
|
||||
" for (Method method : " + testClassName + ".class.getDeclaredMethods()) {\n" +
|
||||
" if (method.isAnnotationPresent(Test.class)) {\n" +
|
||||
" methodNames.add(method.getName().toLowerCase() + \"." + testDataFileExtension + "\");\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" File[] testDataFiles = new File(\"testDataDi\").listFiles(new FileFilter() {\n" +
|
||||
" @Override\n" +
|
||||
" public boolean accept(File pathname) {\n" +
|
||||
" return pathname.getName().endsWith(\"." + testDataFileExtension + "\");\n" +
|
||||
" }\n" +
|
||||
" });\n" +
|
||||
" for (File testDataFile : testDataFiles) {\n" +
|
||||
" if (!methodNames.contains(\"test\" + testDataFile.getName().toLowerCase())) {\n" +
|
||||
" Assert.fail(\"Test data file missing from the generated test class: \" + testDataFile + \"\\nPlease re-run the generator: " + testClassName + "\");\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" }\n";
|
||||
String[] methodText = new String[] {
|
||||
"public static void allTestsPresent(File testDataDir, boolean recursive) {",
|
||||
" Set<String> methodNames = new HashSet<String>();",
|
||||
" for (Method method : " + testClassName + ".class.getDeclaredMethods()) {",
|
||||
" if (method.isAnnotationPresent(Test.class)) {",
|
||||
" methodNames.add(method.getName().toLowerCase() + \"." + testDataFileExtension + "\");",
|
||||
" }",
|
||||
" }",
|
||||
" for (File file : testDataDir.listFiles()) {",
|
||||
" if (file.isDirectory()) {",
|
||||
" if (recursive) {",
|
||||
" allTestsPresent(file, recursive);",
|
||||
" }",
|
||||
" }",
|
||||
" else {",
|
||||
" String name = file.getName();",
|
||||
" if (name.endsWith(\"." + testDataFileExtension + "\") && !methodNames.contains(\"test\" + name.toLowerCase())) {",
|
||||
" Assert.fail(\"Test data file missing from the generated test class: \" + file + \"\\nPlease re-run the generator: " + testClassName + "\");",
|
||||
" }",
|
||||
" }",
|
||||
" }",
|
||||
"}"};
|
||||
|
||||
p.println(methodText);
|
||||
for (String s : methodText) {
|
||||
p.println(s);
|
||||
}
|
||||
}
|
||||
|
||||
private static class Printer {
|
||||
|
||||
Reference in New Issue
Block a user