1 23 24 package org.enhydra.xml.driver; 25 26 import java.io.PrintWriter ; 27 import java.lang.reflect.Method ; 28 import java.util.Enumeration ; 29 import java.util.HashSet ; 30 31 import junit.framework.TestSuite; 32 33 50 public class RunTests implements TestCaseBase.TestSelector { 51 52 private static boolean DEBUG = false; 53 54 55 private Class [] FACTORY_SIG = { 56 Class .class, TestCaseBase.TestSelector.class 57 }; 58 59 60 private HashSet fStepRestrictions; 61 62 63 private PrintWriter fOut = new PrintWriter (System.err, true); 64 65 69 public boolean select(Method method) { 70 if (fStepRestrictions == null) { 71 return true; 72 } else { 73 return fStepRestrictions.contains(method.getName()); 74 } 75 } 76 77 80 private TestSuite createTestSuite(String className) { 81 try { 85 Class testClass = getClass().getClassLoader().loadClass(className); 86 Method createSuite = testClass.getMethod("createSuite", 87 FACTORY_SIG); 88 Object [] args = new Object []{testClass, this}; 89 return (TestSuite)createSuite.invoke(null, args); 90 } catch (Exception except) { 91 throw new TestException(except); 92 } 93 } 94 95 96 private void runTest(TestCaseBase test) { 97 fOut.println("RUN: " + test); 98 if (DEBUG) { 99 test.dumpInfo(fOut); 100 } 101 boolean succeed = false; 102 try { 103 test.runTest(); 104 succeed = true; 105 } catch (Throwable except) { 106 fOut.println("FAILED: " + test + ": " + except); 107 if (!(except instanceof DiffException)) { 108 except.printStackTrace(); 109 } 110 } 111 if (succeed) { 112 fOut.println("SUCCEED: " + test); 113 } 114 } 115 116 117 private void runTestSuite(TestSuite suite) { 118 Enumeration tests = suite.tests(); 119 while (tests.hasMoreElements()) { 120 runTest((TestCaseBase)tests.nextElement()); 121 } 122 } 123 124 127 private void run(String [] args) { 128 int argi = 0; 129 while ((argi < args.length) && args[argi].startsWith("-")) { 130 if (args[argi].equals("-test-root")) { 131 TestProperties.setTestRoot(args[++argi]); 132 } else if (args[argi].equals("-dom")) { 133 TestProperties.setDom(args[++argi]); 134 } else if (args[argi].equals("-parser")) { 135 TestProperties.setParser(args[++argi]); 136 } else if (args[argi].equals("-reloading")) { 137 TestProperties.setReloading(true); 138 } else if (args[argi].equals("-no-reloading")) { 139 TestProperties.setReloading(false); 140 } else if (args[argi].equals("-update")) { 141 TestProperties.setUpdate(true); 142 } else if (args[argi].equals("-test")) { 143 if (fStepRestrictions == null) { 144 fStepRestrictions = new HashSet (); 145 } 146 fStepRestrictions.add(args[++argi]); 147 } else { 148 fOut.println("invalid opt: " + args[argi]); 149 } 150 argi++; 151 } 152 TestProperties.setVerbose(true); 153 154 for (; argi < args.length; argi++) { 155 runTestSuite(createTestSuite(args[argi])); 156 } 157 } 158 159 160 public static void main(String [] args) { 161 new RunTests().run(args); 162 } 163 } 164 165 | Popular Tags |