Commit | Line | Data |
---|---|---|
1ef586b1 TC |
1 | #!perl -w |
2 | use strict; | |
3 | use Config; | |
4 | use ExtUtils::Manifest 'maniread'; | |
86c50c46 | 5 | use Cwd; |
7fcc2ea8 TC |
6 | use Getopt::Long; |
7 | ||
8 | my @tests; | |
9 | my $verbose; | |
6aadff55 | 10 | my $nodc; |
7fcc2ea8 | 11 | GetOptions("t|test=s" => \@tests, |
6aadff55 | 12 | "n" => \$nodc, |
7fcc2ea8 TC |
13 | "v" => \$verbose) |
14 | or die; | |
1ef586b1 TC |
15 | |
16 | my $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 | |
19 | if (-f 'Makefile') { | |
7fcc2ea8 | 20 | run("$make clean"); |
1ef586b1 | 21 | } |
7fcc2ea8 | 22 | run("cover -delete"); |
25e68978 | 23 | run("perl Makefile.PL --coverage @ARGV") |
1ef586b1 | 24 | and die; |
7fcc2ea8 | 25 | run("$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 | |
39 | my $mani = maniread(); | |
40 | # split by directory | |
41 | my %paths; | |
42 | for my $filename (keys %$mani) { | |
43 | next unless $filename =~ /\.(xs|c|im)$/; | |
44 | if ($filename =~ m!^(\w+)/(\w+\.\w+)$!) { | |
45 | push @{$paths{$1}}, $2; | |
46 | } | |
47 | else { | |
48 | push @{$paths{''}}, $filename; | |
49 | } | |
50 | } | |
51 | ||
52 | for my $path (keys %paths) { | |
53 | if ($path) { | |
7fcc2ea8 | 54 | run("cd $path ; gcov -abc @{$paths{$path}} ; cd .."); |
1ef586b1 TC |
55 | } |
56 | else { | |
7fcc2ea8 | 57 | run("gcov -abc @{$paths{$path}}"); |
1ef586b1 TC |
58 | } |
59 | my $dir = $path ? $path : '.'; | |
60 | for my $file (@{$paths{$path}}) { | |
7fcc2ea8 | 61 | run("gcov2perl $dir/$file.gcov"); |
1ef586b1 TC |
62 | } |
63 | } | |
64 | ||
65 | my @dbs = "cover_db", map "$_/cover_db", grep $_, keys %paths; | |
7fcc2ea8 TC |
66 | # we already ran gcov |
67 | run("cover -nogcov -ignore_re '^t/'"); | |
1ef586b1 | 68 | |
7fcc2ea8 TC |
69 | sub run { |
70 | my $cmd = shift; | |
71 | ||
72 | print "Running: $cmd\n" if $verbose; | |
73 | return system $cmd; | |
74 | } |