git » chasquid » commit 150976b

test: Use a pretty table for the coverage html

author Alberto Bertogli
2020-03-04 00:59:37 UTC
committer Alberto Bertogli
2020-03-04 00:59:37 UTC
parent a1ca50ab57b0da35baa51083ffb4d5dcf1799f2f

test: Use a pretty table for the coverage html

This patch improves the readability and usability of the generated
coverage HTML by making the list of files be a table.

test/util/coverhtml.go +32 -4

diff --git a/test/util/coverhtml.go b/test/util/coverhtml.go
index 85f91b0..768e99a 100644
--- a/test/util/coverhtml.go
+++ b/test/util/coverhtml.go
@@ -191,6 +191,27 @@ const htmlTmpl = `<!DOCTYPE html>
         color: #069;
       }
 
+      table {
+        border-collapse: collapse;
+      }
+
+      tr:nth-child(odd) {
+        background: #f5f5f7;
+      }
+
+      tr.total {
+        border-top: 1px solid;
+        font-weight: bold;
+      }
+
+      td {
+        padding: 0.2em 1em;
+      }
+
+      td.pcnt {
+        text-align: right;
+      }
+
       code, pre, tt {
         font-family: Monaco, Bitstream Vera Sans Mono, Lucida Console,
           Terminal, Consolas, Liberation Mono, DejaVu Sans Mono,
@@ -241,13 +262,20 @@ const htmlTmpl = `<!DOCTYPE html>
 
   {{.Notes}}<p>
 
-  <tt>Total: {{.Totals.TotalPercent | printf "%.2f"}}%</tt><p>
-
+  <table>
   {{range .Files}}
-  <tt><a onclick="visible('f::{{.}}')">
-    {{.}}  ({{$.Totals.Percent . | printf "%.1f%%"}})</a></tt><br>
+  <tr>
+    <td><a onclick="visible('f::{{.}}')" tabindex="0"> {{.}} </a></td>
+    <td class="pcnt">{{$.Totals.Percent . | printf "%.1f%%"}}</td>
+  </tr>
   {{- end}}
 
+  <tr class="total">
+    <td>Total</td>
+    <td class="pcnt">{{.Totals.TotalPercent | printf "%.1f"}}%</td>
+  </tr>
+  </table>
+
   <div id="source">
   {{range .Files}}
   <pre class="file" id="f::{{.}}" style="display: none">{{index $.Code .}}</pre>