X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=lib%2FTest%2FValgrind.pm;h=b4ce02226566ccf6e2bffeb157338ff315f86989;hb=8e236cf7f5ac06829edb65527fcdf12716ecd159;hp=647cde94f088f4419d454caf5694c0bb3597c227;hpb=41a4b907f4846f2d35b170f517fb83ceb13f298c;p=perl%2Fmodules%2FTest-Valgrind.git diff --git a/lib/Test/Valgrind.pm b/lib/Test/Valgrind.pm index 647cde9..b4ce022 100644 --- a/lib/Test/Valgrind.pm +++ b/lib/Test/Valgrind.pm @@ -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 memory debugger, to test it for memory errors and leaks. Just add C at the beginning of the code you want to test. Behind the hood, C forks so that the child can basically C (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 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). L, L (core modules since perl 5) and L (since 5.6.2). +L. + =head1 AUTHOR Vincent Pit, C<< >>, L. @@ -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 (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