| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
package com.netscape.javascript.qa.drivers; |
| 6 |
|
| 7 |
import java.io.File; |
| 8 |
|
| 9 |
import org.mozilla.javascript.*; |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
public class RhinoDrv extends TestDriver { |
| 63 |
public final String SUFFIX = ".js"; |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
public RhinoDrv( String[] args) { |
| 71 |
super( args ); |
| 72 |
setSuffix(".js"); |
| 73 |
|
| 74 |
} |
| 75 |
public static void main ( String[] args ) { |
| 76 |
RhinoDrv d = new RhinoDrv( args ); |
| 77 |
d.start(); |
| 78 |
} |
| 79 |
public boolean processOptions() { |
| 80 |
int length = ARGS.length; |
| 81 |
if (ARGS[0].startsWith("-")) { |
| 82 |
|
| 83 |
|
| 84 |
for (int i=0; i < ARGS.length; i++ ) { |
| 85 |
if ( ARGS[i].equals("-t")) { |
| 86 |
String __tinderbox = ARGS[++i]; |
| 87 |
|
| 88 |
if ( __tinderbox.equals("true") || __tinderbox.equals("1")){ |
| 89 |
TestDriver.TINDERBOX = true; |
| 90 |
} else { |
| 91 |
TestDriver.TINDERBOX = false; |
| 92 |
} |
| 93 |
} |
| 94 |
|
| 95 |
if ( ARGS[i].equals("-d") ) { |
| 96 |
p( "-d " ); |
| 97 |
|
| 98 |
this.TEST_DIRECTORY = ARGS[i].endsWith(File.separator) |
| 99 |
? new File( ARGS[++i] ) |
| 100 |
: new File( ARGS[++i] + File.separator ); |
| 101 |
p( "-d " +this.TEST_DIRECTORY ); |
| 102 |
|
| 103 |
if ( ! ( this.TEST_DIRECTORY ).isDirectory() ) { |
| 104 |
System.err.println( "error: " + |
| 105 |
this.TEST_DIRECTORY.getAbsolutePath() +" is not a TEST_DIRECTORY." ); |
| 106 |
return false; |
| 107 |
} else { |
| 108 |
continue; |
| 109 |
} |
| 110 |
} |
| 111 |
if ( ARGS[i].equals("-s") ) { |
| 112 |
p( "-s "); |
| 113 |
FILES = new String[20] ; |
| 114 |
for ( int j = ++i, k=0; j < ARGS.length; j++ ) { |
| 115 |
if ( ARGS[j].startsWith("-") ){ |
| 116 |
break; |
| 117 |
} |
| 118 |
FILES[k++] = ARGS[j]; |
| 119 |
} |
| 120 |
} |
| 121 |
if ( ARGS[i].equals("-h") ) { |
| 122 |
p( "-h" ); |
| 123 |
this.HELPER_FUNCTIONS = new File( ARGS[++i] ); |
| 124 |
if ( ! (this.HELPER_FUNCTIONS ).isFile() ) { |
| 125 |
System.err.println( "error: "+ this.HELPER_FUNCTIONS.getAbsolutePath()+ |
| 126 |
" file not found." ); |
| 127 |
return false; |
| 128 |
} |
| 129 |
} |
| 130 |
if ( ARGS[i].equals("-o") ) { |
| 131 |
p( "-o" ); |
| 132 |
OUTPUT_DIRECTORY = new File(ARGS[++i]+File.separator); |
| 133 |
if ( !OUTPUT_DIRECTORY.exists() || !OUTPUT_DIRECTORY.isDirectory() ) { |
| 134 |
System.err.println( "error: "+OUTPUT_DIRECTORY.getAbsolutePath()+ |
| 135 |
" is not a directory."); |
| 136 |
return false; |
| 137 |
} |
| 138 |
} |
| 139 |
|
| 140 |
if ( ARGS[i].equals("-p") ) { |
| 141 |
OPT_LEVEL = Integer.parseInt( ARGS[++i] ); |
| 142 |
} |
| 143 |
|
| 144 |
if ( ARGS[i].equals("-db" )) { |
| 145 |
DEBUG_LEVEL = Integer.parseInt( ARGS[++i] ); |
| 146 |
OPT_LEVEL = 0; |
| 147 |
} |
| 148 |
|
| 149 |
if ( ARGS[i].equals("-e")) { |
| 150 |
EXECUTABLE = ARGS[++i]; |
| 151 |
} |
| 152 |
} |
| 153 |
|
| 154 |
return true; |
| 155 |
|
| 156 |
} else { |
| 157 |
|
| 158 |
switch ( ARGS.length ) { |
| 159 |
case 0: |
| 160 |
System.err.println( "error: specify location of JavaScript "+ |
| 161 |
"tests" ); |
| 162 |
return false; |
| 163 |
case 1: |
| 164 |
System.err.println( "error: specify location of JavaScript "+ |
| 165 |
"HELPER_FUNCTIONS file" ); |
| 166 |
return false; |
| 167 |
case 2: |
| 168 |
this.TEST_DIRECTORY = ARGS[0].endsWith(File.separator) |
| 169 |
? new File( ARGS[0] ) |
| 170 |
: new File( ARGS[0] + File.separator ); |
| 171 |
this.HELPER_FUNCTIONS = new File( ARGS[1] ); |
| 172 |
if ( ! ( this.TEST_DIRECTORY ).isDirectory() ) { |
| 173 |
System.err.println( "error: " + |
| 174 |
this.TEST_DIRECTORY.getAbsolutePath() +" is not a directory." ); |
| 175 |
return false; |
| 176 |
} |
| 177 |
if ( ! (this.HELPER_FUNCTIONS ).isFile() ) { |
| 178 |
System.err.println( "error: "+ this.HELPER_FUNCTIONS.getAbsolutePath()+ |
| 179 |
" file not found." ); |
| 180 |
return false; |
| 181 |
} |
| 182 |
return true; |
| 183 |
default: |
| 184 |
System.err.println( "could not understand arguments." ); |
| 185 |
return false; |
| 186 |
} |
| 187 |
} |
| 188 |
} |
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
public synchronized void executeSuite( TestSuite suite ) { |
| 195 |
RhinoEnv context; |
| 196 |
TestFile file; |
| 197 |
|
| 198 |
for ( int i = 0; i < suite.size(); i++ ) { |
| 199 |
synchronized ( suite ) { |
| 200 |
file = (TestFile) suite.elementAt( i ); |
| 201 |
|
| 202 |
context = new RhinoEnv( file, suite, this ); |
| 203 |
|
| 204 |
context.runTest(); |
| 205 |
|
| 206 |
writeFileResult( file, suite, OUTPUT_DIRECTORY ); |
| 207 |
writeCaseResults(file, suite, OUTPUT_DIRECTORY ); |
| 208 |
context.close(); |
| 209 |
context = null; |
| 210 |
|
| 211 |
if ( ! file.passed ) { |
| 212 |
suite.passed = false; |
| 213 |
} |
| 214 |
} |
| 215 |
} |
| 216 |
writeSuiteResult( suite, OUTPUT_DIRECTORY ); |
| 217 |
writeSuiteSummary( suite, OUTPUT_DIRECTORY ); |
| 218 |
} |
| 219 |
} |