-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake-report
executable file
·108 lines (106 loc) · 2.54 KB
/
make-report
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env perl
use 5.024;
use utf8;
use strictures;
use File::Slurper qw(read_binary);
use List::AllUtils qw(uniq);
use TAP::Parser qw();
use Text::Xslate qw();
my $r;
my (@grammars, @parsers);
for my $file (glob 'reports/*__*.tap') {
my $parser = TAP::Parser->new({source => $file});
my @tests;
my $idx = 0;
while (my $result = $parser->next) {
last if $result->is_plan;
$idx++ if $result->is_test;
$tests[$idx] .= $result->as_string . "\n";
}
shift @tests unless $tests[0];
$file =~ s|^reports/||;
$file =~ s/\.tap$//;
my ($g, $p) = split '__', $file;
push @grammars, $g;
push @parsers, $p;
$r->{$g}{$p} = \@tests;
}
my $tx = Text::Xslate->new(
function => {
ok => sub { $_[0] =~ /^ok/ }
}
);
my $vars = {
r => $r,
parsers => [sort, uniq @parsers],
grammars => [sort, uniq @grammars],
};
open my $fh, '>:encoding(UTF-8)', 'comparison.html' or die "report.html: $!";
$fh->print($tx->render_string(<<~'...', $vars));
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
table, tr, th, td { border: 2px inset; }
td { vertical-align: top; }
p { background: #fcb; }
p.ok { background: #bfd; }
p.collapse { display: inline-block; }
p.collapse:after { content: '✘'; }
p.ok.collapse:after { content: '✔'; }
code { white-space: pre-wrap; }
.collapse > code { display: none; }
</style>
<script src="jquery-3.4.1.slim.min.js"></script>
<script>
let collapse = button => {
button.parent().parent().find('td').each(
(_,td) => {
$(td).find('p').each(
(_,pelem) => {
let p = $(pelem);
if (p.hasClass('collapse')) {
p.removeClass('collapse');
} else {
p.addClass('collapse');
}
}
)
}
);
};
$(() => {
$('button').each((idx,button) => collapse($(button)));
$('button').click(ev => collapse($(ev.target)))
});
</script>
</head>
<body>
<table>
<tr>
<th>grammar</th>
: for $parsers -> $p {
<th><: $p :></th>
: }
</tr>
: for $grammars -> $g {
<tr>
<td><: $g :><button>⮕</button></td>
: for $parsers -> $p {
<td>
: for $r[$g][$p] -> $test {
<p
: if ok($test) {
class="ok"
: }
><code><:$test:></code></p>
: }
</td>
: }
</tr>
: }
</table>
</body>
</html>
...