3 # ***** BEGIN LICENSE BLOCK *****
4 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 # The contents of this file are subject to the Mozilla Public License Version
7 # 1.1 (the "License"); you may not use this file except in compliance with
8 # the License. You may obtain a copy of the License at
9 # http://www.mozilla.org/MPL/
11 # Software distributed under the License is distributed on an "AS IS" basis,
12 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 # for the specific language governing rights and limitations under the
16 # The Original Code is JavaScript Core Tests.
18 # The Initial Developer of the Original Code is
19 # Netscape Communications Corporation.
20 # Portions created by the Initial Developer are Copyright (C) 1997-1999
21 # the Initial Developer. All Rights Reserved.
27 # Alternatively, the contents of this file may be used under the terms of
28 # either the GNU General Public License Version 2 or later (the "GPL"), or
29 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 # in which case the provisions of the GPL or the LGPL are applicable instead
31 # of those above. If you wish to allow use of your version of this file only
32 # under the terms of either the GPL or the LGPL, and not to allow others to
33 # use your version of this file under the terms of the MPL, indicate your
34 # decision by deleting the provisions above and replace them with the notice
35 # and other provisions required by the GPL or the LGPL. If you do not delete
36 # the provisions above, a recipient may use your version of this file under
37 # the terms of any one of the MPL, the GPL or the LGPL.
39 # ***** END LICENSE BLOCK *****
41 # Creates the meat of a test suite manager page, requites menuhead.html and menufoot.html
42 # to create the complete page. The test suite manager lets you choose a subset of tests
43 # to run under the runtests2.pl script.
45 local $lxr_url = "http://lxr.mozilla.org/mozilla/source/js/tests/";
46 local $suite_path = $ARGV[0] || "./";
47 local $uid = 0; # radio button unique ID
48 local $html = ""; # html output
49 local $javascript = ""; # script output
52 # automatically exclude spidermonkey-n.tests
53 # XXXbc better to emulate jsDriver.pl's option processing
54 # and allow -L file1 file2 etc.
57 local @excludedlist = expand_user_test_list
('spidermonkey-n.tests');
58 local %excludedhash = {};
59 foreach $excludedtest (@excludedlist)
61 $excludedhash{"./" . $excludedtest} = 1;
66 print (&scriptTag
($javascript) . "\n");
70 local $i, @suite_list;
72 if (!($suite_path =~ /\/$/)) {
73 $suite_path = $suite_path . "/";
76 @suite_list = sort(&get_subdirs
($suite_path));
79 $javascript .= "var suites = {};\n";
80 $javascript .= "function populateSuites()\n";
82 $javascript .= "var currSuite;\n";
83 $javascript .= "var currDirectory;\n";
84 $javascript .= "var currTestDirs;\n";
85 $javascript .= "var currTests;\n";
87 $html .= "<h3>Test Suites:</h3>\n";
88 $html .= "<center>\n";
89 $html .= "<input type='button' value='Select All' " .
90 "onclick='selectAll();'> \n";
91 $html .= "<input type='button' value='Select None' " .
92 "onclick='selectNone();'> \n";
95 $html .= "<table border='1' summary='suite menu'>\n";
96 foreach $suite (@suite_list) {
97 local @readme_text = ("No description available.");
98 if (open (README
, $suite_path . $suite . "/README")) {
99 @readme_text = <README
>;
104 $html .= "<a href='\#SUITE_$suite'>$suite</a>\n";
106 $html .= "<td>@readme_text</td>\n";
108 $html .= "<input type='button' value='Select All' " .
109 "onclick='selectAll(\"$suite\");'> \n";
110 $html .= "<input type='button' value='Select None' " .
111 "onclick='selectNone(\"$suite\");'>\n";
113 $html .= "<td><input readonly name='SUMMARY_$suite'></td>";
116 $html .= "</table>\n";
117 $html .= "<div><input readonly name='TOTAL'></div>\n";
118 $html .= "</center>\n";
121 foreach $i (0 .. $#suite_list) {
122 local $prev_href = ($i > 0) ?
"\#SUITE_" . $suite_list[$i - 1] : "";
123 local $next_href = ($i < $#suite_list) ?
"\#SUITE_" .
124 $suite_list[$i + 1] : "";
125 &process_suite
($suite_path, $suite_list[$i], $prev_href, $next_href);
129 $javascript .= "}\n";
130 $javascript .= "populateSuites();\n";
134 # Append detail from a 'suite' directory (eg: ecma, ecma_2, js1_1, etc.), calling
135 # process_test_dir for subordinate categories.
138 local ($suite_path, $suite, $prev_href, $next_href) = @_;
139 local $i, @test_dir_list;
140 local $suite_count = 0;
143 $javascript .= "currSuite = suites[\"$suite\"] = " .
144 "{testDirs:{}, count:0, selected:0};\n";
145 $javascript .= "currTestDirs = currSuite.testDirs;\n";
147 @test_dir_list = sort(&get_subdirs
($test_home . $suite));
152 $html .= "<a name='SUITE_$suite'></a>$suite " .
153 "(" . ($#test_dir_list + 1) . " Sub-Categories)\n";
154 $html .= "<input type='button' value='Select All' " .
155 "onclick='selectAll(\"$suite\");'>\n";
156 $html .= "<input type='button' value='Select None' " .
157 "onclick='selectNone(\"$suite\");'> \n";
159 $html .= "<a href='\#top_of_page'>Top of page</a> \n";
162 $html .= "<a href='$prev_href'>Previous Suite</a> \n";
166 $html .= "<a href='$next_href'>Next Suite</a> \n";
172 foreach $i (0 .. $#test_dir_list) {
173 local $prev_href = ($i > 0) ?
"\#TESTDIR_" . $suite .
174 $test_dir_list[$i - 1] :
176 local $next_href = ($i < $#test_dir_list) ?
177 "\#TESTDIR_" . $suite . $test_dir_list[$i + 1] : "";
178 &process_test_dir
($suite_path . $suite . "/", $test_dir_list[$i],
180 $prev_href, $next_href);
182 $javascript .= "currSuite.count = $suite_count;\n";
188 # Append detail from a test directory,
189 # calling process_test for subordinate js files
191 sub process_test_dir
{
192 local ($test_dir_path, $test_dir, $suite, $prev_href, $next_href) = @_;
194 @test_list = sort(&get_js_files
($test_dir_path . $test_dir));
196 if ($#test_list >= 0)
198 $suite_count += @test_list;
200 $javascript .= "currDirectory = currTestDirs[\"$test_dir\"] = " .
202 $javascript .= "currTests = currDirectory.tests;\n";
206 $html .= "<a name='TESTDIR_$suite$test_dir'></a>\n";
207 $html .= "$test_dir (" . ($#test_list + 1) . " tests)\n";
208 $html .= "<input type='button' value='Select All' " .
209 "onclick='selectAll(\"$suite\", \"$test_dir\");'>\n";
210 $html .= "<input type='button' value='Select None' " .
211 "onclick='selectNone(\"$suite\", \"$test_dir\");'> ";
212 $html .= "[ <a href='\#SUITE_$suite'>Top of $suite Suite</a> ";
214 $html .= "| <a href='$prev_href'>Previous Category</a> ";
217 $html .= " | <a href='$next_href'>Next Category</a> ";
224 foreach $test (@test_list) {
225 &process_test
($test_dir_path . $test_dir, $test);
234 # Append detail from a single JavaScript file.
237 local ($test_dir_path, $test) = @_;
240 # ignore excluded tests
241 if ($excludedhash{"$test_dir_path/$test"})
249 open (TESTCASE
, $test_dir_path . "/" . $test) ||
250 die ("Error opening " . $test_dir_path . "/" . $test);
253 if (/.*(TITLE|summary)\s+\=\s+[\"\'](.*)[\"\']/i) {
257 if (/.*START\([\"\'](.*)[\"\']\);/)
265 $javascript .= "currTests[\"$test\"] = {id:\"t$uid\"}\n";
267 $html .= " <input type='checkbox' value='$test' name='t$uid' " .
268 "id='$suite:$test_dir:$test' ".
269 "onclick='return onRadioClick(this);'>\n";
270 $html .= "<a href='$lxr_url$suite/$test_dir/$test' target='other_window'>" .
271 "$test</a> $title\n";
278 return ("<script type='text/javascript' language='JavaScript'>@_</script>");
283 # given a directory, return an array of all subdirectories
289 if (!($dir =~ /\/$/)) {
293 opendir (DIR
, $dir) || die ("couldn't open directory $dir: $!");
294 local @testdir_contents = readdir(DIR
);
297 foreach (@testdir_contents) {
298 if ((-d
($dir . $_)) && ($_ ne 'CVS') && ($_ ne '.') && ($_ ne '..')) {
299 @subdirs[$#subdirs + 1] = $_;
307 # given a directory, return an array of all the js files that are in it.
310 local ($test_subdir) = @_;
311 local @js_file_array;
313 opendir ( TEST_SUBDIR
, $test_subdir) || die ("couldn't open directory " .
315 @subdir_files = readdir( TEST_SUBDIR
);
316 closedir( TEST_SUBDIR
);
318 foreach ( @subdir_files ) {
319 # print "excluded $test_subdir/$_\n" if $excludedhash{"$test_subdir/$_"};
320 if ( ($_ =~ /\.js$/) && ($_ ne 'shell.js') && ($_ ne 'browser.js') &&
321 (!$excludedhash{"$test_subdir/$_"}) ) {
322 $js_file_array[$#js_file_array+1] = $_;
326 return @js_file_array;
330 # copied from jsDriver.pl
333 # reads $list_file, storing non-comment lines into an array.
334 # lines in the form suite_dir/[*] or suite_dir/test_dir/[*] are expanded
335 # to include all test files under the specified directory
337 sub expand_user_test_list
{
338 my ($list_file) = @_;
342 # Trim off the leading path separator that begins relative paths on the Mac.
343 # Each path will get concatenated with $opt_suite_path, which ends in one.
347 # We will call expand_test_list_entry(), which does pattern-matching on $list_file.
348 # This will make the pattern-matching the same as it would be on Linux/Windows -
350 if ($os_type eq "MAC") {
351 $list_file =~ s/^$path_sep//;
354 if ($list_file =~ /\.js$/ || -d
$opt_suite_path . $list_file) {
356 push (@retval, &expand_test_list_entry
($list_file));
360 open (TESTLIST
, $list_file) ||
361 die("Error opening test list file '$list_file': $!\n");
366 # It's not a comment, so process it
367 push (@retval, &expand_test_list_entry
($_));
381 # Currently expect all paths to be RELATIVE to the top-level tests directory.
382 # One day, this should be improved to allow absolute paths as well -
384 sub expand_test_list_entry
{
388 if ($entry =~ /\.js$/) {
389 # it's a regular entry, add it to the list
390 if (-f
$opt_suite_path . $entry) {
391 push (@retval, $entry);
393 status
("testcase '$entry' not found.");
395 } elsif ($entry =~ /(.*$path_sep[^\*][^$path_sep]*)$path_sep?\*?$/) {
396 # Entry is in the form suite_dir/test_dir[/*]
397 # so iterate all tests under it
398 my $suite_and_test_dir = $1;
399 my @test_files = &get_js_files
($opt_suite_path .
400 $suite_and_test_dir);
403 foreach $i (0 .. $#test_files) {
404 $test_files[$i] = $suite_and_test_dir . $path_sep .
408 splice (@retval, $#retval + 1, 0, @test_files);
410 } elsif ($entry =~ /([^\*][^$path_sep]*)$path_sep?\*?$/) {
411 # Entry is in the form suite_dir[/*]
412 # so iterate all test dirs and tests under it
414 my @test_dirs = &get_subdirs
($opt_suite_path . $suite);
417 foreach $test_dir (@test_dirs) {
418 my @test_files = &get_js_files
($opt_suite_path . $suite .
419 $path_sep . $test_dir);
422 foreach $i (0 .. $#test_files) {
423 $test_files[$i] = $suite . $path_sep . $test_dir . $path_sep .
427 splice (@retval, $#retval + 1, 0, @test_files);
431 die ("Dont know what to do with list entry '$entry'.\n");
440 print STDERR
("-#- ", @_ , "\n");