Debian Codegraph @

rhino/testsrc/tests/src/com/netscape/javascript/qa/drivers/RefDrv.java

raw symbols SCIP
1 /* -*- Mode: java; tab-width: 8 -*-
2 * Copyright (C) 1997, 1998 Netscape Communications Corporation,
3 * All Rights Reserved.
4 */
5
6 package com.netscape.javascript.qa.drivers;
7
8 import java.util.Vector;
9 import java.util.Date;
10 import java.io.*;
11 import java.applet.Applet;
12
13 /**
14 * TestDriver for running the JavaScript conformance tests against the
15 * JavaScript engine implemenation in C, A.K.A. js/ref, Monkey.
16 *
17 * <p>
18 *
19 * For each test program, RefDrv creates a RefEnv. RefEnv in turn calls the
20 * JavaScript shell executable (jsshell.exe), passing the helper file and the
21 * test file as arguments.
22 *
23 * <p>
24 *
25 * RefEnv reads the output of the jsshell process. You must use the <b><tt>
26 * jsref.js</b></tt> helper file, which formats the printed output of each
27 * test in a way that RefEnv can parse.
28 *
29 * <p> RefEnv expects the following command line options:
30 <pre>
31 -c 1 or 0; whether or not to use code coverage
32 -e Full path to jsshell.exe
33 -d Path to the directory where the tests are installed
34 -h Path to the helper file (jsref.js)
35 -s List of suites to execute (optional)
36 -o Directory in which log files should be written (optional)
37 -t
38 </pre>
39
40 * For example, the following command line will run the tests in
41 * c:\src\ns\js\tests\ecma\Math and c:\src\ns\js\tests\ecma\Number against
42 * the jsshell executable found in c:\src\js\ref
43 *
44 <pre>
45 java -classpath %CLASSPATH% com.netscape.javascript.qa.drivers.RefDrv
46 -d c:\src\ns\js\tests\ecma\ -h c:\src\ns\js\tests\ecma\jsref.js
47 -e c:\src\js\ref\jsshell.exe -s Math Number
48 </pre>
49 * @see com.netscape.javascript.qa.drivers.TestDriver
50 * @see com.netscape.javascript.qa.drivers.RhinoDrv
51 *
52 * @author [email protected]
53 * @author Nick Lerissa
54 *
55 */
56
57 public class RefDrv extends TestDriver {
58 String SUFFIX = ".js";
59 boolean CODE_COVERAGE = false;
60 String HELPER_STRING;
61
62 /**
63 * Create a new RefDrv.
64 *
65 * @param args the arguments passed to the main method.
66 */
67
68 public RefDrv( String[] args) {
69 super( args );
70 setSuffix( ".js");
71 }
72
73 /**
74 * RefDrv expects the following options:
75 <pre>
76 -e full path to the JavaScript executable
77 -d directory in which tests are installed
78 -h path to helper functions file (jsref.js)
79 -o directory in which log files will be written
80 -s list of Suites that should be executed
81 </pre>
82 */
83
84 public static void main ( String[] args ) {
85 RefDrv d = new RefDrv( args );
86 d.start();
87 }
88 /**
89 * Process command line options.
90 *
91 * @see com.netscape.javascript.qa.drivers.RhinoDrv#processOptions
92 */
93
94 public boolean processOptions() {
95 int length = ARGS.length;
96
97 if (ARGS[0].startsWith("-")) {
98 //XXX need to verify that we at least get valid d and -h options
99
100 for (int i=0; i < ARGS.length; i++ ) {
101 if ( ARGS[i].equals("-d") ) {
102 p( "-d " );
103
104 this.TEST_DIRECTORY = ARGS[i].endsWith(File.separator)
105 ? new File( ARGS[++i] )
106 : new File( ARGS[++i] + File.separator );
107 p( "-d " +this.TEST_DIRECTORY );
108
109 if ( ! ( this.TEST_DIRECTORY ).isDirectory() ) {
110 p( "error: " +
111 this.TEST_DIRECTORY.getAbsolutePath() +
112 " is not a TEST_DIRECTORY." );
113 return false;
114 } else {
115 continue;
116 }
117 }
118 if ( ARGS[i].equals("-s") ) {
119 p( "-s ");
120 FILES = new String[20] ;
121 for ( int j = ++i, k=0; j < ARGS.length; j++ ) {
122 if ( ARGS[j].startsWith("-") ){
123 break;
124 }
125 FILES[k++] = ARGS[j];
126 }
127 }
128 if ( ARGS[i].equals("-h") ) {
129 p( "-h" );
130 this.HELPER_STRING = new String( ARGS[++i] );
131 this.HELPER_FUNCTIONS = new File( HELPER_STRING );
132 if ( ! (this.HELPER_FUNCTIONS ).isFile() ) {
133 p( "error: "+
134 this.HELPER_FUNCTIONS.getAbsolutePath()+
135 " file not found." );
136 return false;
137 }
138 p( "-h " +this.HELPER_FUNCTIONS );
139 }
140 if ( ARGS[i].equals("-c")) {
141 p("-c");
142 this.CODE_COVERAGE = new Boolean( ARGS[++i] ).booleanValue();
143 }
144 if ( ARGS[i].equals("-o") ) {
145 p( "-o" );
146 OUTPUT_DIRECTORY = new File(ARGS[++i]+File.separator);
147 if ( !OUTPUT_DIRECTORY.exists() ||
148 !OUTPUT_DIRECTORY.isDirectory() )
149 {
150 p( "error: "+
151 OUTPUT_DIRECTORY.getAbsolutePath()+
152 " is not a directory.");
153 return false;
154 }
155 }
156
157 if ( ARGS[i].equals("-p") ) {
158 this.OPT_LEVEL = Integer.parseInt( ARGS[++i] );
159 }
160
161 if ( ARGS[i].equals("-db" )) {
162 this.DEBUG_LEVEL = Integer.parseInt( ARGS[++i] );
163 this.OPT_LEVEL = 0;
164 }
165
166 if ( ARGS[i].equals("-e")) {
167 this.EXECUTABLE = ARGS[++i];
168 }
169 if ( ARGS[i].equals("-t")) {
170 String __tinderbox = ARGS[++i];
171
172 if ( __tinderbox.equals("true") || __tinderbox.equals("1")){
173 this.TINDERBOX = true;
174 } else {
175 this.TINDERBOX = false;
176 }
177 }
178 }
179
180 return true;
181
182 } else {
183
184 switch ( ARGS.length ) {
185 case 0:
186 p( "error: specify location of JavaScript "+
187 "tests" );
188 return false;
189 case 1:
190 p( "error: specify location of JavaScript "+
191 "HELPER_FUNCTIONS file" );
192 return false;
193 case 2:
194 this.TEST_DIRECTORY = ARGS[0].endsWith(File.separator)
195 ? new File( ARGS[0] )
196 : new File( ARGS[0] + File.separator );
197 this.HELPER_FUNCTIONS = new File( ARGS[1] );
198 if ( ! ( this.TEST_DIRECTORY ).isDirectory() ) {
199 p( "error: " +
200 this.TEST_DIRECTORY.getAbsolutePath() +" is not a directory." );
201 return false;
202 }
203 if ( ! (this.HELPER_FUNCTIONS ).isFile() ) {
204 p( "error: "+
205 this.HELPER_FUNCTIONS.getAbsolutePath()+
206 " file not found." );
207 return false;
208 }
209 return true;
210 default:
211 p( "could not understand arguments." );
212 return false;
213 }
214 }
215 }
216 /**
217 * For each TestFile in each TestSuite, create a new RefEnv, run the
218 * test, parse its results, and close the RefEnv.
219 */
220
221 public synchronized void executeSuite( TestSuite suite ) {
222 TestEnvironment context;
223 TestFile file;
224
225 p("executing suite" );
226 try {
227 for ( int i = 0; i < suite.size(); i++ ) {
228 synchronized ( suite ) {
229 file = (TestFile) suite.elementAt( i );
230
231 if ( getSystemInformation()[0].startsWith( "Mac" )) {
232 context = new MacRefEnv( file, suite, this );
233 ((MacRefEnv) context).runTest();
234 } else {
235 context = new RefEnv( file, suite, this );
236 ((RefEnv) context).runTest();
237 }
238 }
239
240 writeFileResult( file, suite, OUTPUT_DIRECTORY );
241 writeCaseResults(file, suite, OUTPUT_DIRECTORY );
242 context.close();
243 context = null;
244
245 if ( ! file.passed ) {
246 suite.passed = false;
247 }
248 }
249 } catch ( Exception e ) {
250 e.printStackTrace() ;
251 }
252 writeSuiteResult( suite, OUTPUT_DIRECTORY );
253 writeSuiteSummary( suite, OUTPUT_DIRECTORY );
254 }
255 }
256