Fri, 16 Jan 2015 18:13:44 +0100
Integrate suggestion from review to improve consistency with existing code.
1 #!/usr/bin/perl
3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 print <<EOD
8 <html>
9 <head>
10 <title>reftest output</title>
11 <style type="text/css">
12 /* must be in this order */
13 .PASS { background-color: green; }
14 .FAIL { background-color: red; }
15 .XFAIL { background-color: #999300; }
16 .WEIRDPASS { background-color: #00FFED; }
17 .PASSRANDOM { background-color: #598930; }
18 .FAILRANDOM, td.XFAILRANDOM { background-color: #99402A; }
20 .FAILIMAGES { }
21 img { margin: 5px; width: 80px; height: 100px; }
22 img.testresult { border: 2px solid red; }
23 img.testref { border: 2px solid green; }
24 a { color: inherit; }
25 .always { display: inline ! important; }
26 </style>
27 </head>
28 <body>
29 <p>
30 <span class="PASS always"><input type="checkbox" checked="true" onclick="var s = document.styleSheets[0].cssRules[0].style; if (s.display == 'none') s.display = null; else s.display = 'none';">PASS</span>
31 <span class="FAIL always"><input type="checkbox" checked="true" onclick="var s = document.styleSheets[0].cssRules[1].style; if (s.display == 'none') s.display = null; else s.display = 'none';">UNEXPECTED FAIL</span>
32 <span class="XFAIL always"><input type="checkbox" checked="true" onclick="var s = document.styleSheets[0].cssRules[2].style; if (s.display == 'none') s.display = null; else s.display = 'none';">KNOWN FAIL</span>
33 <span class="WEIRDPASS always"><input type="checkbox" checked="true" onclick="var s = document.styleSheets[0].cssRules[3].style; if (s.display == 'none') s.display = null; else s.display = 'none';">UNEXPECTED PASS</span>
34 <span class="PASSRANDOM always"><input type="checkbox" checked="true" onclick="var s = document.styleSheets[0].cssRules[4].style; if (s.display == 'none') s.display = null; else s.display = 'none';">PASS (Random)</span>
35 <span class="FAILRANDOM always"><input type="checkbox" checked="true" onclick="var s = document.styleSheets[0].cssRules[5].style; if (s.display == 'none') s.display = null; else s.display = 'none';">FAIL (Random)</span>
36 </p>
37 <table>
38 EOD
39 ;
41 sub readcleanline {
42 my $l = <>;
43 chomp $l;
44 chop $l if ($l =~ /\r$/);
45 return $l;
46 }
48 sub do_html {
49 my ($l) = @_;
51 $l =~ s,(file:[^ ]*),<a href="\1">\1</a>,g;
52 $l =~ s,(data:[^ ]*),<a href="\1">\1</a>,g;
54 return $l;
55 }
57 $l = 0;
59 while (<>) {
60 $l++;
61 next unless /^REFTEST/;
63 chomp;
64 chop if /\r$/;
66 s/^REFTEST *//;
68 my $randomresult = 0;
69 if (/EXPECTED RANDOM/) {
70 s/\(EXPECTED RANDOM\)//;
71 $randomresult = 1;
72 }
74 if (/^TEST-PASS \| (.*)$/) {
75 my $class = $randomresult ? "PASSRANDOM" : "PASS";
76 print '<tr><td class="' . $class . '">' . do_html($1) . "</td></tr>\n";
77 } elsif (/^TEST-UNEXPECTED-(....) \| (.*)$/) {
78 if ($randomresult) {
79 die "Error on line $l: UNEXPECTED with test marked random?!";
80 }
81 my $class = ($1 eq "PASS") ? "WEIRDPASS" : "FAIL";
82 print '<tr><td class="' . $class . '">' . do_html($2) . "</td></tr>\n";
84 # UNEXPECTED results can be followed by one or two images
85 $testline = &readcleanline;
87 print '<tr><td class="FAILIMAGES">';
89 if ($testline =~ /REFTEST IMAGE: (data:.*)$/) {
90 print '<a href="' . $1 . '"><img class="testresult" src="' . $1 . '"></a>';
91 } elsif ($testline =~ /REFTEST IMAGE 1 \(TEST\): (data:.*)$/) {
92 $refline = &readcleanline;
93 print '<a href="' . $1 . '"><img class="testresult" src="' . $1 . '"></a>';
94 {
95 die "Error on line $l" unless $refline =~ /REFTEST IMAGE 2 \(REFERENCE\): (data:.*)$/;
96 print '<a href="' . $1 . '"><img class="testref" src="' . $1 . '"></a>';
97 }
99 } else {
100 die "Error on line $l";
101 }
103 print "</td></tr>\n";
104 } elsif (/^TEST-KNOWN-FAIL \| (.*$)/) {
105 my $class = $randomresult ? "XFAILRANDOM" : "XFAIL";
106 print '<tr><td class="' . $class . '">' . do_html($1) . "</td></tr>\n";
107 } else {
108 print STDERR "Unknown Line: " . $_ . "\n";
109 print "<tr><td><pre>" . $_ . "</pre></td></tr>\n";
110 }
111 }
113 print <<EOD
114 </table>
115 </body>
116 </html>
117 EOD
118 ;