X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2Flib%2FTest%2FValgrind%2FTest%2FAction.pm;h=c56eb038f553ee8c4d402009d6d734c7b575494d;hb=eb5a898c606b10dc7ffd4038ef8fc3690bb22367;hp=0b409400df761198bcd18820e02661d11b1b3196;hpb=b6d864328dca14ce16a994f974546a76a7097665;p=perl%2Fmodules%2FTest-Valgrind.git diff --git a/t/lib/Test/Valgrind/Test/Action.pm b/t/lib/Test/Valgrind/Test/Action.pm index 0b40940..c56eb03 100644 --- a/t/lib/Test/Valgrind/Test/Action.pm +++ b/t/lib/Test/Valgrind/Test/Action.pm @@ -3,7 +3,7 @@ package Test::Valgrind::Test::Action; use strict; use warnings; -use base qw/Test::Valgrind::Action::Test/; +use base qw; my $extra_tests; @@ -16,7 +16,7 @@ BEGIN { if ($@) { $extra_tests = 0; } else { - $extra_tests = 2; + $extra_tests = 3; *report = *report_smart; } } @@ -25,17 +25,27 @@ use Test::Builder; sub new { shift->SUPER::new(extra_tests => $extra_tests) } +my @filtered_reports; + sub report_smart { my ($self, $sess, $report) = @_; if ($report->can('is_leak') and $report->is_leak) { my $data = $report->data; - my $trace = join ' ', map { $_->[2] } @{$data->{stack} || []}[0 .. 2]; - if ($trace eq 'malloc XS_Test__Valgrind_leak Perl_pp_entersub') { - my $tb = Test::Builder->new; - $tb->diag("The subsequent report was correctly caught:\n" . $report->dump); - $tb->is_eq($data->{leakedbytes}, 10_000, '10_000 bytes leaked'); - $tb->is_eq($data->{leakedblocks}, 1, ' in one block'); + my @trace = map $_->[2] || '?', + @{$data->{stack} || []}[0 .. 3]; + my $valid_trace = ( + $trace[0] eq 'malloc' + and $trace[1] eq 'tv_leak' + and ($trace[2] eq 'Perl_pp_entersub' or $trace[3] eq 'Perl_pp_entersub') + ); + + if ($valid_trace) { + push @filtered_reports, [ + $report->dump, + $data->{leakedbytes}, + $data->{leakedblocks}, + ]; return; } } @@ -43,4 +53,28 @@ sub report_smart { $self->SUPER::report($sess, $report); } +sub DESTROY { + return unless $extra_tests; + + my $tb = Test::Builder->new; + + $tb->is_eq(scalar(@filtered_reports), 1, 'caught one extra leak'); + + if (@filtered_reports) { + my $first = shift @filtered_reports; + $tb->diag("The subsequent report was correctly caught:\n" . $first->[0]); + $tb->is_eq($first->[1], 10_000, '10_000 bytes leaked'); + $tb->is_eq($first->[2], 1, ' in one block'); + + for my $extra_report (@filtered_reports) { + $tb->diag( + "The subsequent report should NOT have been caught:\n" . $extra_report->[0] + ); + } + } else { + $tb->ok(0, 'no extra leak caught, hence no bytes leaked'); + $tb->ok(0, 'no extra leak caught, hence no block leaked'); + } +} + 1;