# From the command-line
perl -MTest::Valgrind leaky.pl
+ # From the command-line, snippet style
+ perl -MTest::Valgrind -e 'leaky()'
+
# In a test file
use Test::More;
eval 'use Test::Valgrind';
plan skip_all => 'Test::Valgrind is required to test your distribution with valgrind' if $@;
- ...
+ leaky();
# In all the test files of a directory
prove --exec 'perl -Iblib/lib -Iblib/arch -MTest::Valgrind' t/*.t
my $file = delete $args{file};
unless (defined $file) {
- my ($pm, $next);
- my $l = 0;
- while ($l < 1000) {
- $next = (caller $l++)[1];
+ my ($next, $last_pm);
+ for (my $l = 0; 1; ++$l) {
+ $next = (caller $l)[1];
last unless defined $next;
- next if $next eq '-e'
- or $next =~ /^\s*\(\s*eval\s*\d*\s*\)\s*$/
- or !-f $next;
- if ($next =~ /\.pm$/) {
- $pm = $next;
+ next if $next =~ /^\s*\(\s*eval\s*\d*\s*\)\s*$/;
+ if ($next =~ /\.pmc?$/) {
+ $last_pm = $next;
} else {
$file = $next;
+ last;
}
}
- unless (defined($file) or defined($file = $pm)) {
- require Test::Builder;
- Test::Builder->new->diag('Couldn\'t find a valid source file');
- return;
- }
+ $file = $last_pm unless defined $file;
+ }
+
+ unless (defined $file) {
+ require Test::Builder;
+ Test::Builder->new->diag('Couldn\'t find a valid source file');
+ return;
}
- exit $class->analyse(
- file => $file,
- %args,
- );
+ if ($file ne '-e') {
+ exit $class->analyse(
+ file => $file,
+ %args,
+ );
+ }
+
+ require File::Temp;
+ my $tmp = File::Temp->new;
+
+ require Filter::Util::Call;
+ Filter::Util::Call::filter_add(sub {
+ my $status = Filter::Util::Call::filter_read();
+ if ($status > 0) {
+ print $tmp $_;
+ } elsif ($status == 0) {
+ close $tmp;
+ my $code = $class->analyse(
+ file => $tmp->filename,
+ %args,
+ );
+ exit $code;
+ }
+ $status;
+ });
}
END {
=head1 CAVEATS
-You can't use this module to test code given by the C<-e> command-line switch.
-
Perl 5.8 is notorious for leaking like there's no tomorrow, so the suppressions are very likely not to be very accurate on it. Anyhow, results will most likely be better if your perl is built with debugging enabled. Using the latest C<valgrind> available will also help.
This module is not really secure. It's definitely not taint safe. That shouldn't be a problem for test files.