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