[llvm] [llvm-cov] format cells in code coverage report with 0/0 branches/functions/lines differently (PR #75780)

Hana Dusíková via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 18 02:18:53 PST 2023


https://github.com/hanickadot created https://github.com/llvm/llvm-project/pull/75780

Currently such cells in the report are formatted as red. Which screams "problem" but with more and more rangefied code, there can be whole files without any branch inside them. 

Before:
<img width="916" alt="Screenshot 2023-12-18 at 11 09 07" src="https://github.com/llvm/llvm-project/assets/6557263/d0e79c75-7f34-471f-a1f6-a2fd2bd111f2">

After:
<img width="920" alt="Screenshot 2023-12-18 at 11 08 29" src="https://github.com/llvm/llvm-project/assets/6557263/7db3278f-ad6d-4421-967a-cf72b67c5760">

Things to notice:
-  highlighted line which is result of cursor hover (now whole line is highlighted)
-  before there were some borders doubled (fixed)
-  cells with `- 0/0` coverage are no longer red




>From 6d19504c09f66d8b9b290397b84d60533c3bf7e6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Hana=20Dusi=CC=81kova=CC=81?= <hanicka at hanicka.net>
Date: Mon, 18 Dec 2023 11:11:15 +0100
Subject: [PATCH] [llvm-cov] format cells in report with 0/0
 branches/functions/lines differenly (gray instead red) and make the table a
 bit nicer

---
 .../tools/llvm-cov/SourceCoverageViewHTML.cpp | 24 +++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)

diff --git a/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp b/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp
index b43e9e64231e0c..e1aa5e4a05af78 100644
--- a/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp
+++ b/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp
@@ -130,10 +130,14 @@ table {
 .light-row {
   background: #ffffff;
   border: 1px solid #dbdbdb;
+  border-left: none;
+  border-right: none;
 }
 .light-row-bold {
   background: #ffffff;
   border: 1px solid #dbdbdb;
+  border-left: none;
+  border-right: none;
   font-weight: bold;
 }
 .column-entry {
@@ -147,21 +151,28 @@ table {
   text-align: left;
   background-color: #ffffd0;
 }
-.column-entry-yellow:hover {
+.column-entry-yellow:hover, tr:hover .column-entry-yellow {
   background-color: #fffff0;
 }
 .column-entry-red {
   text-align: left;
   background-color: #ffd0d0;
 }
-.column-entry-red:hover {
+.column-entry-red:hover, tr:hover .column-entry-red {
   background-color: #fff0f0;
 }
+.column-entry-gray {
+  text-align: left;
+  background-color: #fbfbfb;
+}
+.column-entry-gray:hover, tr:hover .column-entry-gray {
+  background-color: #f0f0f0;
+}
 .column-entry-green {
   text-align: left;
   background-color: #d0ffd0;
 }
-.column-entry-green:hover {
+.column-entry-green:hover, tr:hover .column-entry-green {
   background-color: #f0fff0;
 }
 .line-number {
@@ -232,6 +243,9 @@ td:last-child {
 tr:hover {
   background-color: #f0f0f0;
 }
+tr:last-child {
+  border-bottom: none;
+}
 )";
 
 const char *EndHeader = "</head>";
@@ -309,7 +323,9 @@ void emitTableRow(raw_ostream &OS, const CoverageViewOptions &Opts,
           RSO << '(' << Hit << '/' << Total << ')';
         }
         const char *CellClass = "column-entry-yellow";
-        if (Pctg >= Opts.HighCovWatermark)
+        if (!Total) {
+          CellClass = "column-entry-gray";
+        } else if (Pctg >= Opts.HighCovWatermark)
           CellClass = "column-entry-green";
         else if (Pctg < Opts.LowCovWatermark)
           CellClass = "column-entry-red";



More information about the llvm-commits mailing list