lcov-inject 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/usr/bin/perl
  2. #
  3. # lcov-inject
  4. #
  5. # Copyright © 2014 Guillem Jover <guillem@debian.org>
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. #
  20. use strict;
  21. use warnings;
  22. use Cwd;
  23. use Devel::Cover::DB;
  24. my $dir = $ARGV[0] // 'scripts';
  25. my $cwd = cwd();
  26. chdir $dir or die "cannot switch to $dir\n";
  27. my $db = Devel::Cover::DB->new(db => 'cover_db');
  28. $db = $db->merge_runs();
  29. $db->calculate_summary(map { $_ => 1 } $db->collected());
  30. chdir $cwd or die "cannot switch to $cwd\n";
  31. my $s = $db->{summary}{Total};
  32. my $tmpl = sprintf '
  33. <td class="coverFile"><a href="%s">%s</a></td>
  34. <td class="coverBar" align="center">
  35. <table border=0 cellspacing=0 cellpadding=1>
  36. <tr><td class="coverBarOutline">
  37. <img src="ruby.png" width=%.0f height=10 alt="%.1f"><img src="snow.png" width=%.0f height=10 alt="%.1f">
  38. </td></tr>
  39. </table>
  40. </td>
  41. <td class="coverPerLo">%.1f&nbsp;%%</td>
  42. <td class="coverNumLo">%d / %d</td>
  43. <td class="coverPerLo">%.1f&nbsp;%%</td>
  44. <td class="coverNumLo">%d / %d</td>
  45. <td class="coverPerLo">%.1f&nbsp;%%</td>
  46. <td class="coverNumLo">%d / %d</td>
  47. </tr>
  48. <tr>
  49. ', "$dir/coverage.html", $dir,
  50. $s->{total}{percentage}, $s->{total}{percentage},
  51. 100 - $s->{total}{percentage}, $s->{total}{percentage},
  52. $s->{total}{percentage}, $s->{total}{covered}, $s->{total}{total},
  53. $s->{subroutine}{percentage},
  54. $s->{subroutine}{covered}, $s->{subroutine}{total},
  55. $s->{branch}{percentage}, $s->{branch}{covered}, $s->{branch}{total};
  56. while (<>) {
  57. s/^(.*<td .*href="src\/index\.html">.*)$/$tmpl$1/;
  58. print;
  59. }
  60. 1;