From: Vincent Pit Date: Sun, 28 Sep 2008 11:52:59 +0000 (+0200) Subject: Capture STDOUT so that its output doesn't mix with our test results X-Git-Tag: v0.07~7 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=a7322910d865380e6ca34f5d7d93942e384e7734;p=perl%2Fmodules%2FTest-Valgrind.git Capture STDOUT so that its output doesn't mix with our test results --- diff --git a/lib/Test/Valgrind.pm b/lib/Test/Valgrind.pm index a676ad0..4c87dec 100644 --- a/lib/Test/Valgrind.pm +++ b/lib/Test/Valgrind.pm @@ -151,21 +151,24 @@ sub import { return; } } - pipe my $rdr, my $wtr or die "pipe(\$rdr, \$wtr): $!"; + pipe my $ordr, my $owtr or die "pipe(\$ordr, \$owtr): $!"; + pipe my $vrdr, my $vwtr or die "pipe(\$vrdr, \$vwtr): $!"; my $pid = fork; if (!defined $pid) { die "fork(): $!"; } elsif ($pid == 0) { setpgrp 0, 0 or die "setpgrp(0, 0): $!"; - close $rdr or die "close(\$rdr): $!"; - fcntl $wtr, F_SETFD, 0 or die "fcntl(\$wtr, F_SETFD, 0): $!"; + close $ordr or die "close(\$ordr): $!"; + open STDOUT, '>&=', $owtr or die "open(STDOUT, '>&=', \$owtr): $!"; + close $vrdr or die "close(\$vrdr): $!"; + fcntl $vwtr, F_SETFD, 0 or die "fcntl(\$vwtr, F_SETFD, 0): $!"; my @args = ( '--tool=memcheck', '--leak-check=full', '--leak-resolution=high', '--num-callers=' . $callers, '--error-limit=yes', - '--log-fd=' . fileno($wtr) + '--log-fd=' . fileno($vwtr) ); unless ($args{no_supp}) { for (Test::Valgrind::Suppressions::supp_path(), $args{supp}) { @@ -178,12 +181,11 @@ sub import { push @args, $^X; push @args, '-I' . $_ for @INC; push @args, '-MTest::Valgrind=run,1', $file; - print STDERR "valgrind @args\n" if $args{diag}; + print STDOUT "valgrind @args\n"; local $ENV{PERL_DESTRUCT_LEVEL} = 3; local $ENV{PERL_DL_NONLAZY} = 1; exec $vg, @args; } - close $wtr or die "close(\$wtr): $!"; local $SIG{INT} = sub { kill -(SIGTERM) => $pid }; $Test->plan(tests => 5) unless $args{no_test} or defined $Test->has_plan; my @tests = ( @@ -191,7 +193,11 @@ sub import { 'definitely lost', 'indirectly lost', 'possibly lost', 'still reachable' ); my %res = map { $_ => 0 } @tests; - while (<$rdr>) { + close $owtr or die "close(\$owtr): $!"; + $Test->diag(do { local $/; <$ordr> }) if $args{diag}; + close $ordr or die "close(\$ordr): $!"; + close $vwtr or die "close(\$vwtr): $!"; + while (<$vrdr>) { $Test->diag($_) if $args{diag}; if (/^=+\d+=+\s*FATAL\s*:\s*(.*)/) { chomp(my $err = $1); diff --git a/t/20-good.t b/t/20-good.t index 510a0a3..4c31222 100644 --- a/t/20-good.t +++ b/t/20-good.t @@ -11,4 +11,5 @@ if ($@) { plan skip_all => 'Test::Valgrind is required to run test your distribution with valgrind'; } -1; +plan tests => 1; +fail('shouldn\'t see this'); diff --git a/t/21-good-block.t b/t/21-good-block.t index 272ea53..22d3c47 100644 --- a/t/21-good-block.t +++ b/t/21-good-block.t @@ -11,4 +11,5 @@ if ($@) { plan skip_all => 'Test::Valgrind is required to run test your distribution with valgrind'; } -1; +plan tests => 1; +fail('shouldn\'t see this');