Debian Codegraph @

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

raw symbols SCIP
1 /* Copyright (C) 1997, 1998 Netscape Communications Corporation,
2 * All Rights Reserved.
3 */
4
5 package com.netscape.javascript.qa.drivers;
6
7 import java.io.File;
8
9 import org.mozilla.javascript.*;
10
11 /**
12 RhinoDrv is an application for executing JavaScript tests against the
13 JavaScript engine implemented in Java.
14
15 <p>
16
17 The application requires two arguments:
18 <ul >
19 <li > the full path to the JavaScript test suite directory
20 <li > the full path to a file of shared JavaScript functions that
21 should be evaluated by the JavaScript Context before each
22 JavaScript test is evaluated. See the file <b>shell.js</b>
23 included in the test suite.
24 </ul>
25
26 For example:
27 <pre>
28
29 java -classpath /tmp/Rhino/:/tmp/tests COM.netscape.javascript.qa.RhinoDrv
30 /tmp/tests/ecma/ /tmp/tests/ecma/shell.js
31
32 </pre>
33
34 <p>
35
36 Alternatively, you can specify one or many of the suites by using the
37 following command-line options:
38
39 <pre >
40 -d Directory in which suites are located
41 -s Names of suites to execute
42 -h Name of helper file
43 -p Optimization level
44 -o Output directory
45 -db Debug level
46 -t Whether or not we're using tinderbox
47
48 </pre>
49
50 For example:
51 <pre>
52
53 java -classpath $CLASSPATH com.netscape.javascript.qa.drivers.RhinoDrv -d c:\src\ns\js\tests\ecma\ -s Math Number Function -h shell.js -p 2 -db 0
54
55 </pre>
56
57 @see TestDriver
58 @author [email protected]
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 //XXX need to verify that we at least get valid d and -h options
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 * For each file in each suite, create a new RhinoEnv.
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 }