1 package Test::Valgrind::Command::Perl;
8 Test::Valgrind::Command::Perl - A Test::Valgrind command that invokes perl.
16 our $VERSION = '1.12';
20 This command is the base for all C<perl>-based commands.
21 It handles the suppression generation and sets the main command-line flags.
27 use Test::Valgrind::Suppressions;
29 use base qw<Test::Valgrind::Command Test::Valgrind::Carp>;
33 This class inherits L<Test::Valgrind::Command>.
35 =head2 C<< new perl => $^X, inc => \@INC, taint_mode => $taint_mode, ... >>
37 The package constructor, which takes several options :
43 The C<perl> option specifies which C<perl> executable will run the arugment list given in C<args>.
49 C<inc> is a reference to an array of paths that will be passed as C<-I> to the invoked command.
55 C<$taint_mode> is a boolean that specifies if the script should be run under taint mode.
61 Other arguments are passed straight to C<< Test::Valgrind::Command->new >>.
67 $class = ref($class) || $class;
71 my $perl = delete $args{perl} || $^X;
72 my $inc = delete $args{inc} || [ @INC ];
73 $class->_croak('Invalid INC list') unless ref $inc eq 'ARRAY';
74 my $taint_mode = delete $args{taint_mode};
76 my $trainer_file = delete $args{trainer_file};
78 my $self = bless $class->SUPER::new(%args), $class;
80 $self->{perl} = $perl;
82 $self->{taint_mode} = $taint_mode;
84 $self->{trainer_file} = $trainer_file;
93 my ($fh, $file) = File::Temp::tempfile(UNLINK => 0);
95 my $curpos = tell DATA;
96 print $fh $_ while <DATA>;
97 seek DATA, $curpos, 0;
99 close $fh or $self->_croak("close(tempscript): $!");
102 args => [ '-MTest::Valgrind=run,1', $file ],
103 trainer_file => $file,
110 Read-only accessor for the C<perl> option.
114 sub perl { $_[0]->{perl} }
118 Read-only accessor for the C<inc> option.
122 sub inc { @{$_[0]->{inc} || []} }
126 Read-only accessor for the C<taint_mode> option.
130 sub taint_mode { $_[0]->{taint_mode} }
136 (('-T') x!! $self->taint_mode),
137 map("-I$_", $self->inc),
138 $self->SUPER::args(@_);
141 =head2 C<env $session>
143 Returns an L<Env::Sanctify> object that sets the environment variables C<PERL_DESTRUCT_LEVEL> to C<3> and C<PERL_DL_NONLAZY> to C<1> during the run.
148 Env::Sanctify->sanctify(
150 PERL_DESTRUCT_LEVEL => 3,
151 PERL_DL_NONLAZY => 1,
156 sub suppressions_tag {
159 unless (defined $self->{suppressions_tag}) {
160 my $env = Env::Sanctify->sanctify(sanctify => [ qr/^PERL/ ]);
162 open my $pipe, '-|', $self->perl, '-V'
163 or $self->_croak('open("-| ' . $self->perl . " -V\"): $!");
164 my $perl_v = do { local $/; <$pipe> };
165 close $pipe or $self->_croak('close("-| ' . $self->perl . " -V\"): $!");
168 $self->{suppressions_tag} = Digest::MD5::md5_hex($perl_v);
171 return $self->{suppressions_tag};
175 my ($self, $session, $report) = @_;
177 return $report if $report->is_diag
178 or not $report->isa('Test::Valgrind::Report::Suppressions');
180 my $data = $report->data;
181 $data =~ s/[^\r\n]*\bPerl_runops_(?:standard|debug)\b.*//s;
182 $data = Test::Valgrind::Suppressions->strip_tail($session, $data);
186 kind => $report->kind,
194 my $file = $self->{trainer_file};
195 return unless $file and -e $file;
197 1 while unlink $file;
204 L<Test::Valgrind>, L<Test::Valgrind::Command>.
210 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
212 You can contact me by mail or on C<irc.perl.org> (vincent).
216 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>.
217 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
221 You can find documentation for this module with the perldoc command.
223 perldoc Test::Valgrind::Command::Perl
225 =head1 COPYRIGHT & LICENSE
227 Copyright 2009,2010,2011 Vincent Pit, all rights reserved.
229 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
233 1; # End of Test::Valgrind::Command::Perl
239 BEGIN { require Test::Valgrind; }
245 XSLoader::load('Test::Valgrind', $Test::Valgrind::VERSION);
249 Test::Valgrind::notleak("valgrind it!");
252 *Test::Valgrind::DEBUGGING = sub { 'unknown' };
256 fail 'should not be seen';
257 diag 'debbugging flag is ' . Test::Valgrind::DEBUGGING();
261 XSLoader::load('Test::Valgrind::Fake', 0);
264 diag $@ ? 'Ok' : 'Succeeded to load Test::Valgrind::Fake but should\'t';
268 my @cards = List::Util::shuffle(0 .. 51);
271 package Test::Valgrind::Test::Fake;
276 eval 'use Time::HiRes qw<usleep>';