local $lxr_url = "http://lxr.mozilla.org/mozilla/source/js/tests/";
local $suite_path = $ARGV[0] || "./";
local $uid = 0; local $html = ""; local $javascript = "";
&main;
print (&scriptTag($javascript) . "\n");
print ($html);
sub main {
local $i, @suite_list;
if (!($suite_path =~ /\/$/)) {
$suite_path = $suite_path . "/";
}
@suite_list = sort(&get_subdirs ($suite_path));
$javascript .= "suites = new Object();\n";
$html .= "<h3>Test Suites:</h3>\n";
$html .= "<center>\n";
$html .= " <input type='button' value='Select All' " .
"onclick='selectAll();'> ";
$html .= " <input type='button' value='Select None' " .
"onclick='selectNone();'> ";
$html .= "<table border='1'>\n";
foreach $suite (@suite_list) {
local @readme_text = ("No description available.");
if (open (README, $suite_path . $suite . "/README")) {
@readme_text = <README>;
close (README);
}
$html .= "<tr><td><a href='\#SUITE_$suite'>$suite</a></td>" .
"<td>@readme_text</td>";
$html .= "<td><input type='button' value='Select All' " .
"onclick='selectAll(\"$suite\");'> ";
$html .= "<input type='button' value='Select None' " .
"onclick='selectNone(\"$suite\");'></td>";
$html .= "<td><input readonly name='SUMMARY_$suite'></td>";
$html .= "</tr>";
}
$html .= "</table>\n";
$html .= "<td><input readonly name='TOTAL'></td>";
$html .= "</center>";
$html .= "<dl>\n";
foreach $i (0 .. $ local $prev_href = ($i > 0) ? "\#SUITE_" . $suite_list[$i - 1] : "";
local $next_href = ($i < $ &process_suite ($suite_path, $suite_list[$i], $prev_href, $next_href);
}
$html .= "</dl>\n";
}
sub process_suite {
local ($suite_path, $suite, $prev_href, $next_href) = @_;
local $i, @test_dir_list;
$javascript .= "suites[\"$suite\"] = {testDirs: {}};\n";
@test_dir_list = sort(&get_subdirs ($test_home . $suite));
$html .= " <a name='SUITE_$suite'></a><hr><dt><big><big><b>$suite " .
"(" . ($ $html .= " <input type='button' value='Select All' " .
"onclick='selectAll(\"$suite\");'>\n";
$html .= " <input type='button' value='Select None' " .
"onclick='selectNone(\"$suite\");'> " .
"[ <a href='\#top_of_page'>Top of page</a> ";
if ($prev_href) {
$html .= " | <a href='$prev_href'>Previous Suite</a> ";
}
if ($next_href) {
$html .= " | <a href='$next_href'>Next Suite</a> ";
}
$html .= "]\n";
$html .= " <dd>\n <dl>\n";
foreach $i (0 .. $ local $prev_href = ($i > 0) ? "\#TESTDIR_" . $suite . $test_dir_list[$i - 1] :
"";
local $next_href = ($i < $ "\#TESTDIR_" . $suite . $test_dir_list[$i + 1] : "";
&process_test_dir ($suite_path . $suite . "/", $test_dir_list[$i], $suite,
$prev_href, $next_href);
}
$html .= " </dl>\n";
}
sub process_test_dir {
local ($test_dir_path, $test_dir, $suite, $prev_href, $next_href) = @_;
@test_list = sort(&get_js_files ($test_dir_path . $test_dir));
$javascript .= "suites[\"$suite\"].testDirs[\"$test_dir\"] = {tests: {}};\n";
$html .= " <a name='TESTDIR_$suite$test_dir'></a>\n";
$html .= " <dt><big><b>$test_dir (" . ($ " tests)</b></big><br>\n";
$html .= " <input type='button' value='Select All' " .
"onclick='selectAll(\"$suite\", \"$test_dir\");'>\n";
$html .= " <input type='button' value='Select None' " .
"onclick='selectNone(\"$suite\", \"$test_dir\");'> ";
$html .= "[ <a href='\#SUITE_$suite'>Top of $suite Suite</a> ";
if ($prev_href) {
$html .= "| <a href='$prev_href'>Previous Category</a> ";
}
if ($next_href) {
$html .= " | <a href='$next_href'>Next Category</a> ";
}
$html .= "]<br>\n";
$html .= " </dt>\n";
$html .= " <dl>\n";
foreach $test (@test_list) {
&process_test ($test_dir_path . $test_dir, $test);
}
$html .= " </dl>\n";
}
sub process_test {
local ($test_dir_path, $test) = @_;
local $title = "";
$uid++;
open (TESTCASE, $test_dir_path . "/" . $test) ||
die ("Error opening " . $test_dir_path . "/" . $test);
while (<TESTCASE>) {
if (/.*TITLE\s+\=\s+\"(.*)\"/) {
$title = $1;
break;
}
}
close (TESTCASE);
$javascript .= "suites[\"$suite\"].testDirs[\"$test_dir\"].tests" .
"[\"$test\"] = \"radio$uid\"\n";
$html .= " <input type='radio' value='$test' name='radio$uid' ".
"onclick='return onRadioClick(\"radio$uid\");'>" .
"<a href='$lxr_url$suite/$test_dir/$test' target='other_window'>" .
"$test</a> $title<br>\n";
}
sub scriptTag {
return ("<script langugage='JavaScript'>@_</script>");
}
sub get_subdirs {
local ($dir) = @_;
local @subdirs;
if (!($dir =~ /\/$/)) {
$dir = $dir . "/";
}
opendir (DIR, $dir) || die ("couldn't open directory $dir: $!");
local @testdir_contents = readdir(DIR);
closedir(DIR);
foreach (@testdir_contents) {
if ((-d ($dir . $_)) && ($_ ne 'CVS') && ($_ ne '.') && ($_ ne '..')) {
@subdirs[$ }
}
return @subdirs;
}
sub get_js_files {
local ($test_subdir) = @_;
local @js_file_array;
opendir ( TEST_SUBDIR, $test_subdir) || die ("couldn't open directory " .
"$test_subdir: $!");
@subdir_files = readdir( TEST_SUBDIR );
closedir( TEST_SUBDIR );
foreach ( @subdir_files ) {
if ( $_ =~ /\.js$/ ) {
$js_file_array[$ }
}
return @js_file_array;
}