]> git.vpit.fr Git - perl/modules/Test-Valgrind.git/blobdiff - lib/Test/Valgrind.pm
Importing Test-Valgrind-0.02.tar.gz
[perl/modules/Test-Valgrind.git] / lib / Test / Valgrind.pm
index 647cde94f088f4419d454caf5694c0bb3597c227..b4ce02226566ccf6e2bffeb157338ff315f86989 100644 (file)
@@ -7,25 +7,27 @@ use Carp qw/croak/;
 use POSIX qw/SIGTERM/;
 use Test::More;
 
+use Perl::Destruct::Level level => 3;
+
 use Test::Valgrind::Suppressions;
 
 =head1 NAME
 
-Test::Valgrind - Test your code through valgrind.
+Test::Valgrind - Test Perl code through valgrind.
 
 =head1 VERSION
 
-Version 0.01
+Version 0.02
 
 =cut
 
-our $VERSION = '0.01';
+our $VERSION = '0.02';
 
 =head1 SYNOPSIS
 
     use Test::More;
     eval 'use Test::Valgrind';
-    plan skip_all => 'Test::Valgrind is required to test your distribution with valgrind';
+    plan skip_all => 'Test::Valgrind is required to test your distribution with valgrind' if $@;
 
     # Code to inspect for memory leaks/errors.
 
@@ -33,6 +35,10 @@ our $VERSION = '0.01';
 
 This module lets you run some code through the B<valgrind> memory debugger, to test it for memory errors and leaks. Just add C<use Test::Valgrind> at the beginning of the code you want to test. Behind the hood, C<Test::Valgrind::import> forks so that the child can basically C<exec 'valgrind', $^X, $0> (except that of course C<$0> isn't right there). The parent then parses the report output by valgrind and pass or fail tests accordingly.
 
+You can also use it from the command-line to test a given script :
+
+    perl -MTest::Valgrind leaky.pl
+
 =head1 CONFIGURATION
 
 You can pass parameters to C<import> as a list of key / value pairs, where valid keys are :
@@ -112,7 +118,7 @@ sub import {
     '--error-limit=yes'
    );
    unless ($args{no_supp}) {
-    for (Test::Valgrind::Suppressions::supppath(), $args{supp}) {
+    for (Test::Valgrind::Suppressions::supp_path(), $args{supp}) {
      push @args, '--suppressions=' . $_ if $_;
     }
    }
@@ -125,7 +131,8 @@ sub import {
    print STDERR "valgrind @args\n" if $args{diag};
    local $ENV{PERL_DESTRUCT_LEVEL} = 3;
    local $ENV{PERL_DL_NONLAZY} = 1;
-   exec 'valgrind', @args;
+   my $vg = Test::Valgrind::Suppressions::VG_PATH;
+   exec $vg, @args if $vg and -x $vg;
   }
   close $wtr or croak "close(\$wtr): $!";
   local $SIG{INT} = sub { kill -(SIGTERM) => $pid };
@@ -168,8 +175,12 @@ sub import {
 =head1 CAVEATS
 
 You can't use this module to test code given by the C<-e> command-line switch.
+
+Results will most likely be better if your perl is built with debugging enabled. Using the latest 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.
-If your tests output to STDERR, everything will be eaten in the process.
+
+If your tests output to STDERR, everything will be eaten in the process. In particular, running this module against test files will obliterate their original test results.
 
 =head1 DEPENDENCIES
 
@@ -177,6 +188,8 @@ Valgrind 3.1.0 (L<http://valgrind.org>).
 
 L<Carp>, L<POSIX> (core modules since perl 5) and L<Test::More> (since 5.6.2).
 
+L<Perl::Destruct::Level>.
+
 =head1 AUTHOR
 
 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
@@ -193,12 +206,17 @@ You can find documentation for this module with the perldoc command.
 
     perldoc Test::Valgrind
 
+=head1 ACKNOWLEDGEMENTS
+
+RafaĆ«l Garcia-Suarez, for writing and instructing me about the existence of L<Perl::Destruct::Level> (Elizabeth Mattijsen is a close second).
+
+H.Merijn Brand, for daring to test this thing.
+
 =head1 COPYRIGHT & LICENSE
 
 Copyright 2008 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.
+This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
 
 =cut