]> git.imager.perl.org - imager.git/blame - imcover.perl
set pixels with no coverage to all zero
[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 = "";
1c7c3940 12my $regen_only;
7fcc2ea8 13GetOptions("t|test=s" => \@tests,
40b02446 14 "m=s" => \$make_opts,
6aadff55 15 "n" => \$nodc,
1c7c3940
TC
16 "v" => \$verbose,
17 "r" => \$regen_only)
7fcc2ea8 18 or die;
1ef586b1 19
1c7c3940
TC
20my $do_build = !$regen_only;
21if ($do_build) {
22 my $make = $Config{make};
23 # if there's a way to make with profiling for a recursive build like
24 # Imager I don't see how
25 if (-f 'Makefile') {
26 run("$make clean");
27 }
28 run("cover -delete");
a6f7bffe 29 run("$^X Makefile.PL --coverage @ARGV")
1c7c3940
TC
30 and die "Makefile.PL failed\n";
31 run("$make $make_opts 'OTHERLDFLAGS=-ftest-coverage -fprofile-arcs'")
32 and die "build failed\n";
1ef586b1 33
1c7c3940
TC
34 {
35 local $ENV{DEVEL_COVER_OPTIONS} = "-db," . getcwd() . "/cover_db,-coverage,statement,branch,condition,subroutine";
36 my $makecmd = "$make test";
37 $makecmd .= " TEST_VERBOSE=1" if $verbose;
38 $makecmd .= " HARNESS_PERL_SWITCHES=-MDevel::Cover" unless $nodc;
39 if (@tests) {
40 $makecmd .= " TEST_FILES='@tests'";
41 }
42 run($makecmd)
43 and die "Test failed\n";
7fcc2ea8 44 }
86c50c46 45}
1ef586b1
TC
46
47# build gcov files
48my $mani = maniread();
49# split by directory
50my %paths;
51for my $filename (keys %$mani) {
52 next unless $filename =~ /\.(xs|c|im)$/;
778ca6eb
TC
53 (my $gcda = $filename) =~ s/\.\w+$/.gcda/;
54 next unless -f $gcda;
1ef586b1
TC
55 if ($filename =~ m!^(\w+)/(\w+\.\w+)$!) {
56 push @{$paths{$1}}, $2;
57 }
58 else {
59 push @{$paths{''}}, $filename;
60 }
8091ecbe
TC
61 if ($filename =~ s/\.(xs|im)$/.c/) {
62 if ($filename =~ m!^(\w+)/(\w+\.\w+)$!) {
63 push @{$paths{$1}}, $2;
64 }
65 else {
66 push @{$paths{''}}, $filename;
67 }
68 }
1ef586b1
TC
69}
70
a6f7bffe
TC
71my $gcov2perl = $Config{sitebin} . "/gcov2perl";
72
1ef586b1
TC
73for my $path (keys %paths) {
74 if ($path) {
7fcc2ea8 75 run("cd $path ; gcov -abc @{$paths{$path}} ; cd ..");
1ef586b1
TC
76 }
77 else {
7fcc2ea8 78 run("gcov -abc @{$paths{$path}}");
1ef586b1
TC
79 }
80 my $dir = $path ? $path : '.';
81 for my $file (@{$paths{$path}}) {
a6f7bffe 82 run("$gcov2perl $dir/$file.gcov");
1ef586b1
TC
83 }
84}
85
86my @dbs = "cover_db", map "$_/cover_db", grep $_, keys %paths;
7fcc2ea8
TC
87# we already ran gcov
88run("cover -nogcov -ignore_re '^t/'");
1ef586b1 89
7fcc2ea8
TC
90sub run {
91 my $cmd = shift;
92
93 print "Running: $cmd\n" if $verbose;
94 return system $cmd;
95}
1c7c3940
TC
96
97=head1 NAME
98
99imcover.perl - perform C and perl coverage testing for Imager
100
101=head1 SYNOPSIS
102
103 perl imcover.perl [-m=...][-t=...][-n][-v][-r] -- ... Makefile.PL options
104
105=head1 DESCRIPTION
106
107Builds Imager with the C< -ftest-coverage -fprofile-arcs > gcc options
108and then runs perl's tests.
109
110=cut