Added test for scan directory feature and updated readme.

This commit is contained in:
Tyler Sommer
2016-04-12 09:23:05 -06:00
parent 89978e2427
commit 0f3a4b7b8f
5 changed files with 110 additions and 37 deletions

View File

@ -64,27 +64,54 @@ public class MoreAsserts {
throw new RuntimeException(msg);
}
public static void main(String[] args) {
SeqTest test = new SeqTest();
Class c = test.getClass();
boolean failed = false;
for (Method method : c.getDeclaredMethods()) {
if (!method.getName().startsWith("test") || !Pattern.matches(args[0], method.getName())) {
continue;
}
private static boolean failed = false;
System.out.print(method.getName());
try {
method.invoke(test);
System.out.println(" PASS");
} catch (Exception ex) {
System.out.println(" FAIL");
ex.printStackTrace();
failed = true;
}
private static String pattern = ".*";
public static void main(String[] args) {
if (args.length > 0) {
pattern = args[0];
}
new TestRunner(new SeqTest()).runTests();
new TestRunner(new ExtraTest()).runTests();
// NOTE: We need to call System.exit to force all go threads to exit.
System.exit(failed ? 1 : 0);
}
private static class TestRunner<T> {
private T test;
public TestRunner(T test) {
this.test = test;
}
public void runTests() {
Class c = test.getClass();
for (Method method : c.getDeclaredMethods()) {
if (!method.getName().startsWith("test") || !Pattern.matches(pattern, method.getName())) {
continue;
}
System.out.print(method.getName());
try {
method.invoke(test);
System.out.println(" PASS");
} catch (Exception ex) {
System.out.println(" FAIL");
ex.printStackTrace();
failed = true;
}
}
}
}
private static class ExtraTest {
public void testCopyFromScanDir() {
Dummy d = new Dummy();
assertEquals("Values must match", 42, d.fortyTwo);
}
}
}