View Javadoc
1 /* Textui.java */ 2 3 package org.quilt.textui; 4 5 import java.io.File; 6 import java.io.FileInputStream; 7 import java.io.IOException; 8 import java.util.Enumeration; 9 import java.util.Hashtable; 10 import java.util.Properties; 11 import java.util.Vector; 12 13 // XXX remove me 14 import org.apache.tools.ant.BuildException; 15 import org.apache.tools.ant.Project; 16 17 import org.quilt.cl.QuiltClassLoader; 18 import org.quilt.cover.stmt.StmtRegistry; 19 import org.quilt.framework.QuiltTest; 20 import org.quilt.reports.*; 21 import org.quilt.runner.*; 22 23 /*** 24 * Template textui test runner. Need to add main() and runWithIt(). 25 * 26 * @todo Modify to permit types (brief, plain, summary, xml) on the 27 * command line. 28 */ 29 30 public abstract class Textui implements RunnerConst { 31 32 protected QuiltClassLoader quiltLoader = null; 33 34 protected StmtRegistry stmtReg = null; 35 36 // ////////////////////////////////////////////////////////////// 37 // NEEDS WORK 38 // ////////////////////////////////////////////////////////////// 39 40 /*** 41 * Command line usage message. 42 * 43 * XXX This must be fleshed out. 44 */ 45 public void usage () { 46 System.out.println ("usage:\n" 47 + "java [javaOptions] testName [testOptions]\n" 48 + "where the test options (all optional) are\n" 49 + " checkCoverage={true|false}\n" 50 + " checkIncludes={comma-separated list of class names}\n" 51 + " checkExcludes={comma-separated list of class names}\n" 52 + " haltOnError={true|false}\n" 53 + " haltOnFailure={true|false}\n" 54 + " filtertrace={true|false}\n" 55 + " formatter={className[,outputName]}\n" 56 + " propsfile={pathname}\n" 57 + " showOutput={true|false}\n" 58 + "Parameter values are not quoted. Anything in square brackets []\n" 59 + "is optional. Anything in curly braces {} is required.\n" 60 + "\n"); 61 System.exit(ERRORS); 62 } 63 64 // YOU MUST IMPLEMENT A main() LIKE THIS: 65 // public static void main(String[] args) throws IOException { 66 // System.exit( new MockTestRunner().handleArgs(args) ); 67 // } 68 69 /*** 70 * Called by main - pulls arguments off a command line to build a 71 * QuiltTest structure and formatter vector. 72 * 73 * @see QuiltTest 74 * @see RunnerConst 75 * @param args Usual command line argument vector 76 * @return RunnerConst status codes 77 */ 78 protected int handleArgs (String[] args) { 79 int retCode = ERRORS; 80 try { 81 Vector myFormatters = new Vector(); 82 if (args.length == 0) { 83 usage(); 84 } 85 // our goal here is to populate this structure 86 QuiltTest qt = new QuiltTest(args[0]); 87 qt.setFork(true); // always true if textui 88 89 Properties p = new Properties(); 90 for (int i = 1; i < args.length; i++) { 91 if (args[i].startsWith("checkCoverage=")) { 92 qt.setCheckCoverage ( 93 Project.toBoolean(args[i].substring(14))); 94 } else if (args[i].startsWith("checkExcludes=")) { 95 qt.setCheckExcludes (args[i].substring(14)); 96 } else if (args[i].startsWith("checkIncludes=")) { 97 qt.setCheckIncludes (args[i].substring(14)); 98 } else if (args[i].startsWith("haltOnError=")) { 99 qt.setHaltOnError ( 100 Project.toBoolean(args[i].substring(12))); 101 } else if (args[i].startsWith("haltOnFailure=")) { 102 qt.setHaltOnFailure ( 103 Project.toBoolean(args[i].substring(14))); 104 } else if (args[i].startsWith("filtertrace=")) { 105 qt.setFiltertrace ( 106 Project.toBoolean(args[i].substring(12))); 107 } else if (args[i].startsWith("formatter=")) { 108 // looks like: "formatter=CLASSNAME{.OUTFILENAME}" 109 110 // ////////////////////////////////////////////// 111 // MODIFY TO PERMIT TYPES (brief, plain, summary, xml) 112 // AS WELL AS CLASS NAMES 113 // ////////////////////////////////////////////// 114 try { 115 String selector = args[i].substring(10); 116 int commaAt = selector.indexOf(','); 117 FmtSelector fs = new FmtSelector(); 118 if ( commaAt < 0) { 119 fs.setClassname (selector); 120 } else { 121 fs.setClassname (selector.substring(0, commaAt)); 122 fs.setOutfile (new File( 123 selector.substring(commaAt + 1))); 124 } 125 myFormatters.addElement ( fs ); 126 } catch (BuildException be) { 127 System.err.println(be.getMessage()); 128 System.exit(ERRORS); 129 } 130 } else if (args[i].startsWith("propsfile=")) { 131 FileInputStream in = new FileInputStream(args[i] 132 .substring(10)); 133 p.load(in); 134 in.close(); 135 } else if (args[i].startsWith("showoutput=")) { 136 qt.setShowOutput (Project.toBoolean(args[i].substring(11))); 137 } 138 } 139 Hashtable sysP = System.getProperties(); 140 Enumeration e = sysP.keys(); 141 while ( e.hasMoreElements()) { 142 String key = (String)e.nextElement(); 143 p.put(key, (String)sysP.get(key)); 144 } 145 qt.setProperties(p); 146 // set up QuiltClassLoader if appropriate 147 // // DEBUG 148 // StringBuffer sb = new StringBuffer().append("Textui.handleArgs\n"); 149 // String [] inc = qt.getCheckIncludesArray(); 150 // sb.append(" includes\n"); 151 // for (int j = 0; j < inc.length; j++) 152 // sb.append(" ").append(inc[j]).append("\n"); 153 154 // String [] exc = qt.getCheckExcludesArray(); 155 // sb.append(" excludes\n"); 156 // for (int j = 0; j < exc.length; j++) 157 // sb.append(" ").append(exc[j]).append("\n"); 158 // System.out.println(sb.toString()); 159 // // END 160 161 if (qt.getCheckCoverage() && (qt.getCheckIncludes() != null)) { 162 String myClasspath = System.getProperty("java.class.path"); 163 // // DEBUG 164 // System.out.println( 165 // "Textui.handleArgs: setting up QCL with classpath:\n" 166 // + myClasspath); 167 // // END 168 quiltLoader = new QuiltClassLoader ( 169 QuiltClassLoader.cpToURLs(myClasspath), 170 (ClassLoader)null, // classloader we delegate to 171 (String [])null, // delegated classes 172 qt.getCheckIncludesArray(), // needs to be String[] 173 qt.getCheckExcludesArray()); // ditto 174 175 stmtReg = (StmtRegistry) quiltLoader.addQuiltRegistry( 176 "org.quilt.cover.stmt.StmtRegistry"); 177 } 178 // // DEBUG 179 // else { 180 // System.out.println("Textui.handleArgs: NOT USING QCL" 181 // + "\n getCheckCoverage() => " + qt.getCheckCoverage()); 182 // } 183 // // END 184 185 retCode = runWithIt (qt, myFormatters); 186 } catch (Exception e) { 187 System.out.println("EXCEPTION " + e); 188 e.printStackTrace(); 189 retCode = ERRORS; 190 } 191 return retCode; 192 } 193 /*** 194 * Override this method. Runs the individual test. 195 * @param qt Quilt test descriptor 196 * @param myFormatters Vector of formatters 197 */ 198 int runWithIt (QuiltTest qt, Vector myFormatters) { 199 // override this; MockTestRunner should be talkative 200 System.out.println ( 201 "Textui.runWithIt: you should never see this message"); 202 return ERRORS; 203 } 204 }

This page was automatically generated by Maven