/usr/share/perl5/Test/Valgrind/Action/Test.pm is in libtest-valgrind-perl 1.19-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | package Test::Valgrind::Action::Test;
use strict;
use warnings;
=head1 NAME
Test::Valgrind::Action::Test - Test that an analysis didn't generate any error report.
=head1 VERSION
Version 1.19
=cut
our $VERSION = '1.19';
=head1 DESCRIPTION
This action uses C<Test::Builder> to plan and pass or fail tests according to the reports received.
=cut
use Test::Builder;
use base qw<Test::Valgrind::Action Test::Valgrind::Action::Captor>;
=head1 METHODS
This class inherits L<Test::Valgrind::Action> and L<Test::Valgrind::Action::Captor>.
=head2 C<new>
my $tvat = Test::Valgrind::Action::Test->new(
diag => $diag,
extra_tests => $extra_tests,
%extra_args,
);
Your usual constructor.
When C<$diag> is true, the original output of the command and the error reports are intermixed as diagnostics.
C<$extra_tests> specifies how many extraneous tests you want to plan in addition to the default ones.
Other arguments are passed straight to C<< Test::Valgrind::Action->new >>.
=cut
sub new {
my $class = shift;
$class = ref($class) || $class;
my %args = @_;
my $diag = delete $args{diag};
my $extra_tests = delete $args{extra_tests} || 0;
my $self = bless $class->SUPER::new(%args), $class;
$self->{diag} = $diag;
$self->{extra_tests} = $extra_tests;
$self;
}
=head2 C<diag>
my $diag = $tvat->diag;
Read-only accessor for the C<diag> option.
=cut
sub diag { $_[0]->{diag} }
=head2 C<kinds>
my @kinds = $tvat->kinds;
Returns the list of all the monitored report kinds.
=cut
sub kinds { @{$_[0]->{kinds} || []} }
sub start {
my ($self, $sess) = @_;
$self->SUPER::start($sess);
my @kinds = grep $_ ne 'Diag', $sess->report_class->kinds;
$self->{kinds} = \@kinds;
$self->{status} = 0;
my $tb = Test::Builder->new;
$tb->plan(tests => $self->{extra_tests} + scalar @kinds);
$self->restore_all_fh;
delete $self->{capture};
if ($self->diag) {
require File::Temp;
$self->{capture} = File::Temp::tempfile();
$self->{capture_pos} = 0;
}
$self->save_fh(\*STDOUT => '>' => $self->{capture});
$self->save_fh(\*STDERR => '>' => $self->{capture});
return;
}
sub abort {
my ($self, $sess, $msg) = @_;
$self->restore_all_fh;
my $tb = Test::Builder->new;
my $plan = $tb->has_plan;
if (defined $plan) {
$tb->BAIL_OUT($msg);
$self->{status} = 255;
} else {
$tb->skip_all($msg);
$self->{status} = 0;
}
return;
}
sub report {
my ($self, $sess, $report) = @_;
if ($report->is_diag) {
my $tb = Test::Builder->new;
$tb->diag($report->data);
return;
}
$self->SUPER::report($sess, $report);
$self->{reports}->{$report->kind}->{$report->id} = $report;
if ($self->diag) {
my $tb = Test::Builder->new;
my $fh = $self->{capture};
seek $fh, $self->{capture_pos}, 0;
$tb->diag($_) while <$fh>;
$self->{capture_pos} = tell $fh;
$tb->diag($report->dump);
}
return;
}
sub finish {
my ($self, $sess) = @_;
$self->SUPER::finish($sess);
my $tb = Test::Builder->new;
$self->restore_all_fh;
if (my $fh = $self->{capture}) {
seek $fh, $self->{capture_pos}, 0;
$tb->diag($_) while <$fh>;
close $fh or $self->_croak('close(capture[' . fileno($fh) . "]): $!");
delete @{$self}{qw<capture capture_pos>};
}
my $failed = 0;
for my $kind ($self->kinds) {
my $reports = $self->{reports}->{$kind} || { };
my $errors = keys %$reports;
$tb->is_num($errors, 0, $kind);
if ($errors) {
++$failed;
unless ($self->diag) {
$tb->diag("\n" . $_->dump) for values %$reports;
}
}
}
$self->{status} = $failed < 255 ? $failed : 254;
return;
}
sub status {
my ($self, $sess) = @_;
$self->SUPER::status($sess);
$self->{status};
}
=head1 SEE ALSO
L<Test::Valgrind>, L<Test::Valgrind::Action>.
=head1 AUTHOR
Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
You can contact me by mail or on C<irc.perl.org> (vincent).
=head1 BUGS
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>.
I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
=head1 SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Test::Valgrind::Action::Test
=head1 COPYRIGHT & LICENSE
Copyright 2009,2010,2011,2013,2015,2016 Vincent Pit, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
=cut
1; # End of Test::Valgrind::Action::Test
|