r24345: Add --format=html option to selftest.
[kai/samba.git] / source4 / selftest / output / html.pm
1 #!/usr/bin/perl
2
3 package output::html;
4 use Exporter;
5 @ISA = qw(Exporter);
6
7 use strict;
8
9 sub new($$$$) {
10         my ($class, $dirname, $statistics) = @_;
11         my $self = { 
12                 dirname => $dirname,
13                 statistics => $statistics,
14                 active_test => undef,
15                 msg => ""
16         };
17
18         open(INDEX, ">$dirname/index.html");
19
20         print INDEX "<html>\n";
21         print INDEX "<body>\n";
22         print INDEX "<table>\n";
23         print INDEX "<tr><td>Test</td><td>Environment</td><td>Result</td><td>Duration</td></tr>\n";
24
25         $self->{INDEX} = *INDEX;
26
27         bless($self, $class);
28 }
29
30 sub output_msg($$$);
31
32 sub start_testsuite($$)
33 {
34         my ($self, $state) = @_;
35
36         $state->{HTMLFILE} = "$state->{NAME}.html";
37
38         $state->{HTMLFILE} =~ s/[:\t\n ]/_/g;
39
40         open(TEST, ">$self->{dirname}/$state->{HTMLFILE}");
41
42         print TEST "<html>\n";
43         print TEST "<body>\n";
44 }
45
46 sub output_msg($$$)
47 {
48         my ($self, $state, $output) = @_;
49
50         unless (defined($self->{active_test})) {
51                 print TEST "$output<br>";
52         } else {
53                 $self->{msg} .= "$output<br>";
54         }
55 }
56
57 sub end_testsuite($$$$$)
58 {
59         my ($self, $state, $expected_ret, $ret, $envlog) = @_;
60
61         print TEST "</body>\n";
62         print TEST "</html>\n";
63
64         close(TEST);
65
66         print {$self->{INDEX}} "<tr><td><a href=\"$state->{HTMLFILE}\">$state->{NAME}</a></td><td>$state->{ENVNAME}</td>";
67
68         if ($ret == $expected_ret) {
69                 print {$self->{INDEX}} "<td bgcolor=\"green\">OK</td>";
70         } else {
71                 print {$self->{INDEX}} "<td bgcolor=\"red\">FAIL</td>";
72         }
73
74         print {$self->{INDEX}} "<td>" . (time() - $state->{START_TIME}) . "</td>\n";
75
76         print {$self->{INDEX}} "</tr>\n";
77 }
78
79 sub start_test($$$)
80 {
81         my ($self, $state, $testname) = @_;
82
83         print TEST "<h3>$testname</h3>\n";
84
85         $self->{active_test} = $testname;
86         $self->{msg} = "";
87 }
88
89 sub end_test($$$$$)
90 {
91         my ($self, $state, $testname, $result, $unexpected) = @_;
92
93         if ($result eq "skip") {
94                 print TEST "<div bgcolor=\"yellow\">\n";
95         } elsif ($unexpected) {
96                 print TEST "<div bgcolor=\"red\">\n";
97         }
98
99         print TEST $self->{msg};
100
101         print TEST "</div>\n";
102
103         $self->{active_test} = undef;
104 }
105
106 sub summary($)
107 {
108         my ($self) = @_;
109         print {$self->{INDEX}} "</table>\n";
110         print {$self->{INDEX}} "FAILED ($self->{statistics}->{TESTS_UNEXPECTED_FAIL} failures and $self->{statistics}->{TESTS_ERROR} errors in $self->{statistics}->{SUITES_FAIL} testsuites)\n";
111
112         print {$self->{INDEX}} "</body>\n";
113         print {$self->{INDEX}} "</html>\n";
114 }
115
116 sub missing_env($$$)
117 {
118         my ($self, $name, $envname) = @_;
119
120         print "FAIL: $name (ENV[$envname] not available!)\n";
121 }
122
123 sub skip_testsuite($$)
124 {
125         my ($self, $name) = @_;
126
127         print {$self->{INDEX}} "<tr><td>$name</td><td>N/A</td><td bgcolor=\"yellow\">SKIPPED</td><td>N/A</td></tr>\n";
128 }
129
130 1;