r24669: Add CSS to the test run HTML output. See http://samba.org/~jelmer/ for an
[kai/samba.git] / source4 / selftest / output / html.pm
index d18151600203faf470e3fe76227ae4618863bcf0..5a7ee15af207be3c9a55bfaa0adf904bf2b5fb68 100644 (file)
@@ -16,14 +16,27 @@ sub new($$$$) {
                msg => ""
        };
 
+       link("selftest/output/testresults.css", "$dirname/testresults.css");
+
        open(INDEX, ">$dirname/index.html");
 
-       print INDEX "<html>\n";
+       print INDEX "<html lang=\"en\">\n";
+       print INDEX "<head>\n";
+       print INDEX "  <title>Samba Testsuite Run</title>\n";
+       print INDEX "  <link rel=\"stylesheet\" type=\"text/css\" href=\"testresults.css\"/>\n";
+       print INDEX "</head>\n";
        print INDEX "<body>\n";
-       print INDEX "<table>\n";
-       print INDEX "<tr><td>Test</td><td>Environment</td><td>Result</td><td>Duration</td></tr>\n";
-
-       $self->{INDEX} = *INDEX;
+       print INDEX "<table width=\"100%\" border=\"0\" cellspacing=\"0\">\n";
+       print INDEX "  <tr><td class=\"title\">Samba Testsuite Run</td></tr>\n";
+       print INDEX "  <tr><td>\n";
+       print INDEX "  <center>";
+       print INDEX "  <table>\n";
+       print INDEX "  <tr>\n";
+       print INDEX "    <td class=\"tableHead\">Test</td>\n";
+       print INDEX "    <td class=\"tableHead\">Environment</td>\n";
+       print INDEX "    <td class=\"tableHead\">Result</td>\n";
+       print INDEX "    <td class=\"tableHead\">Duration</td>\n";
+       print INDEX "  </tr>\n";
 
        bless($self, $class);
 }
@@ -35,13 +48,22 @@ sub start_testsuite($$)
        my ($self, $state) = @_;
 
        $state->{HTMLFILE} = "$state->{NAME}.html";
+       $state->{HTMLFILE} =~ s/[:\t\n \/]/_/g;
 
-       $state->{HTMLFILE} =~ s/[:\t\n ]/_/g;
+       open(TEST, ">$self->{dirname}/$state->{HTMLFILE}") or die("Unable to open $state->{HTMLFILE} for writing");
 
-       open(TEST, ">$self->{dirname}/$state->{HTMLFILE}");
+       my $title = "Test Results for $state->{NAME}";
 
-       print TEST "<html>\n";
+       print TEST "<html lang=\"en\">\n";
+       print TEST "<head>\n";
+       print TEST "  <title>$title</title>\n";
+       print TEST "  <link rel=\"stylesheet\" type=\"text/css\" href=\"testresults.css\"/>\n";
+       print TEST "</head>\n";
        print TEST "<body>\n";
+       print TEST "<table width=\"100%\" border=\"0\" cellspacing=\"0\">\n";
+       print TEST "  <tr><td class=\"title\">$title</td></tr>\n";
+       print TEST "  <tr><td>\n";
+       print TEST "  <table>\n";
 }
 
 sub output_msg($$$)
@@ -59,20 +81,21 @@ sub end_testsuite($$$$$)
 {
        my ($self, $state, $expected_ret, $ret, $envlog) = @_;
 
+       print TEST "</table>\n";
        print TEST "</body>\n";
        print TEST "</html>\n";
 
        close(TEST);
 
-       print INDEX "<tr><td><a href=\"$state->{HTMLFILE}\">$state->{NAME}</a></td><td>$state->{ENVNAME}</td>";
+       print INDEX "<tr><td class=\"testSuite\"><a href=\"$state->{HTMLFILE}\">$state->{NAME}</a></td><td class=\"environment\">$state->{ENVNAME}</td>";
 
        if ($ret == $expected_ret) {
-               print INDEX "<td bgcolor=\"green\">OK</td>";
+               print INDEX "<td class=\"resultOk\">OK</td>";
        } else {
-               print INDEX "<td bgcolor=\"red\">FAIL</td>";
+               print INDEX "<td class=\"resultFailure\">FAIL</td>";
        }
 
-       print INDEX "<td>" . (time() - $state->{START_TIME}) . "</td>\n";
+       print INDEX "<td class=\"duration\">" . (time() - $state->{START_TIME}) . "</td>\n";
 
        print INDEX "</tr>\n";
 }
@@ -81,8 +104,6 @@ sub start_test($$$)
 {
        my ($self, $state, $testname) = @_;
 
-       print TEST "<h3>$testname</h3>\n";
-
        $self->{active_test} = $testname;
        $self->{msg} = "";
 }
@@ -91,15 +112,21 @@ sub end_test($$$$$)
 {
        my ($self, $state, $testname, $result, $unexpected) = @_;
 
+       print TEST "<tr>";
+
        if ($result eq "skip") {
-               print TEST "<div bgcolor=\"yellow\">\n";
+               print TEST "<td class=\"outputSkipped\">\n";
        } elsif ($unexpected) {
-               print TEST "<div bgcolor=\"red\">\n";
+               print TEST "<td class=\"outputFailure\">\n";
+       } else {
+               print TEST "<td class=\"outputOk\">\n";
        }
 
+       print TEST "<h3>$testname</h3>\n";
+
        print TEST $self->{msg};
 
-       print TEST "</div>\n";
+       print TEST "</td></tr>\n";
 
        $self->{active_test} = undef;
 }
@@ -107,12 +134,13 @@ sub end_test($$$$$)
 sub summary($)
 {
        my ($self) = @_;
-       print INDEX "</table>\n";
-       print INDEX "FAILED ($self->{statistics}->{TESTS_UNEXPECTED_FAIL} failures and $self->{statistics}->{TESTS_ERROR} errors in $self->{statistics}->{SUITES_FAIL} testsuites)\n";
 
+       print INDEX "</table>\n";
+       print INDEX "</center>\n";
+       print INDEX "</td></tr>\n";
+       print INDEX "</table>\n";
        print INDEX "</body>\n";
        print INDEX "</html>\n";
-
        close(INDEX);
 }
 
@@ -127,7 +155,7 @@ sub skip_testsuite($$)
 {
        my ($self, $name) = @_;
 
-       print INDEX "<tr><td>$name</td><td>N/A</td><td bgcolor=\"yellow\">SKIPPED</td><td>N/A</td></tr>\n";
+       print INDEX "<tr><td class=\"testSuite\">$name</td><td class=\"environmentSkipped\">N/A</td><td class=\"resultSkipped\">SKIPPED</td><td class=\"durationSkipped\">N/A</td></tr>\n";
 }
 
 1;