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