From: Vincent Pit Date: Fri, 30 Oct 2015 14:48:37 +0000 (-0200) Subject: Improve diagnostics when t/20-bad.t fails X-Git-Tag: v1.15~10 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=eb5a898c606b10dc7ffd4038ef8fc3690bb22367;p=perl%2Fmodules%2FTest-Valgrind.git Improve diagnostics when t/20-bad.t fails In particular, make sure it always passes/fails the right number of tests. --- diff --git a/t/lib/Test/Valgrind/Test/Action.pm b/t/lib/Test/Valgrind/Test/Action.pm index 369a921..c56eb03 100644 --- a/t/lib/Test/Valgrind/Test/Action.pm +++ b/t/lib/Test/Valgrind/Test/Action.pm @@ -16,7 +16,7 @@ BEGIN { if ($@) { $extra_tests = 0; } else { - $extra_tests = 2; + $extra_tests = 3; *report = *report_smart; } } @@ -25,6 +25,8 @@ use Test::Builder; sub new { shift->SUPER::new(extra_tests => $extra_tests) } +my @filtered_reports; + sub report_smart { my ($self, $sess, $report) = @_; @@ -39,10 +41,11 @@ sub report_smart { ); if ($valid_trace) { - 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'); + push @filtered_reports, [ + $report->dump, + $data->{leakedbytes}, + $data->{leakedblocks}, + ]; return; } } @@ -50,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;