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
|
# scripts/lib/render-coverage-index.awk
# Render the coverage index page from summary rows.
# Input CSV rows (no header): "<file>,<executable>,<covered>,<percent>".
# Per-file detail pages are expected at html/<file>.html.
# Variables: -v TITLE="..."
function esc(s) {
gsub(/&/, "\\&", s); gsub(/</, "\\<", s); gsub(/>/, "\\>", s)
return s
}
function color(p) {
if (p + 0 >= 80) return "#2da44e"
if (p + 0 >= 50) return "#bf8700"
return "#cf222e"
}
BEGIN { FS = ","; n = 0; tot = 0; cov = 0 }
{
n++
f[n] = $1; ex[n] = $2 + 0; cv[n] = $3 + 0; pc[n] = $4 + 0
tot += $2 + 0; cov += $3 + 0
}
END {
overall = (tot > 0 ? cov * 100.0 / tot : 0)
print "<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"utf-8\">"
print "<title>" esc(TITLE) "</title>"
print "<style>body{font:14px/1.5 sans-serif;margin:0;padding:1.5rem;color:#111}"
print "h1{font-size:18px}.overall{font-size:15px;margin:.5rem 0 1rem}"
print "table{border-collapse:collapse;width:100%;max-width:820px}"
print "th,td{padding:.35rem .5rem;text-align:left;border-bottom:1px solid #eee}"
print "td.num{text-align:right;font-variant-numeric:tabular-nums}"
print ".track{background:#eee;border-radius:3px;height:.7em;width:160px}"
print ".fill{height:.7em;border-radius:3px}"
print "a{color:#0969da;text-decoration:none}a:hover{text-decoration:underline}"
print "</style></head><body>"
print "<h1>" esc(TITLE) "</h1>"
printf "<div class=\"overall\">Overall: <strong style=\"color:%s\">%.1f%%</strong> (%d/%d executable lines)</div>\n", color(overall), overall, cov, tot
print "<table><thead><tr><th>file</th><th>coverage</th><th>%</th><th>covered</th><th>executable</th></tr></thead><tbody>"
for (i = 1; i <= n; i++) {
printf "<tr><td><a href=\"html/%s.html\">%s</a></td>", esc(f[i]), esc(f[i])
printf "<td><div class=\"track\"><div class=\"fill\" style=\"width:%.0f%%;background:%s\"></div></div></td>", pc[i], color(pc[i])
printf "<td class=\"num\">%.1f%%</td><td class=\"num\">%d</td><td class=\"num\">%d</td></tr>\n", pc[i], cv[i], ex[i]
}
print "</tbody></table></body></html>"
}
|