From 527be5b5621a54bf5a0a6e0f75938ff2f8be8b28 Mon Sep 17 00:00:00 2001 From: Eric Grange Date: Mon, 14 Feb 2022 08:14:35 +0100 Subject: [PATCH] HTMLReport improvements - added "not covered" line count, to help find units with most uncovered lines of code - table header & footer are now stick, so they are always in view - disable text selection on sortable column headers - unit navigator moved to the right and made responsive --- Source/HTMLCoverageReport.pas | 52 +++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/Source/HTMLCoverageReport.pas b/Source/HTMLCoverageReport.pas index 57acec6..86c5864 100644 --- a/Source/HTMLCoverageReport.pas +++ b/Source/HTMLCoverageReport.pas @@ -80,7 +80,7 @@ THTMLCoverageReport = class(TInterfacedObject, IReport) const SourceClass: string = ' class="s"'; - OverviewClass: string = ' class="o"'; + OverviewClass: string = 'o'; SummaryClass: string = ' class="sum"'; implementation @@ -280,7 +280,7 @@ procedure THTMLCoverageReport.IterateOverStats( HtmlDetails : THtmlDetails; PostLink: string; PreLink: string; - Percent: String; + PercentCovered: String; CurrentStats: ICoverageStats; begin AOutputFile.WriteLine('' - + Percent - ) + '' + + '' + PreLink + HtmlDetails.LinkName + PostLink + + '' + IntToStr(CurrentStats.CoveredLineCount) + + '' + IntToStr(CurrentStats.LineCount - CurrentStats.CoveredLineCount) + + '' + IntToStr(CurrentStats.LineCount) + + '' + + PercentCovered ); end; end; @@ -339,14 +341,14 @@ procedure THTMLCoverageReport.AddPreAmble(const AOutFile: TTextWriter); AOutFile.WriteLine('body {max-width: max-content;margin: auto;}'); - AOutFile.WriteLine('table {border-spacing:0; border-collapse:collapse;}'); + AOutFile.WriteLine('table {border-spacing:0;}'); AOutFile.WriteLine('table, td, th {border: 0;}'); AOutFile.WriteLine('td, th {background: white; margin: 0; padding: .5em 1em}'); AOutFile.WriteLine('p, h1, h2, h3, th {font-family: verdana,arial,sans-serif; font-size: 10pt;}'); AOutFile.WriteLine('td {font-family: consolas,courier,monospace; font-size: 10pt;}'); AOutFile.WriteLine('th {background: #ccc;}'); - AOutFile.WriteLine('th[idx] {cursor:pointer;}'); + AOutFile.WriteLine('th[idx] {cursor: pointer; user-select: none;}'); AOutFile.WriteLine('table.o tr td:nth-child(1) {font-weight: bold;}'); AOutFile.WriteLine('table.o tr td:nth-child(2) {text-align: right;}'); @@ -364,11 +366,23 @@ procedure THTMLCoverageReport.AddPreAmble(const AOutFile: TTextWriter); AOutFile.WriteLine('table.sum td { background-position: 50%; background-repeat: no-repeat; background-size: 90% 70%; }'); AOutFile.WriteLine('table.sum tr:nth-child(odd) td { background-color: #f4f4f4}'); AOutFile.WriteLine('table.sum tr:hover td, tr:hover td a { filter: invert(10%) }'); - AOutFile.WriteLine('table.sum tr th {text-align:left; border: 1px solid #888}'); + AOutFile.WriteLine('table.sum tr th {text-align:left; border: 1px solid #888; height: 1em}'); AOutFile.WriteLine('table.sum tr td {text-align:right;}'); AOutFile.WriteLine('table.sum tr td:first-child {text-align:left;}'); - - AOutFile.WriteLine('#nav {position: fixed; margin-left: -3.5em; overflow: visible;}'); + AOutFile.WriteLine('table.sum thead th { position: sticky; top:0; }'); + AOutFile.WriteLine('table.sum thead tr + tr th { position: sticky; top: calc(2.5em - 2px); }'); + AOutFile.WriteLine('table.sum tfoot th { position: sticky; bottom:0; }'); + + + AOutFile.WriteLine( + '#nav {' + + 'position: fixed;' + + 'overflow: visible;' + + 'left: min(calc(50% + 41em), calc(100% - 6em));' + + 'padding: .1em .5em .1em .2em;' + + 'background: white;' + + 'box-shadow: 1px 1px 3px #888;' + + '}'); AOutFile.WriteLine('#nav div {opacity: .3; user-select: none; pointer-events: none;}'); AOutFile.WriteLine('#nav div.active {opacity: 1; cursor: pointer; pointer-events: initial;}'); AOutFile.WriteLine('#nav div.active:hover {color: #00A;}'); @@ -442,6 +456,7 @@ procedure THTMLCoverageReport.AddTableFooter( tr( th(TNetEncoding.HTML.Encode(AHeading)) + th(IntToStr(ACoverageStats.CoveredLineCount)) + + th(IntToStr(ACoverageStats.LineCount - ACoverageStats.CoveredLineCount)) + th(IntToStr(ACoverageStats.LineCount)) + th(em(IntToStr(ACoverageStats.PercentCovered) + '%')) ) @@ -460,11 +475,12 @@ procedure THTMLCoverageReport.AddTableHeader( '' + '' + '' + TNetEncoding.HTML.Encode(AColumnHeading) - + 'Number of lines' - + 'Percent(s) covered' + + 'Number of lines' + + 'Percent(s) covered' + '' + 'Covered' - + 'Which generated code' + + 'Not Covered' + + 'Which generated code' ); end;