[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[lintian] 02/02: Improve Devel::Cover support



This is an automated email from the git hooks/post-receive script.

nthykier pushed a commit to branch master
in repository lintian.

commit bbcfb60771b94140a96748c2652fd9d25b4bc6ce
Author: Niels Thykier <niels@thykier.net>
Date:   Sun Feb 7 11:23:18 2016 +0000

    Improve Devel::Cover support
    
    Signed-off-by: Niels Thykier <niels@thykier.net>
---
 checks/manpages.pm      |  2 +-
 frontend/dplint         |  6 ++++++
 lib/Lintian/Unpacker.pm |  5 +++++
 t/runtests              | 26 +++++++++++++++++++++-----
 4 files changed, 33 insertions(+), 6 deletions(-)

diff --git a/checks/manpages.pm b/checks/manpages.pm
index c58f7f0..f8267bb 100644
--- a/checks/manpages.pm
+++ b/checks/manpages.pm
@@ -23,7 +23,7 @@ use strict;
 use warnings;
 use autodie;
 
-use constant LINTIAN_COVERAGE => ($ENV{'LINTIAN_COVERAGE'}//0);
+use constant LINTIAN_COVERAGE => ($ENV{'LINTIAN_COVERAGE'}?1:0);
 
 use File::Basename;
 use List::MoreUtils qw(any none);
diff --git a/frontend/dplint b/frontend/dplint
index fda7eb5..db6d193 100755
--- a/frontend/dplint
+++ b/frontend/dplint
@@ -146,6 +146,12 @@ sub setup_env {
     $ENV{'LINTIAN_DPLINT_CALLED_AS'} = $0;
     $ENV{'LINTIAN_DPLINT_FRONTEND'} = realpath($0)
       // error("Cannot resolve $0: $!");
+
+    if (my $coverage_arg = $ENV{'LINTIAN_COVERAGE'}) {
+        my $p5opt = $ENV{'PERL5OPT'}//q{};
+        $p5opt .= ' ' if $p5opt ne q{};
+        $ENV{'PERL5OPT'} = "${p5opt} ${coverage_arg}";
+    }
     return;
 }
 
diff --git a/lib/Lintian/Unpacker.pm b/lib/Lintian/Unpacker.pm
index dd0e3d4..7df337d 100644
--- a/lib/Lintian/Unpacker.pm
+++ b/lib/Lintian/Unpacker.pm
@@ -454,6 +454,11 @@ sub process_tasks {
                             $ret = 2;
                         }
                     } else {
+                        if (my $coverage_arg = $ENV{'LINTIAN_COVERAGE'}) {
+                            my $p5opt = $ENV{'PERL5OPT'}//q{};
+                            $p5opt .= ' ' if $p5opt ne q{};
+                            $ENV{'PERL5OPT'} = "${p5opt} ${coverage_arg}";
+                        }
                         # Its fork + exec - invoke that directly (saves a fork)
                         exec $cs->script_path, $pkg_name, $pkg_type, $base
                           or die "exec $cs->script_path: $!";
diff --git a/t/runtests b/t/runtests
index 7b02c54..fe11aa8 100755
--- a/t/runtests
+++ b/t/runtests
@@ -41,7 +41,7 @@ use List::MoreUtils qw(none);
 
 use constant SUITES => qw(scripts changes debs source tests);
 
-our ($LINTIAN_ROOT, $LINTIAN, @LINTIAN_CMD);
+our ($LINTIAN_ROOT, $LINTIAN, @LINTIAN_CMD, @LINTIAN_COMMON_OPTIONS);
 
 BEGIN {
     # Whitelist the part of the environment we permit.  This is to
@@ -246,12 +246,15 @@ sub parse_args {
         my @criteria = qw(statement branch condition path subroutine);
         my $coverage_arg
           = '-MDevel::Cover=-silent,1,+ignore,^(.*/)?t/scripts/.+';
+        $coverage_arg .= ',+ignore,/usr/bin/.*,+ignore,(.*/)?Dpkg';
         $coverage_arg .= ',-coverage,' . join(',-coverage,', @criteria);
         $coverage_arg .= ',' . $coverage if $coverage ne '';
-        $ENV{'LINTIAN_COVERAGE'} = 1;
+        $ENV{'LINTIAN_COVERAGE'} = $coverage_arg;
         $harness_perl_switches .= ' ' . $coverage_arg;
         $ENV{'HARNESS_PERL_SWITCHES'} = $harness_perl_switches;
-        unshift(@LINTIAN_CMD, 'perl', $coverage_arg);
+        # Coverage has some race conditions (at least when using the same
+        # cover database).
+        push(@LINTIAN_COMMON_OPTIONS, '-j1');
     }
 
     # Getopt::Long assigns 0 as default value if none was specified
@@ -479,8 +482,16 @@ sub run_lintian {
             close($fd);
         }
     } else {
+        my @cmd = @LINTIAN_CMD;
+        if ($ENV{'LINTIAN_COVERAGE'}) {
+            my $suite = $testdata->{suite};
+            my $name = $testdata->{testname};
+            my $cover_dir = "./cover_db-${suite}-${name}";
+            $ENV{'LINTIAN_COVERAGE'} .= ",-db,${cover_dir}";
+            unshift(@cmd, 'perl', $ENV{'LINTIAN_COVERAGE'});
+        }
         open(STDERR, '>&', \*STDOUT);
-        exec {$LINTIAN_CMD[0]} @LINTIAN_CMD, @options, $file
+        exec @cmd, @options, @LINTIAN_COMMON_OPTIONS, $file
           or fail "exec failed: $!";
     }
     return 1;
@@ -686,7 +697,12 @@ sub run_prove_tests {
         @do_run = ("$TESTSET/scripts");
     }
     if (@do_run) {
-        my @prove_cmd= ('prove', '-j', $JOBS, '-r', '-I', "$LINTIAN_ROOT/lib");
+        my $jobs = $JOBS;
+        # Devel::Cover + one cover_db + multiple processes is a recipe
+        # for corruptions.  Force $jobs to 1 if we are running under
+        # coverage.
+        $jobs = 1 if $ENV{'LINTIAN_COVERAGE'};
+        my @prove_cmd= ('prove', '-j', $jobs, '-r', '-I', "$LINTIAN_ROOT/lib");
 
         print "Test scripts:\n";
         if (system(@prove_cmd, @do_run) != 0) {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/lintian/lintian.git


Reply to: