1 package Test::Valgrind::Action::Suppressions;
8 Test::Valgrind::Action::Suppressions - Generate suppressions for a given tool.
16 our $VERSION = '1.16';
20 This action just writes the contents of the suppressions reports received into the suppression file.
24 use base qw<Test::Valgrind::Action Test::Valgrind::Action::Captor>;
28 This class inherits L<Test::Valgrind::Action>.
32 my $tvas = Test::Valgrind::Action::Suppressions->new(
38 Your usual constructor.
40 You need to specify the suppression prefix as the value of C<name>, and the target file as C<target>.
42 Other arguments are passed straight to C<< Test::Valgrind::Action->new >>.
48 $class = ref($class) || $class;
54 for (qw<name target>) {
55 my $arg = delete $args{$_};
56 $class->_croak("'$_' is expected to be a plain scalar")
57 unless $arg and not ref $arg;
58 $validated{$_} = $arg;
61 my $self = $class->SUPER::new(%args);
63 $self->{$_} = $validated{$_} for qw<name target>;
68 sub do_suppressions { 1 }
72 my $name = $tvas->name;
74 Read-only accessor for the C<name> option.
78 sub name { $_[0]->{name} }
82 my $target = $tvas->target;
84 Read-only accessor for the C<target> option.
88 sub target { $_[0]->{target} }
91 my ($self, $sess) = @_;
93 $self->SUPER::start($sess);
95 delete @{$self}{qw<status supps diagnostics>};
97 $self->save_fh(\*STDOUT => '>' => undef);
98 $self->save_fh(\*STDERR => '>' => undef);
106 $self->restore_all_fh;
108 print $self->{diagnostics} if defined $self->{diagnostics};
109 delete $self->{diagnostics};
111 $self->{status} = 255;
113 $self->SUPER::abort(@_);
117 my ($self, $sess, $report) = @_;
119 if ($report->is_diag) {
120 my $data = $report->data;
122 $self->{diagnostics} .= "$data\n";
126 $self->SUPER::report($sess, $report);
128 push @{$self->{supps}}, $report;
134 my ($self, $sess) = @_;
136 $self->SUPER::finish($sess);
138 $self->restore_all_fh;
140 print $self->{diagnostics} if defined $self->{diagnostics};
141 delete $self->{diagnostics};
143 my $target = $self->target;
146 my ($vol, $dir, $file) = File::Spec->splitpath($target);
147 my $base = File::Spec->catpath($vol, $dir, '');
149 1 while unlink $target;
152 File::Path::mkpath([ $base ]);
155 open my $fh, '>', $target
156 or $self->_croak("open(\$fh, '>', \$self->target): $!");
160 for (sort { $a->data cmp $b->data }
161 grep !$seen{$_->data}++, @{$self->{supps}}) {
163 . $self->name . ++$id . "\n"
168 close $fh or $self->_croak("close(\$fh): $!");
170 print "Found $id distinct suppressions\n";
177 sub status { $_[0]->{status} }
181 L<Test::Valgrind>, L<Test::Valgrind::Action>.
185 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
187 You can contact me by mail or on C<irc.perl.org> (vincent).
191 Please report any bugs or feature requests to C<bug-test-valgrind at rt.cpan.org>, or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Valgrind>.
192 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
196 You can find documentation for this module with the perldoc command.
198 perldoc Test::Valgrind::Action::Suppressions
200 =head1 COPYRIGHT & LICENSE
202 Copyright 2009,2010,2011,2013,2015 Vincent Pit, all rights reserved.
204 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
208 1; # End of Test::Valgrind::Action::Supressions