Debian Codegraph @

rhino/testsrc/tests/mklistpage.pl

raw
1 #!/usr/bin/perl
2 #
3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7 # Creates the meat of a test suite manager page, requites menuhead.html and menufoot.html
8 # to create the complete page. The test suite manager lets you choose a subset of tests
9 # to run under the runtests2.pl script.
10
11 local $lxr_url = "http://lxr.mozilla.org/mozilla/source/js/tests/";
12 local $suite_path = $ARGV[0] || "./";
13 local $uid = 0; # radio button unique ID
14 local $html = ""; # html output
15 local $javascript = ""; # script output
16
17 #
18 # automatically exclude spidermonkey-n.tests
19 # XXXbc better to emulate jsDriver.pl's option processing
20 # and allow -L file1 file2 etc.
21 #
22 local $excludedtest;
23 local @excludedlist = expand_user_test_list('spidermonkey-n.tests');
24 local %excludedhash = {};
25 foreach $excludedtest (@excludedlist)
26 {
27 $excludedhash{"./" . $excludedtest} = 1;
28 }
29
30 &main;
31
32 print (&scriptTag($javascript) . "\n");
33 print ($html);
34
35 sub main {
36 local $i, @suite_list;
37
38 if (!($suite_path =~ /\/$/)) {
39 $suite_path = $suite_path . "/";
40 }
41
42 @suite_list = sort(&get_subdirs ($suite_path));
43
44 $javascript .= "\n";
45 $javascript .= "var suites = {};\n";
46 $javascript .= "function populateSuites()\n";
47 $javascript .= "{\n";
48 $javascript .= "var currSuite;\n";
49 $javascript .= "var currDirectory;\n";
50 $javascript .= "var currTestDirs;\n";
51 $javascript .= "var currTests;\n";
52
53 $html .= "<h3>Test Suites:</h3>\n";
54 $html .= "<center>\n";
55 $html .= "<input type='button' value='Select All' " .
56 "onclick='selectAll();'> \n";
57 $html .= "<input type='button' value='Select None' " .
58 "onclick='selectNone();'> \n";
59
60 # suite menu
61 $html .= "<table border='1' summary='suite menu'>\n";
62 foreach $suite (@suite_list) {
63 local @readme_text = ("No description available.");
64 if (open (README, $suite_path . $suite . "/README")) {
65 @readme_text = <README>;
66 close (README);
67 }
68 $html .= "<tr>\n";
69 $html .= "<td>\n";
70 $html .= "<a href='\#SUITE_$suite'>$suite</a>\n";
71 $html .= "</td>\n";
72 $html .= "<td>@readme_text</td>\n";
73 $html .= "<td>\n";
74 $html .= "<input type='button' value='Select All' " .
75 "onclick='selectAll(\"$suite\");'> \n";
76 $html .= "<input type='button' value='Select None' " .
77 "onclick='selectNone(\"$suite\");'>\n";
78 $html .= "</td>\n";
79 $html .= "<td><input readonly name='SUMMARY_$suite'></td>";
80 $html .= "</tr>";
81 }
82 $html .= "</table>\n";
83 $html .= "<div><input readonly name='TOTAL'></div>\n";
84 $html .= "</center>\n";
85
86 $html .= "<dl>\n";
87 foreach $i (0 .. $#suite_list) {
88 local $prev_href = ($i > 0) ? "\#SUITE_" . $suite_list[$i - 1] : "";
89 local $next_href = ($i < $#suite_list) ? "\#SUITE_" .
90 $suite_list[$i + 1] : "";
91 &process_suite ($suite_path, $suite_list[$i], $prev_href, $next_href);
92 }
93 $html .= "</dl>\n";
94
95 $javascript .= "}\n";
96 $javascript .= "populateSuites();\n";
97 }
98
99 #
100 # Append detail from a 'suite' directory (eg: ecma, ecma_2, js1_1, etc.), calling
101 # process_test_dir for subordinate categories.
102 #
103 sub process_suite {
104 local ($suite_path, $suite, $prev_href, $next_href) = @_;
105 local $i, @test_dir_list;
106 local $suite_count = 0;
107
108 # suite js object
109 $javascript .= "currSuite = suites[\"$suite\"] = " .
110 "{testDirs:{}, count:0, selected:0};\n";
111 $javascript .= "currTestDirs = currSuite.testDirs;\n";
112
113 @test_dir_list = sort(&get_subdirs ($test_home . $suite));
114
115 # suite header
116
117 $html .= "<dt>\n";
118 $html .= "<a name='SUITE_$suite'></a>$suite " .
119 "(" . ($#test_dir_list + 1) . " Sub-Categories)\n";
120 $html .= "<input type='button' value='Select All' " .
121 "onclick='selectAll(\"$suite\");'>\n";
122 $html .= "<input type='button' value='Select None' " .
123 "onclick='selectNone(\"$suite\");'> \n";
124 $html .= "[ ";
125 $html .= "<a href='\#top_of_page'>Top of page</a> \n";
126 if ($prev_href) {
127 $html .= " | ";
128 $html .= "<a href='$prev_href'>Previous Suite</a> \n";
129 }
130 if ($next_href) {
131 $html .= " | ";
132 $html .= "<a href='$next_href'>Next Suite</a> \n";
133 }
134 $html .= "]\n";
135 $html .= "</dt>\n";
136 $html .= "<dd>\n";
137
138 foreach $i (0 .. $#test_dir_list) {
139 local $prev_href = ($i > 0) ? "\#TESTDIR_" . $suite .
140 $test_dir_list[$i - 1] :
141 "";
142 local $next_href = ($i < $#test_dir_list) ?
143 "\#TESTDIR_" . $suite . $test_dir_list[$i + 1] : "";
144 &process_test_dir ($suite_path . $suite . "/", $test_dir_list[$i],
145 $suite,
146 $prev_href, $next_href);
147 }
148 $javascript .= "currSuite.count = $suite_count;\n";
149
150 $html .= "</dd>\n";
151 }
152
153 #
154 # Append detail from a test directory,
155 # calling process_test for subordinate js files
156 #
157 sub process_test_dir {
158 local ($test_dir_path, $test_dir, $suite, $prev_href, $next_href) = @_;
159
160 @test_list = sort(&get_js_files ($test_dir_path . $test_dir));
161
162 if ($#test_list >= 0)
163 {
164 $suite_count += @test_list;
165
166 $javascript .= "currDirectory = currTestDirs[\"$test_dir\"] = " .
167 "{tests:{}};\n";
168 $javascript .= "currTests = currDirectory.tests;\n";
169
170 $html .= "<dl>\n";
171 $html .= "<dt>\n";
172 $html .= "<a name='TESTDIR_$suite$test_dir'></a>\n";
173 $html .= "$test_dir (" . ($#test_list + 1) . " tests)\n";
174 $html .= "<input type='button' value='Select All' " .
175 "onclick='selectAll(\"$suite\", \"$test_dir\");'>\n";
176 $html .= "<input type='button' value='Select None' " .
177 "onclick='selectNone(\"$suite\", \"$test_dir\");'> ";
178 $html .= "[ <a href='\#SUITE_$suite'>Top of $suite Suite</a> ";
179 if ($prev_href) {
180 $html .= "| <a href='$prev_href'>Previous Category</a> ";
181 }
182 if ($next_href) {
183 $html .= " | <a href='$next_href'>Next Category</a> ";
184 }
185 $html .= "]\n";
186 $html .= "</dt>\n";
187
188 $html .= "<dd>\n";
189
190 foreach $test (@test_list) {
191 &process_test ($test_dir_path . $test_dir, $test);
192 }
193
194 $html .= "</dl>\n";
195 }
196 }
197
198
199 #
200 # Append detail from a single JavaScript file.
201 #
202 sub process_test {
203 local ($test_dir_path, $test) = @_;
204 local $title = "";
205
206 # ignore excluded tests
207 if ($excludedhash{"$test_dir_path/$test"})
208 {
209 --$suite_count;
210 return;
211 }
212
213 $uid++;
214
215 open (TESTCASE, $test_dir_path . "/" . $test) ||
216 die ("Error opening " . $test_dir_path . "/" . $test);
217
218 while (<TESTCASE>) {
219 if (/.*(TITLE|summary)\s+\=\s+[\"\'](.*)[\"\']/i) {
220 $title = $2;
221 break;
222 }
223 if (/.*START\([\"\'](.*)[\"\']\);/)
224 {
225 $title = $1;
226 break;
227 }
228 }
229 close (TESTCASE);
230
231 $javascript .= "currTests[\"$test\"] = {id:\"t$uid\"}\n";
232 $html .= "<dd>\n";
233 $html .= " <input type='checkbox' value='$test' name='t$uid' " .
234 "id='$suite:$test_dir:$test' ".
235 "onclick='return onRadioClick(this);'>\n";
236 $html .= "<a href='$lxr_url$suite/$test_dir/$test' target='other_window'>" .
237 "$test</a> $title\n";
238 $html .= "</dd>\n";
239
240 }
241
242 sub scriptTag {
243
244 return ("<script type='text/javascript' language='JavaScript'>@_</script>");
245
246 }
247
248 #
249 # given a directory, return an array of all subdirectories
250 #
251 sub get_subdirs {
252 local ($dir) = @_;
253 local @subdirs;
254
255 if (!($dir =~ /\/$/)) {
256 $dir = $dir . "/";
257 }
258
259 opendir (DIR, $dir) || die ("couldn't open directory $dir: $!");
260 local @testdir_contents = readdir(DIR);
261 closedir(DIR);
262
263 foreach (@testdir_contents) {
264 if ((-d ($dir . $_)) && ($_ ne 'CVS') && ($_ ne '.') && ($_ ne '..')) {
265 @subdirs[$#subdirs + 1] = $_;
266 }
267 }
268
269 return @subdirs;
270 }
271
272 #
273 # given a directory, return an array of all the js files that are in it.
274 #
275 sub get_js_files {
276 local ($test_subdir) = @_;
277 local @js_file_array;
278
279 opendir ( TEST_SUBDIR, $test_subdir) || die ("couldn't open directory " .
280 "$test_subdir: $!");
281 @subdir_files = readdir( TEST_SUBDIR );
282 closedir( TEST_SUBDIR );
283
284 foreach ( @subdir_files ) {
285 # print "excluded $test_subdir/$_\n" if $excludedhash{"$test_subdir/$_"};
286 if ( ($_ =~ /\.js$/) && ($_ ne 'shell.js') && ($_ ne 'browser.js') &&
287 (!$excludedhash{"$test_subdir/$_"}) ) {
288 $js_file_array[$#js_file_array+1] = $_;
289 }
290 }
291
292 return @js_file_array;
293 }
294
295
296 # copied from jsDriver.pl
297
298 #
299 # reads $list_file, storing non-comment lines into an array.
300 # lines in the form suite_dir/[*] or suite_dir/test_dir/[*] are expanded
301 # to include all test files under the specified directory
302 #
303 sub expand_user_test_list {
304 my ($list_file) = @_;
305 my @retval = ();
306
307 #
308 # Trim off the leading path separator that begins relative paths on the Mac.
309 # Each path will get concatenated with $opt_suite_path, which ends in one.
310 #
311 # Also note:
312 #
313 # We will call expand_test_list_entry(), which does pattern-matching on $list_file.
314 # This will make the pattern-matching the same as it would be on Linux/Windows -
315 #
316 if ($os_type eq "MAC") {
317 $list_file =~ s/^$path_sep//;
318 }
319
320 if ($list_file =~ /\.js$/ || -d $opt_suite_path . $list_file) {
321
322 push (@retval, &expand_test_list_entry($list_file));
323
324 } else {
325
326 open (TESTLIST, $list_file) ||
327 die("Error opening test list file '$list_file': $!\n");
328
329 while (<TESTLIST>) {
330 s/\r*\n*$//;
331 if (!(/\s*\#/)) {
332 # It's not a comment, so process it
333 push (@retval, &expand_test_list_entry($_));
334 }
335 }
336
337 close (TESTLIST);
338
339 }
340
341 return @retval;
342
343 }
344
345
346 #
347 # Currently expect all paths to be RELATIVE to the top-level tests directory.
348 # One day, this should be improved to allow absolute paths as well -
349 #
350 sub expand_test_list_entry {
351 my ($entry) = @_;
352 my @retval;
353
354 if ($entry =~ /\.js$/) {
355 # it's a regular entry, add it to the list
356 if (-f $opt_suite_path . $entry) {
357 push (@retval, $entry);
358 } else {
359 status ("testcase '$entry' not found.");
360 }
361 } elsif ($entry =~ /(.*$path_sep[^\*][^$path_sep]*)$path_sep?\*?$/) {
362 # Entry is in the form suite_dir/test_dir[/*]
363 # so iterate all tests under it
364 my $suite_and_test_dir = $1;
365 my @test_files = &get_js_files ($opt_suite_path .
366 $suite_and_test_dir);
367 my $i;
368
369 foreach $i (0 .. $#test_files) {
370 $test_files[$i] = $suite_and_test_dir . $path_sep .
371 $test_files[$i];
372 }
373
374 splice (@retval, $#retval + 1, 0, @test_files);
375
376 } elsif ($entry =~ /([^\*][^$path_sep]*)$path_sep?\*?$/) {
377 # Entry is in the form suite_dir[/*]
378 # so iterate all test dirs and tests under it
379 my $suite = $1;
380 my @test_dirs = &get_subdirs ($opt_suite_path . $suite);
381 my $test_dir;
382
383 foreach $test_dir (@test_dirs) {
384 my @test_files = &get_js_files ($opt_suite_path . $suite .
385 $path_sep . $test_dir);
386 my $i;
387
388 foreach $i (0 .. $#test_files) {
389 $test_files[$i] = $suite . $path_sep . $test_dir . $path_sep .
390 $test_files[$i];
391 }
392
393 splice (@retval, $#retval + 1, 0, @test_files);
394 }
395
396 } else {
397 die ("Dont know what to do with list entry '$entry'.\n");
398 }
399
400 return @retval;
401
402 }
403
404 sub status {
405
406 print STDERR ("-#- ", @_ , "\n");
407
408 }
409