summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorGuillem Jover <guillem@debian.org>2014-05-04 19:56:53 +0200
committerGuillem Jover <guillem@debian.org>2014-05-17 09:28:58 +0200
commit3fb93b089cd890aadc043c79c7926682b23392bf (patch)
treed56ca398922a353fc70c949ae7111fbd411a1372 /doc
parentacd884519b4c4aae38ef37e26fe14cbffe2b4f78 (diff)
downloaddpkg-3fb93b089cd890aadc043c79c7926682b23392bf.tar.gz
build: Fix lcov-inject to consider different coverage percentages
The current code was not taking into account the different coverage ranges, with their different colors, and different images for the completion bar. Refactor the code into functions, while we are at it.
Diffstat (limited to 'doc')
-rwxr-xr-xdoc/lcov-inject61
1 files changed, 45 insertions, 16 deletions
diff --git a/doc/lcov-inject b/doc/lcov-inject
index ecb614a19..eda121d5a 100755
--- a/doc/lcov-inject
+++ b/doc/lcov-inject
@@ -41,30 +41,59 @@ my $tmpl = sprintf '
<td class="coverFile"><a href="%s">%s</a></td>
<td class="coverBar" align="center">
<table border=0 cellspacing=0 cellpadding=1>
- <tr><td class="coverBarOutline">
- <img src="ruby.png" width=%.0f height=10 alt="%.1f"><img src="snow.png" width=%.0f height=10 alt="%.1f">
- </td></tr>
+ <tr><td class="coverBarOutline">%s</td></tr>
</table>
</td>
- <td class="coverPerLo">%.1f&nbsp;%%</td>
- <td class="coverNumLo">%d / %d</td>
- <td class="coverPerLo">%.1f&nbsp;%%</td>
- <td class="coverNumLo">%d / %d</td>
- <td class="coverPerLo">%.1f&nbsp;%%</td>
- <td class="coverNumLo">%d / %d</td>
+ %s
+ %s
+ %s
</tr>
<tr>
-', "$dir/coverage.html", $dir,
- $s->{total}{percentage}, $s->{total}{percentage},
- 100 - $s->{total}{percentage}, $s->{total}{percentage},
- $s->{total}{percentage}, $s->{total}{covered}, $s->{total}{total},
- $s->{subroutine}{percentage},
- $s->{subroutine}{covered}, $s->{subroutine}{total},
- $s->{branch}{percentage}, $s->{branch}{covered}, $s->{branch}{total};
+', "$dir/coverage.html", $dir, bar_html($s->{total}{percentage}),
+ box_html($s->{total}), box_html($s->{subroutine}), box_html($s->{branch});
while (<>) {
s/^(.*<td .*href="src\/index\.html">.*)$/$tmpl$1/;
print;
}
+sub bar_image {
+ my ($num) = @_;
+
+ return 'emerald.png' if $num >= 90;
+ return 'ruby.png' if $num < 75;
+ return 'amber.png';
+}
+
+sub bar_html {
+ my ($num) = @_;
+
+ my $html = sprintf '<img src="%s" width=%.0f height=10 alt="%.1f">',
+ bar_image($num), $num, $num;
+
+ if ($num < 100) {
+ $html .= sprintf '<img src="snow.png" width=%.0f height=10 alt="%.1f">',
+ 100 - $num, $num;
+ }
+
+ return $html;
+}
+
+sub box_rating {
+ my ($num) = @_;
+
+ return 'Hi' if $num >= 90;
+ return 'Lo' if $num < 75;
+ return 'Med';
+}
+
+sub box_html {
+ my ($stats) = @_;
+
+ return sprintf '<td class="coverPer%s">%.1f&nbsp;%%</td>\n' .
+ '<td class="coverNum%s">%d / %d</td>',
+ box_rating($stats->{percentage}), $stats->{percentage},
+ box_rating($stats->{percentage}), $stats->{covered}, $stats->{total};
+}
+
1;