Add links to custom coverage report.
When multiple files were missing coverage it could be hard to locate the coverage report for a specific file.
Add links for uncovered files to make this easier.
Also move table titles out of the table so they are valid html.
@@ -11,6 +11,7 @@ use warnings FATAL => qw(all);
use Carp qw(confess);
use English '-no_match_vars';
+use Digest::SHA qw(sha1_hex);
use Exporter qw(import);
our @EXPORT = qw();
use File::Basename qw(dirname);
@@ -102,6 +103,10 @@ sub coverageGenerate
{
$strFile = substr($strLine, 3);
$rhCoverage->{$strFile} = undef;
+
+ # Generate a random anchor so new reports will not show links as already followed. This is also an easy way
+ # to create valid, disambiguos links.
+ $rhCoverage->{$strFile}{anchor} = sha1_hex(rand(16));
}
# Check branch coverage
elsif ($strLine =~ /^BRDA\:/)
@@ -429,11 +434,13 @@ sub coverageGenerate
" color: white;\n" .
"}\n");
+ # File list title
$oHtml->bodyGet()->addNew(HTML_DIV, 'title', {strContent => $strTitle});
# Build the file list table
+ $oHtml->bodyGet()->addNew(HTML_DIV, 'list-table-caption');
+
my $oTable = $oHtml->bodyGet()->addNew(HTML_TABLE, 'list-table');
- $oTable->addNew(HTML_DIV, 'list-table-caption');
my $oHeader = $oTable->addNew(HTML_TR, 'list-table-header');
$oHeader->addNew(HTML_TH, 'list-table-header-file', {strContent => 'FILE'});
@@ -441,19 +448,35 @@ sub coverageGenerate
foreach my $strFile (sort(keys(%{$rhCoverage})))
{
my $oRow = $oTable->addNew(HTML_TR, 'list-table-row-' . (defined($rhCoverage->{$strFile}{line}) ? 'uncovered' : 'covered'));
+
+ # Link only created when file is uncovered
+ if (defined($rhCoverage->{$strFile}{line}))
+ {
+ $oRow->addNew(HTML_TD, 'list-table-row-file')->addNew(
+ HTML_A, undef,
+ {strContent => substr($strFile, length($strBasePath) + 1), strRef => '#' . $rhCoverage->{$strFile}{anchor}});
+ }
+ # Else just show the file name
+ else
+ {
$oRow->addNew(HTML_TD, 'list-table-row-file', {strContent => substr($strFile, length($strBasePath) + 1)});
}
+ }
# Report on files that are missing coverage
foreach my $strFile (sort(keys(%{$rhCoverage})))
{
if (defined($rhCoverage->{$strFile}{line}))
{
+ # Anchor only created when file is uncovered
+ $oHtml->bodyGet()->addNew(HTML_A, undef, {strId => $rhCoverage->{$strFile}{anchor}});
+
+ # Report table caption, i.e. the uncovered file name
+ $oHtml->bodyGet()->addNew(HTML_DIV, 'report-table-caption', {strContent => substr($strFile, length($strBasePath) + 1)});
+
# Build the file report table
$oTable = $oHtml->bodyGet()->addNew(HTML_TABLE, 'report-table');
- $oTable->addNew(HTML_DIV, 'report-table-caption', {strContent => substr($strFile, length($strBasePath) + 1)});
-
$oHeader = $oTable->addNew(HTML_TR, 'report-table-header');
$oHeader->addNew(HTML_TH, 'report-table-header-line', {strContent => 'LINE'});
$oHeader->addNew(HTML_TH, 'report-table-header-branch', {strContent => 'BRANCH'});
