1 package Test::Valgrind::Command::Perl;
8 Test::Valgrind::Command::Perl - A Test::Valgrind command that invokes perl.
16 our $VERSION = '1.11';
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 base qw/Test::Valgrind::Command Test::Valgrind::Carp/;
31 This class inherits L<Test::Valgrind::Command>.
33 =head2 C<< new perl => $^X, inc => \@INC, taint_mode => $taint_mode, ... >>
35 The package constructor, which takes several options :
41 The C<perl> option specifies which C<perl> executable will run the arugment list given in C<args>.
47 C<inc> is a reference to an array of paths that will be passed as C<-I> to the invoked command.
53 C<$taint_mode> is a boolean that specifies if the script should be run under taint mode.
59 Other arguments are passed straight to C<< Test::Valgrind::Command->new >>.
65 $class = ref($class) || $class;
69 my $perl = delete $args{perl} || $^X;
70 my $inc = delete $args{inc} || [ @INC ];
71 $class->_croak('Invalid INC list') unless ref $inc eq 'ARRAY';
72 my $taint_mode = delete $args{taint_mode};
74 my $trainer_file = delete $args{trainer_file};
76 my $self = bless $class->SUPER::new(%args), $class;
78 $self->{perl} = $perl;
80 $self->{taint_mode} = $taint_mode;
82 $self->{trainer_file} = $trainer_file;
91 my ($fh, $file) = File::Temp::tempfile(UNLINK => 0);
93 my $curpos = tell DATA;
94 print $fh $_ while <DATA>;
95 seek DATA, $curpos, 0;
97 close $fh or $self->_croak("close(tempscript): $!");
100 args => [ '-MTest::Valgrind=run,1', $file ],
101 trainer_file => $file,
108 Read-only accessor for the C<perl> option.
112 sub perl { $_[0]->{perl} }
116 Read-only accessor for the C<inc> option.
120 sub inc { @{$_[0]->{inc} || []} }
124 Read-only accessor for the C<taint_mode> option.
128 sub taint_mode { $_[0]->{taint_mode} }
134 (('-T') x!! $self->taint_mode),
135 map("-I$_", $self->inc),
136 $self->SUPER::args(@_);
139 =head2 C<env $session>
141 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.
146 Env::Sanctify->sanctify(
148 PERL_DESTRUCT_LEVEL => 2,
149 PERL_DL_NONLAZY => 1,
154 sub suppressions_tag {
157 unless (defined $self->{suppressions_tag}) {
158 my $env = Env::Sanctify->sanctify(sanctify => [ qr/^PERL/ ]);
160 open my $pipe, '-|', $self->perl, '-V'
161 or $self->_croak('open("-| ' . $self->perl . " -V\"): $!");
162 my $perl_v = do { local $/; <$pipe> };
163 close $pipe or $self->_croak('close("-| ' . $self->perl . " -V\"): $!");
166 $self->{suppressions_tag} = Digest::MD5::md5_hex($perl_v);
169 return $self->{suppressions_tag};
173 my ($self, $session, $report) = @_;
175 return $report if $report->is_diag
176 or not $report->isa('Test::Valgrind::Report::Suppressions');
178 my $data = $report->data;
179 $data =~ s/^[^\r\n]*\bPerl_runops_(?:standard|debug)\b.*//ms;
183 kind => $report->kind,
191 my $file = $self->{trainer_file};
192 return unless $file and -e $file;
194 1 while unlink $file;
201 L<Test::Valgrind>, L<Test::Valgrind::Command>.
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::Command::Perl
222 =head1 COPYRIGHT & LICENSE
224 Copyright 2009 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::Command::Perl
236 BEGIN { require Test::Valgrind; }
242 XSLoader::load('Test::Valgrind', $Test::Valgrind::VERSION);
246 Test::Valgrind::notleak("valgrind it!");
249 *Test::Valgrind::DEBUGGING = sub { 'unknown' };
253 fail 'should not be seen';
254 diag 'debbugging flag is ' . Test::Valgrind::DEBUGGING();
258 XSLoader::load('Test::Valgrind::Fake', 0);
261 diag $@ ? 'Ok' : 'Succeeded to load Test::Valgrind::Fake but should\'t';
265 my @cards = List::Util::shuffle(0 .. 51);
268 package Test::Valgrind::Test::Fake;
273 eval 'use Time::HiRes qw/usleep/';