]> git.imager.perl.org - imager.git/blame - imcover.perl
adjust the IEEEFP check for older versions of perl
[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;
40b02446 11my $make_opts = "";
7fcc2ea8 12GetOptions("t|test=s" => \@tests,
40b02446 13 "m=s" => \$make_opts,
6aadff55 14 "n" => \$nodc,
7fcc2ea8
TC
15 "v" => \$verbose)
16 or die;
1ef586b1
TC
17
18my $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
21if (-f 'Makefile') {
7fcc2ea8 22 run("$make clean");
1ef586b1 23}
7fcc2ea8 24run("cover -delete");
25e68978 25run("perl Makefile.PL --coverage @ARGV")
40b02446
TC
26 and die "Makefile.PL failed\n";
27run("$make $make_opts 'OTHERLDFLAGS=-ftest-coverage -fprofile-arcs'")
28 and die "build failed\n";
1ef586b1 29
86c50c46 30{
bdea445e 31 local $ENV{DEVEL_COVER_OPTIONS} = "-db," . getcwd() . "/cover_db,-coverage,statement,branch,condition,subroutine";
6aadff55
TC
32 my $makecmd = "$make test TEST_VERBOSE=1";
33 $makecmd .= " HARNESS_PERL_SWITCHES=-MDevel::Cover" unless $nodc;
7fcc2ea8
TC
34 if (@tests) {
35 $makecmd .= " TEST_FILES='@tests'";
36 }
40b02446
TC
37 run($makecmd)
38 and die "Test failed\n";
86c50c46 39}
1ef586b1
TC
40
41# build gcov files
42my $mani = maniread();
43# split by directory
44my %paths;
45for my $filename (keys %$mani) {
46 next unless $filename =~ /\.(xs|c|im)$/;
778ca6eb
TC
47 (my $gcda = $filename) =~ s/\.\w+$/.gcda/;
48 next unless -f $gcda;
1ef586b1
TC
49 if ($filename =~ m!^(\w+)/(\w+\.\w+)$!) {
50 push @{$paths{$1}}, $2;
51 }
52 else {
53 push @{$paths{''}}, $filename;
54 }
8091ecbe
TC
55 if ($filename =~ s/\.(xs|im)$/.c/) {
56 if ($filename =~ m!^(\w+)/(\w+\.\w+)$!) {
57 push @{$paths{$1}}, $2;
58 }
59 else {
60 push @{$paths{''}}, $filename;
61 }
62 }
1ef586b1
TC
63}
64
65for my $path (keys %paths) {
66 if ($path) {
7fcc2ea8 67 run("cd $path ; gcov -abc @{$paths{$path}} ; cd ..");
1ef586b1
TC
68 }
69 else {
7fcc2ea8 70 run("gcov -abc @{$paths{$path}}");
1ef586b1
TC
71 }
72 my $dir = $path ? $path : '.';
73 for my $file (@{$paths{$path}}) {
7fcc2ea8 74 run("gcov2perl $dir/$file.gcov");
1ef586b1
TC
75 }
76}
77
78my @dbs = "cover_db", map "$_/cover_db", grep $_, keys %paths;
7fcc2ea8
TC
79# we already ran gcov
80run("cover -nogcov -ignore_re '^t/'");
1ef586b1 81
7fcc2ea8
TC
82sub run {
83 my $cmd = shift;
84
85 print "Running: $cmd\n" if $verbose;
86 return system $cmd;
87}