simpler creation of coverage reports
[imager.git] / imcover.perl
CommitLineData
1ef586b1
TC
1#!perl -w
2use strict;
3use Config;
4use ExtUtils::Manifest 'maniread';
5
6my $make = $Config{make};
7# if there's a way to make with profiling for a recursive build like
8# Imager I don't see how
9if (-f 'Makefile') {
10 system "$make clean";
11}
12system "cover -delete";
13system "perl Makefile.PL --coverage"
14 and die;
15system "$make 'OTHERLDFLAGS=-ftest-coverage -fprofile-arcs'"
16 and die;
17
18system "$make test HARNESS_PERL_SWITCHES=-MDevel::Cover";
19
20# build gcov files
21my $mani = maniread();
22# split by directory
23my %paths;
24for my $filename (keys %$mani) {
25 next unless $filename =~ /\.(xs|c|im)$/;
26 if ($filename =~ m!^(\w+)/(\w+\.\w+)$!) {
27 push @{$paths{$1}}, $2;
28 }
29 else {
30 push @{$paths{''}}, $filename;
31 }
32}
33
34for my $path (keys %paths) {
35 if ($path) {
36 system "cd $path ; gcov @{$paths{$path}} ; cd ..";
37 }
38 else {
39 system "gcov @{$paths{$path}}";
40 }
41 my $dir = $path ? $path : '.';
42 for my $file (@{$paths{$path}}) {
43 system "gcov2perl $dir/$file.gcov";
44 }
45}
46
47my @dbs = "cover_db", map "$_/cover_db", grep $_, keys %paths;
48system "cover @dbs";
49