From 5ff55648127c8a8e1b9829775045af986e37647c Mon Sep 17 00:00:00 2001 From: Shevek Date: Fri, 21 Mar 2008 23:05:04 +0000 Subject: move stuff into trunk --- src/tests/AutoTestSuite.java | 121 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 src/tests/AutoTestSuite.java (limited to 'src/tests/AutoTestSuite.java') diff --git a/src/tests/AutoTestSuite.java b/src/tests/AutoTestSuite.java new file mode 100644 index 0000000..894a365 --- /dev/null +++ b/src/tests/AutoTestSuite.java @@ -0,0 +1,121 @@ +import java.lang.reflect.Modifier; + +import java.io.File; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + +import junit.framework.TestSuite; +import junit.framework.TestCase; +import junit.framework.Test; + +public class AutoTestSuite extends TestSuite { + private String testPackage; + private Set testCases; + private boolean testAll; + private File root; + + public AutoTestSuite() { + this.testPackage = System.getProperty("test.package"); + String tcase = System.getProperty("test.case"); + if (tcase != null && tcase.length() > 0) { + this.testCases = new HashSet(Arrays.asList( + tcase.split("[,:]") + )); + } + else { + this.testCases = null; + } + this.testAll = System.getProperty("test.all") != null; + this.root = new File(System.getProperty("test.root")); + + Set tests = new HashSet(); + + findClasses("", root, tests); + + Iterator i = tests.iterator(); + + while(i.hasNext()) { + addTestSuite(i.next()); + } + } + + public void addTestSuite(Class clazz) { + if (testPackage != null) { + String name = clazz.getPackage().getName(); + if (!name.startsWith(testPackage)) { + /* + System.out.println("Skipping test in package '" + + name + "' - does not start with '" + + testPackage + "'"); + */ + return; + } + } + if (testCases != null) { + String name = clazz.getName(); + name = name.substring(name.lastIndexOf('.') + 1); + if (!testCases.contains(name)) { + /* + System.out.println("Skipping test in class '" + + name + "' - does not start with '" + + testCases + "'"); + */ + return; + } + } + /* + if ( + testCases == null && + testPackage == null && + !testAll && + Optional.class.isAssignableFrom(clazz) + ) + { + return; + } + */ + System.out.println("Adding test class '" + clazz + "'"); + super.addTestSuite(clazz); + } + + public static Test suite() { + return new AutoTestSuite(); + } + + private final void findClasses(String pkg, File root, Set result) { + File[] children = root.listFiles(); + for(int i = 0; i 0 || + (modifiers & Modifier.INTERFACE) > 0 || + !TestCase.class.isAssignableFrom(test) || + TestSuite.class.isAssignableFrom(test) + ) + continue; + result.add(test); + } catch (ClassNotFoundException cnfe) { + cnfe.printStackTrace(); + } + } + } + } + } +} -- cgit v1.2.3