From: Vincent Pit Date: Thu, 16 Apr 2009 15:45:34 +0000 (+0200) Subject: Move the duplicate suppressions removal from the tool to the action X-Git-Tag: v1.02~12 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=38a501a5b07a91a8ff1d83581d570fae588282a6;p=perl%2Fmodules%2FTest-Valgrind.git Move the duplicate suppressions removal from the tool to the action --- diff --git a/lib/Test/Valgrind/Action/Suppressions.pm b/lib/Test/Valgrind/Action/Suppressions.pm index 9f4d3fb..859f56e 100644 --- a/lib/Test/Valgrind/Action/Suppressions.pm +++ b/lib/Test/Valgrind/Action/Suppressions.pm @@ -82,28 +82,7 @@ sub start { $self->SUPER::start($sess); - $self->{status} = undef; - $self->{total} = 0; - delete $self->{diagnostics}; - - if ($self->{fh}) { - close $self->{fh} or $self->_croak("close(\$self->{fh}): $!"); - } - - my $target = $self->target; - - require File::Spec; - my ($vol, $dir, $file) = File::Spec->splitpath($target); - my $base = File::Spec->catpath($vol, $dir, ''); - unless (-e $base) { - require File::Path; - File::Path::mkpath([ $base ]); - } else { - 1 while unlink $target; - } - - open $self->{fh}, '>', $target - or $self->_croak("open(\$self->{fh}, '>', \$self->target): $!"); + delete @{$self}{qw/status supps diagnostics/}; $self->save_fh(\*STDOUT => '>' => undef); $self->save_fh(\*STDERR => '>' => undef); @@ -136,12 +115,7 @@ sub report { $self->SUPER::report($sess, $report); - ++$self->{total}; - - print { $self->{fh} } "{\n" - . $self->name . $report->id . "\n" - . $report->data - . "}\n"; + push @{$self->{supps}}, $report; return; } @@ -153,11 +127,36 @@ sub finish { $self->restore_all_fh; - close $self->{fh} or $self->_croak("close(\$self->{fh}): $!"); - print $self->{diagnostics} if defined $self->{diagnostics}; delete $self->{diagnostics}; - print "Found $self->{total} distinct suppressions\n"; + + my $target = $self->target; + + require File::Spec; + my ($vol, $dir, $file) = File::Spec->splitpath($target); + my $base = File::Spec->catpath($vol, $dir, ''); + unless (-e $base) { + require File::Path; + File::Path::mkpath([ $base ]); + } else { + 1 while unlink $target; + } + + open my $fh, '>', $target + or $self->_croak("open(\$fh, '>', \$self->target): $!"); + + my (%seen, $id); + for (sort { $a->data cmp $b->data } + grep !$seen{$_->data}++, @{$self->{supps}}) { + print $fh "{\n" + . $self->name . ++$id . "\n" + . $_->data + . "}\n"; + } + + close $fh or $self->_croak("close(\$fh): $!"); + + print "Found $id distinct suppressions\n"; $self->{status} = 0; diff --git a/lib/Test/Valgrind/Tool/SuppressionsParser.pm b/lib/Test/Valgrind/Tool/SuppressionsParser.pm index 6444326..b19a7c6 100644 --- a/lib/Test/Valgrind/Tool/SuppressionsParser.pm +++ b/lib/Test/Valgrind/Tool/SuppressionsParser.pm @@ -104,16 +104,12 @@ sub parse_suppressions { } } - my %dupes; - @dupes{@supps, @extra} = (); - @supps = keys %dupes; - my $num; $sess->report($self->report_class($sess)->new( id => ++$num, kind => 'Suppression', data => $_, - )) for @supps; + )) for @supps, @extra; } =head1 SEE ALSO