summaryrefslogtreecommitdiff
path: root/doc/lcov-inject
blob: 0875bd29c488d451a81fc6bf661308328ab3f7a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/perl
#
# lcov-inject
#
# Copyright © 2014 Guillem Jover <guillem@debian.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.
#

use strict;
use warnings;

use Cwd;
use Devel::Cover::DB;

my $dir = $ARGV[0] // 'scripts';
my $cwd = cwd();

chdir $dir or die "cannot switch to $dir\n";

my $db = Devel::Cover::DB->new(db => 'cover_db');
$db = $db->merge_runs();
$db->calculate_summary(map { $_ => 1 } $db->collected());

chdir $cwd or die "cannot switch to $cwd\n";

my $s = $db->{summary}{Total};

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>
        </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>
    </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};

while (<>) {
    s/^(.*<td .*href="src\/index\.html">.*)$/$tmpl$1/;
    print;
}

1;