]> git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/mklistpage.pl
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / tests / mozilla / mklistpage.pl
1 #!/usr/bin/perl
2 #
3 # The contents of this file are subject to the Netscape Public
4 # License Version 1.1 (the "License"); you may not use this file
5 # except in compliance with the License. You may obtain a copy of
6 # the License at http://www.mozilla.org/NPL/
7 #
8 # Software distributed under the License is distributed on an "AS
9 # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
10 # implied. See the License for the specific language governing
11 # rights and limitations under the License.
12 #
13 # The Original Code is JavaScript Core Tests.
14 #
15 # The Initial Developer of the Original Code is Netscape
16 # Communications Corporation. Portions created by Netscape are
17 # Copyright (C) 1997-1999 Netscape Communications Corporation. All
18 # Rights Reserved.
19 #
20 # Alternatively, the contents of this file may be used under the
21 # terms of the GNU Public License (the "GPL"), in which case the
22 # provisions of the GPL are applicable instead of those above.
23 # If you wish to allow use of your version of this file only
24 # under the terms of the GPL and not to allow others to use your
25 # version of this file under the NPL, indicate your decision by
26 # deleting the provisions above and replace them with the notice
27 # and other provisions required by the GPL. If you do not delete
28 # the provisions above, a recipient may use your version of this
29 # file under either the NPL or the GPL.
30 #
31 # Contributers:
32 # Robert Ginda
33 #
34 # Creates the meat of a test suite manager page, requites menuhead.html and menufoot.html
35 # to create the complete page. The test suite manager lets you choose a subset of tests
36 # to run under the runtests2.pl script.
37 #
38
39 local $lxr_url = "http://lxr.mozilla.org/mozilla/source/js/tests/";
40 local $suite_path = $ARGV[0] || "./";
41 local $uid = 0; # radio button unique ID
42 local $html = ""; # html output
43 local $javascript = ""; # script output
44
45 &main;
46
47 print (&scriptTag($javascript) . "\n");
48 print ($html);
49
50 sub main {
51 local $i, @suite_list;
52
53 if (!($suite_path =~ /\/$/)) {
54 $suite_path = $suite_path . "/";
55 }
56
57 @suite_list = sort(&get_subdirs ($suite_path));
58
59 $javascript .= "suites = new Object();\n";
60
61 $html .= "<h3>Test Suites:</h3>\n";
62 $html .= "<center>\n";
63 $html .= " <input type='button' value='Select All' " .
64 "onclick='selectAll();'> ";
65 $html .= " <input type='button' value='Select None' " .
66 "onclick='selectNone();'> ";
67
68 # suite menu
69 $html .= "<table border='1'>\n";
70 foreach $suite (@suite_list) {
71 local @readme_text = ("No description available.");
72 if (open (README, $suite_path . $suite . "/README")) {
73 @readme_text = <README>;
74 close (README);
75 }
76 $html .= "<tr><td><a href='\#SUITE_$suite'>$suite</a></td>" .
77 "<td>@readme_text</td>";
78 $html .= "<td><input type='button' value='Select All' " .
79 "onclick='selectAll(\"$suite\");'> ";
80 $html .= "<input type='button' value='Select None' " .
81 "onclick='selectNone(\"$suite\");'></td>";
82 $html .= "<td><input readonly name='SUMMARY_$suite'></td>";
83 $html .= "</tr>";
84 }
85 $html .= "</table>\n";
86 $html .= "<td><input readonly name='TOTAL'></td>";
87 $html .= "</center>";
88 $html .= "<dl>\n";
89
90 foreach $i (0 .. $#suite_list) {
91 local $prev_href = ($i > 0) ? "\#SUITE_" . $suite_list[$i - 1] : "";
92 local $next_href = ($i < $#suite_list) ? "\#SUITE_" . $suite_list[$i + 1] : "";
93 &process_suite ($suite_path, $suite_list[$i], $prev_href, $next_href);
94 }
95
96 $html .= "</dl>\n";
97
98 }
99
100 #
101 # Append detail from a 'suite' directory (eg: ecma, ecma_2, js1_1, etc.), calling
102 # process_test_dir for subordinate categories.
103 #
104 sub process_suite {
105 local ($suite_path, $suite, $prev_href, $next_href) = @_;
106 local $i, @test_dir_list;
107
108 # suite js object
109 $javascript .= "suites[\"$suite\"] = {testDirs: {}};\n";
110
111 @test_dir_list = sort(&get_subdirs ($test_home . $suite));
112
113 # suite header
114 $html .= " <a name='SUITE_$suite'></a><hr><dt><big><big><b>$suite " .
115 "(" . ($#test_dir_list + 1) . " Sub-Categories)</b></big></big><br>\n";
116 $html .= " <input type='button' value='Select All' " .
117 "onclick='selectAll(\"$suite\");'>\n";
118 $html .= " <input type='button' value='Select None' " .
119 "onclick='selectNone(\"$suite\");'> " .
120 "[ <a href='\#top_of_page'>Top of page</a> ";
121 if ($prev_href) {
122 $html .= " | <a href='$prev_href'>Previous Suite</a> ";
123 }
124 if ($next_href) {
125 $html .= " | <a href='$next_href'>Next Suite</a> ";
126 }
127 $html .= "]\n";
128
129 $html .= " <dd>\n <dl>\n";
130
131 foreach $i (0 .. $#test_dir_list) {
132 local $prev_href = ($i > 0) ? "\#TESTDIR_" . $suite . $test_dir_list[$i - 1] :
133 "";
134 local $next_href = ($i < $#test_dir_list) ?
135 "\#TESTDIR_" . $suite . $test_dir_list[$i + 1] : "";
136 &process_test_dir ($suite_path . $suite . "/", $test_dir_list[$i], $suite,
137 $prev_href, $next_href);
138 }
139
140 $html .= " </dl>\n";
141
142 }
143
144 #
145 # Append detail from a test directory, calling process_test for subordinate js files
146 #
147 sub process_test_dir {
148 local ($test_dir_path, $test_dir, $suite, $prev_href, $next_href) = @_;
149
150 @test_list = sort(&get_js_files ($test_dir_path . $test_dir));
151
152 $javascript .= "suites[\"$suite\"].testDirs[\"$test_dir\"] = {tests: {}};\n";
153
154 $html .= " <a name='TESTDIR_$suite$test_dir'></a>\n";
155 $html .= " <dt><big><b>$test_dir (" . ($#test_list + 1) .
156 " tests)</b></big><br>\n";
157 $html .= " <input type='button' value='Select All' " .
158 "onclick='selectAll(\"$suite\", \"$test_dir\");'>\n";
159 $html .= " <input type='button' value='Select None' " .
160 "onclick='selectNone(\"$suite\", \"$test_dir\");'> ";
161 $html .= "[ <a href='\#SUITE_$suite'>Top of $suite Suite</a> ";
162 if ($prev_href) {
163 $html .= "| <a href='$prev_href'>Previous Category</a> ";
164 }
165 if ($next_href) {
166 $html .= " | <a href='$next_href'>Next Category</a> ";
167 }
168 $html .= "]<br>\n";
169 $html .= " </dt>\n";
170
171 $html .= " <dl>\n";
172
173 foreach $test (@test_list) {
174 &process_test ($test_dir_path . $test_dir, $test);
175 }
176
177 $html .= " </dl>\n";
178 }
179
180
181 #
182 # Append detail from a single JavaScript file.
183 #
184 sub process_test {
185 local ($test_dir_path, $test) = @_;
186 local $title = "";
187
188 $uid++;
189
190 open (TESTCASE, $test_dir_path . "/" . $test) ||
191 die ("Error opening " . $test_dir_path . "/" . $test);
192
193 while (<TESTCASE>) {
194 if (/.*TITLE\s+\=\s+\"(.*)\"/) {
195 $title = $1;
196 break;
197 }
198 }
199 close (TESTCASE);
200
201 $javascript .= "suites[\"$suite\"].testDirs[\"$test_dir\"].tests" .
202 "[\"$test\"] = \"radio$uid\"\n";
203 $html .= " <input type='radio' value='$test' name='radio$uid' ".
204 "onclick='return onRadioClick(\"radio$uid\");'>" .
205 "<a href='$lxr_url$suite/$test_dir/$test' target='other_window'>" .
206 "$test</a> $title<br>\n";
207
208 }
209
210 sub scriptTag {
211
212 return ("<script langugage='JavaScript'>@_</script>");
213
214 }
215
216 #
217 # given a directory, return an array of all subdirectories
218 #
219 sub get_subdirs {
220 local ($dir) = @_;
221 local @subdirs;
222
223 if (!($dir =~ /\/$/)) {
224 $dir = $dir . "/";
225 }
226
227 opendir (DIR, $dir) || die ("couldn't open directory $dir: $!");
228 local @testdir_contents = readdir(DIR);
229 closedir(DIR);
230
231 foreach (@testdir_contents) {
232 if ((-d ($dir . $_)) && ($_ ne 'CVS') && ($_ ne '.') && ($_ ne '..')) {
233 @subdirs[$#subdirs + 1] = $_;
234 }
235 }
236
237 return @subdirs;
238 }
239
240 #
241 # given a directory, return an array of all the js files that are in it.
242 #
243 sub get_js_files {
244 local ($test_subdir) = @_;
245 local @js_file_array;
246
247 opendir ( TEST_SUBDIR, $test_subdir) || die ("couldn't open directory " .
248 "$test_subdir: $!");
249 @subdir_files = readdir( TEST_SUBDIR );
250 closedir( TEST_SUBDIR );
251
252 foreach ( @subdir_files ) {
253 if ( $_ =~ /\.js$/ ) {
254 $js_file_array[$#js_file_array+1] = $_;
255 }
256 }
257
258 return @js_file_array;
259 }
260
261