]> git.imager.perl.org - imager.git/commitdiff
simpler creation of coverage reports
authorTony Cook <tony@develop=help.com>
Sun, 28 Jan 2007 01:54:58 +0000 (01:54 +0000)
committerTony Cook <tony@develop=help.com>
Sun, 28 Jan 2007 01:54:58 +0000 (01:54 +0000)
Makefile.PL
imcover.perl [new file with mode: 0644]

index f55e7d3097a1f3a9dcf1f20cf1c61a6eaa737c1f..b3b51f4a0c4ec0a029e6e0b8cde2bc3d9b9fcf38 100644 (file)
@@ -39,6 +39,7 @@ my @libpaths; # places to look for libraries
 my $noprobe; # non-zero to disable newer probes
 my $noexif; # non-zero to disable EXIF parsing of JPEGs
 my $no_gif_set_version; # disable calling EGifSetGifVersion
 my $noprobe; # non-zero to disable newer probes
 my $noexif; # non-zero to disable EXIF parsing of JPEGs
 my $no_gif_set_version; # disable calling EGifSetGifVersion
+my $coverage; # build for coverage testing
 GetOptions("help" => \$help,
            "enable=s" => \@enable,
            "disable=s" => \@disable,
 GetOptions("help" => \$help,
            "enable=s" => \@enable,
            "disable=s" => \@disable,
@@ -48,7 +49,8 @@ GetOptions("help" => \$help,
            "verbose|v" => \$VERBOSE,
            "nolog" => \$NOLOG,
           "noexif" => \$noexif,
            "verbose|v" => \$VERBOSE,
            "nolog" => \$NOLOG,
           "noexif" => \$noexif,
-           "nogifsetversion" => \$no_gif_set_version);
+           "nogifsetversion" => \$no_gif_set_version,
+          'coverage' => \$coverage);
 
 if ($VERBOSE) { 
   print "Verbose mode\n"; 
 
 if ($VERBOSE) { 
   print "Verbose mode\n"; 
@@ -174,6 +176,16 @@ my %opts=(
          PREREQ_PM      => { 'Test::More' => 0.47 },
          );
 
          PREREQ_PM      => { 'Test::More' => 0.47 },
          );
 
+if ($coverage) {
+    if ($Config{gccversion}) {
+       push @ARGV, 'OPTIMIZE=-ftest-coverage -fprofile-arcs';
+       #$opts{dynamic_lib} = { OTHERLDFLAGS => '-ftest-coverage -fprofile-arcs' };
+    }
+    else {
+       die "Don't know the coverage C flags for your compiler\n";
+    }
+}
+
 # eval to prevent warnings about versions with _ in them
 my $MM_ver = eval $ExtUtils::MakeMaker::VERSION;
 if ($MM_ver > 6.06) {
 # eval to prevent warnings about versions with _ in them
 my $MM_ver = eval $ExtUtils::MakeMaker::VERSION;
 if ($MM_ver > 6.06) {
diff --git a/imcover.perl b/imcover.perl
new file mode 100644 (file)
index 0000000..67622ea
--- /dev/null
@@ -0,0 +1,49 @@
+#!perl -w
+use strict;
+use Config;
+use ExtUtils::Manifest 'maniread';
+
+my $make = $Config{make};
+# if there's a way to make with profiling for a recursive build like
+# Imager I don't see how
+if (-f 'Makefile') {
+    system "$make clean";
+}
+system "cover -delete";
+system "perl Makefile.PL --coverage"
+  and die;
+system "$make 'OTHERLDFLAGS=-ftest-coverage -fprofile-arcs'"
+  and die;
+
+system "$make test HARNESS_PERL_SWITCHES=-MDevel::Cover";
+
+# build gcov files
+my $mani = maniread();
+# split by directory
+my %paths;
+for my $filename (keys %$mani) {
+  next unless $filename =~ /\.(xs|c|im)$/;
+  if ($filename =~ m!^(\w+)/(\w+\.\w+)$!) {
+    push @{$paths{$1}}, $2;
+  }
+  else {
+    push @{$paths{''}}, $filename;
+  }
+}
+
+for my $path (keys %paths) {
+  if ($path) {
+    system "cd $path ; gcov @{$paths{$path}} ; cd ..";
+  }
+  else {
+    system "gcov @{$paths{$path}}";
+  }
+  my $dir = $path ? $path : '.';
+  for my $file (@{$paths{$path}}) {
+    system "gcov2perl $dir/$file.gcov";
+  }
+}
+
+my @dbs = "cover_db", map "$_/cover_db", grep $_, keys %paths;
+system "cover @dbs";
+