]> git.imager.perl.org - imager.git/blame - imcover.perl
avoid trying to gcov unincluded files
[imager.git] / imcover.perl
CommitLineData
1ef586b1
TC
1#!perl -w
2use strict;
3use Config;
4use ExtUtils::Manifest 'maniread';
86c50c46 5use Cwd;
7fcc2ea8
TC
6use Getopt::Long;
7
8my @tests;
9my $verbose;
6aadff55 10my $nodc;
7fcc2ea8 11GetOptions("t|test=s" => \@tests,
6aadff55 12 "n" => \$nodc,
7fcc2ea8
TC
13 "v" => \$verbose)
14 or die;
1ef586b1
TC
15
16my $make = $Config{make};
17# if there's a way to make with profiling for a recursive build like
18# Imager I don't see how
19if (-f 'Makefile') {
7fcc2ea8 20 run("$make clean");
1ef586b1 21}
7fcc2ea8 22run("cover -delete");
25e68978 23run("perl Makefile.PL --coverage @ARGV")
1ef586b1 24 and die;
7fcc2ea8 25run("$make 'OTHERLDFLAGS=-ftest-coverage -fprofile-arcs'")
1ef586b1
TC
26 and die;
27
86c50c46 28{
bdea445e 29 local $ENV{DEVEL_COVER_OPTIONS} = "-db," . getcwd() . "/cover_db,-coverage,statement,branch,condition,subroutine";
6aadff55
TC
30 my $makecmd = "$make test TEST_VERBOSE=1";
31 $makecmd .= " HARNESS_PERL_SWITCHES=-MDevel::Cover" unless $nodc;
7fcc2ea8
TC
32 if (@tests) {
33 $makecmd .= " TEST_FILES='@tests'";
34 }
35 run($makecmd);
86c50c46 36}
1ef586b1
TC
37
38# build gcov files
39my $mani = maniread();
40# split by directory
41my %paths;
42for my $filename (keys %$mani) {
43 next unless $filename =~ /\.(xs|c|im)$/;
778ca6eb
TC
44 (my $gcda = $filename) =~ s/\.\w+$/.gcda/;
45 next unless -f $gcda;
1ef586b1
TC
46 if ($filename =~ m!^(\w+)/(\w+\.\w+)$!) {
47 push @{$paths{$1}}, $2;
48 }
49 else {
50 push @{$paths{''}}, $filename;
51 }
52}
53
54for my $path (keys %paths) {
55 if ($path) {
7fcc2ea8 56 run("cd $path ; gcov -abc @{$paths{$path}} ; cd ..");
1ef586b1
TC
57 }
58 else {
7fcc2ea8 59 run("gcov -abc @{$paths{$path}}");
1ef586b1
TC
60 }
61 my $dir = $path ? $path : '.';
62 for my $file (@{$paths{$path}}) {
7fcc2ea8 63 run("gcov2perl $dir/$file.gcov");
1ef586b1
TC
64 }
65}
66
67my @dbs = "cover_db", map "$_/cover_db", grep $_, keys %paths;
7fcc2ea8
TC
68# we already ran gcov
69run("cover -nogcov -ignore_re '^t/'");
1ef586b1 70
7fcc2ea8
TC
71sub run {
72 my $cmd = shift;
73
74 print "Running: $cmd\n" if $verbose;
75 return system $cmd;
76}