]> git.vpit.fr Git - perl/modules/Test-Valgrind.git/blobdiff - lib/Test/Valgrind.pm
Log valgrind output to a specific fd so that the output of the script doesn't get...
[perl/modules/Test-Valgrind.git] / lib / Test / Valgrind.pm
index a6561301481845a44c87241ecf75fc39f67dec94..f50edd67eba67a68b166dbc8fb195f6de22b4044 100644 (file)
@@ -5,6 +5,7 @@ use warnings;
 
 use Carp qw/croak/;
 use POSIX qw/SIGTERM/;
+use Fcntl qw/F_SETFD/;
 use Test::Builder;
 
 use Perl::Destruct::Level level => 3;
@@ -146,7 +147,7 @@ sub import {
     }
    }
    if (!$vg) {
-    $Test->plan(skip_all => 'No valgrind executable could be found in your path');
+    $Test->skip_all('No valgrind executable could be found in your path');
     return;
    } 
   }
@@ -157,13 +158,14 @@ sub import {
   } elsif ($pid == 0) {
    setpgrp 0, 0 or croak "setpgrp(0, 0): $!";
    close $rdr or croak "close(\$rdr): $!";
-   open STDERR, '>&', $wtr or croak "open(STDERR, '>&', \$wtr): $!";
+   fcntl $wtr, F_SETFD, 0 or croak "fcntl(\$wtr, F_SETFD, 0): $!";
    my @args = (
     '--tool=memcheck',
     '--leak-check=full',
     '--leak-resolution=high',
     '--num-callers=' . $callers,
-    '--error-limit=yes'
+    '--error-limit=yes',
+    '--log-fd=' . fileno($wtr)
    );
    unless ($args{no_supp}) {
     for (Test::Valgrind::Suppressions::supp_path(), $args{supp}) {
@@ -183,7 +185,7 @@ sub import {
   }
   close $wtr or croak "close(\$wtr): $!";
   local $SIG{INT} = sub { kill -(SIGTERM) => $pid };
-  $Test->plan(tests => 5) unless $args{no_test};
+  $Test->plan(tests => 5) unless $args{no_test} or defined $Test->has_plan;
   my @tests = (
    'errors',
    'definitely lost', 'indirectly lost', 'possibly lost', 'still reachable'
@@ -234,7 +236,7 @@ If your tests output to STDERR, everything will be eaten in the process. In part
 
 Valgrind 3.1.0 (L<http://valgrind.org>).
 
-L<Carp>, L<POSIX> (core modules since perl 5) and L<Test::Builder> (since 5.6.2).
+L<Carp>, L<Fcntl>, L<POSIX> (core modules since perl 5) and L<Test::Builder> (since 5.6.2).
 
 L<Perl::Destruct::Level>.