Skip to content

Commit eb1b437

Browse files
Try #1548:
2 parents a9130c2 + 3820af5 commit eb1b437

File tree

2 files changed

+53
-46
lines changed

2 files changed

+53
-46
lines changed

lib/cover-project.nix

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,12 @@ coverageReports:
1010
let
1111
toBashArray = arr: "(" + (lib.concatStringsSep " " arr) + ")";
1212

13-
# Create table rows for a project coverage index page that look something like:
14-
#
15-
# | Package |
16-
# |------------------|
17-
# | cardano-shell |
18-
# | cardano-launcher |
19-
coverageTableRows = coverageReport:
13+
# Create a list element for a project coverage index page.
14+
coverageListElement = coverageReport:
2015
''
21-
<tr>
22-
<td>
23-
<a href="${coverageReport.passthru.name}/hpc_index.html">${coverageReport.passthru.name}</href>
24-
</td>
25-
</tr>
16+
<li>
17+
<a href="${coverageReport.passthru.name}/hpc_index.html">${coverageReport.passthru.name}</a>
18+
</li>
2619
'';
2720

2821
projectIndexHtml = pkgs.writeText "index.html" ''
@@ -31,16 +24,25 @@ let
3124
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
3225
</head>
3326
<body>
34-
<table border="1" width="100%">
35-
<tbody>
36-
<tr>
37-
<th>Report</th>
38-
</tr>
39-
40-
${with lib; concatStringsSep "\n" (map coverageTableRows coverageReports)}
41-
42-
</tbody>
43-
</table>
27+
<div>
28+
WARNING: Modules with no coverage are not included in any of these reports, this is just how HPC works under the hood.
29+
</div>
30+
<div>
31+
<h2>Union Report</h2>
32+
<p>The following report shows how each module is covered by any test in the project:</p>
33+
<ul>
34+
<li>
35+
<a href="all/hpc_index.html">all</a>
36+
</li>
37+
</ul>
38+
</div>
39+
<div>
40+
<h2>Individual Reports</h2>
41+
<p>The following reports show how each module is covered by tests in its own package:</p>
42+
<ul>
43+
${with lib; concatStringsSep "\n" (map coverageListElement coverageReports)}
44+
</ul>
45+
</div>
4446
</body>
4547
</html>
4648
'';

lib/cover.nix

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,25 @@ in pkgs.runCommand (name + "-coverage-report")
7070
local -n tixFs=$2
7171
local outFile="$3"
7272
73-
local hpcSumCmd=("hpc" "sum" "--union" "--output=$outFile")
74-
75-
for module in "''${includedModules[@]}"; do
76-
hpcSumCmd+=("--include=$module")
77-
done
78-
79-
for tixFile in "''${tixFs[@]}"; do
80-
hpcSumCmd+=("$tixFile")
81-
done
82-
83-
echo "''${hpcSumCmd[@]}"
84-
eval "''${hpcSumCmd[@]}"
73+
if (( "''${#tixFs[@]}" > 0 )); then
74+
local hpcSumCmd=("hpc" "sum" "--union" "--output=$outFile")
75+
76+
for module in "''${includedModules[@]}"; do
77+
hpcSumCmd+=("--include=$module")
78+
done
79+
80+
for tixFile in "''${tixFs[@]}"; do
81+
hpcSumCmd+=("$tixFile")
82+
done
83+
84+
echo "''${hpcSumCmd[@]}"
85+
eval "''${hpcSumCmd[@]}"
86+
else
87+
# If there are no tix files we output an empty tix file so that we can
88+
# markup an empty HTML coverage report. This is preferable to failing to
89+
# output a HTML report.
90+
echo 'Tix []' > $outFile
91+
fi
8592
}
8693
8794
function findModules() {
@@ -153,19 +160,17 @@ in pkgs.runCommand (name + "-coverage-report")
153160
154161
# Sum tix files to create a tix file with all relevant tix
155162
# information and markup a HTML report from this info.
156-
if (( "''${#tixFiles[@]}" > 0 )); then
157-
local sumTixFile="$out/share/hpc/vanilla/tix/${name}/${name}.tix"
158-
local markupOutDir="$out/share/hpc/vanilla/html/${name}"
163+
local sumTixFile="$out/share/hpc/vanilla/tix/${name}/${name}.tix"
164+
local markupOutDir="$out/share/hpc/vanilla/html/${name}"
159165
160-
# Sum all of our tix file, including modules from any local package
161-
sumTix allMixModules tixFiles "$sumTixFile"
166+
# Sum all of our tix file, including modules from any local package
167+
sumTix allMixModules tixFiles "$sumTixFile"
162168
163-
# Markup a HTML report, included modules from only this package
164-
markup srcDirs mixDirs pkgMixModules "$markupOutDir" "$sumTixFile"
169+
# Markup a HTML report, included modules from only this package
170+
markup srcDirs mixDirs pkgMixModules "$markupOutDir" "$sumTixFile"
165171
166-
# Provide a HTML zipfile and Hydra links
167-
( cd "$markupOutDir" ; zip -r $out/share/hpc/vanilla/${name}-html.zip . )
168-
echo "report coverage $markupOutDir/hpc_index.html" >> $out/nix-support/hydra-build-products
169-
echo "file zip $out/share/hpc/vanilla/${name}-html.zip" >> $out/nix-support/hydra-build-products
170-
fi
172+
# Provide a HTML zipfile and Hydra links
173+
( cd "$markupOutDir" ; zip -r $out/share/hpc/vanilla/${name}-html.zip . )
174+
echo "report coverage $markupOutDir/hpc_index.html" >> $out/nix-support/hydra-build-products
175+
echo "file zip $out/share/hpc/vanilla/${name}-html.zip" >> $out/nix-support/hydra-build-products
171176
''

0 commit comments

Comments
 (0)