1 package Test::Valgrind::Action::Test;
8 Test::Valgrind::Action::Test - Test that an analysis didn't generate any error report.
16 our $VERSION = '1.17';
20 This action uses C<Test::Builder> to plan and pass or fail tests according to the reports received.
26 use base qw<Test::Valgrind::Action Test::Valgrind::Action::Captor>;
30 This class inherits L<Test::Valgrind::Action> and L<Test::Valgrind::Action::Captor>.
34 my $tvat = Test::Valgrind::Action::Test->new(
36 extra_tests => $extra_tests,
40 Your usual constructor.
42 When C<$diag> is true, the original output of the command and the error reports are intermixed as diagnostics.
44 C<$extra_tests> specifies how many extraneous tests you want to plan in addition to the default ones.
46 Other arguments are passed straight to C<< Test::Valgrind::Action->new >>.
52 $class = ref($class) || $class;
56 my $diag = delete $args{diag};
57 my $extra_tests = delete $args{extra_tests} || 0;
59 my $self = bless $class->SUPER::new(%args), $class;
61 $self->{diag} = $diag;
62 $self->{extra_tests} = $extra_tests;
69 my $diag = $tvat->diag;
71 Read-only accessor for the C<diag> option.
75 sub diag { $_[0]->{diag} }
79 my @kinds = $tvat->kinds;
81 Returns the list of all the monitored report kinds.
85 sub kinds { @{$_[0]->{kinds} || []} }
88 my ($self, $sess) = @_;
90 $self->SUPER::start($sess);
92 my @kinds = grep $_ ne 'Diag', $sess->report_class->kinds;
93 $self->{kinds} = \@kinds;
96 my $tb = Test::Builder->new;
98 $tb->plan(tests => $self->{extra_tests} + scalar @kinds);
100 $self->restore_all_fh;
102 delete $self->{capture};
105 $self->{capture} = File::Temp::tempfile();
106 $self->{capture_pos} = 0;
109 $self->save_fh(\*STDOUT => '>' => $self->{capture});
110 $self->save_fh(\*STDERR => '>' => $self->{capture});
116 my ($self, $sess, $msg) = @_;
118 $self->restore_all_fh;
120 my $tb = Test::Builder->new;
121 my $plan = $tb->has_plan;
124 $self->{status} = 255;
134 my ($self, $sess, $report) = @_;
136 if ($report->is_diag) {
137 my $tb = Test::Builder->new;
138 $tb->diag($report->data);
142 $self->SUPER::report($sess, $report);
144 $self->{reports}->{$report->kind}->{$report->id} = $report;
147 my $tb = Test::Builder->new;
148 my $fh = $self->{capture};
149 seek $fh, $self->{capture_pos}, 0;
150 $tb->diag($_) while <$fh>;
151 $self->{capture_pos} = tell $fh;
152 $tb->diag($report->dump);
159 my ($self, $sess) = @_;
161 $self->SUPER::finish($sess);
163 my $tb = Test::Builder->new;
165 $self->restore_all_fh;
167 if (my $fh = $self->{capture}) {
168 seek $fh, $self->{capture_pos}, 0;
169 $tb->diag($_) while <$fh>;
170 close $fh or $self->_croak('close(capture[' . fileno($fh) . "]): $!");
171 delete @{$self}{qw<capture capture_pos>};
176 for my $kind ($self->kinds) {
177 my $reports = $self->{reports}->{$kind} || { };
178 my $errors = keys %$reports;
179 $tb->is_num($errors, 0, $kind);
182 unless ($self->diag) {
183 $tb->diag("\n" . $_->dump) for values %$reports;
188 $self->{status} = $failed < 255 ? $failed : 254;
194 my ($self, $sess) = @_;
196 $self->SUPER::status($sess);
203 L<Test::Valgrind>, L<Test::Valgrind::Action>.
207 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
209 You can contact me by mail or on C<irc.perl.org> (vincent).
213 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>.
214 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
218 You can find documentation for this module with the perldoc command.
220 perldoc Test::Valgrind::Action::Test
222 =head1 COPYRIGHT & LICENSE
224 Copyright 2009,2010,2011,2013,2015 Vincent Pit, all rights reserved.
226 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
230 1; # End of Test::Valgrind::Action::Test