Revision history for Test-Valgrind
+0.02 2008-04-21 15:25 UTC
+ + Add : Test::Valgrind now depends on Perl::Destruct::Level. This is
+ needed for non-debugging perls because we can't set their
+ level of memory cleanup correctness on exit with the
+ PERL_DESTRUCT_LEVEL environment variable.
+ + Add : Hardcode valgrind path into the new constant
+ Test::Valgrind::Suppressions::VG_PATH.
+ + Chg : Test::Valgrind::Suppressions::supppath() is now supp_path().
+ + Chg : lib/Test/Valgrind/Suppressions.pm.tpl was renamed to
+ lib/Test/Valgrind/Suppressions.tpl for file portability reasons.
+
0.01 2008-04-19 15:50 UTC
First version, released on an unsuspecting world.
lib/Test/Valgrind.pm
lib/Test/Valgrind/perlTestValgrind.supp
lib/Test/Valgrind/Suppressions.pm
+lib/Test/Valgrind/Suppressions.tpl
samples/map.pl
t/00-load.t
t/01-import.t
--- #YAML:1.0
name: Test-Valgrind
-version: 0.01
-abstract: Test your code through valgrind.
+version: 0.02
+abstract: Test Perl code through valgrind.
license: perl
author:
- Vincent Pit <perl@profvince.com>
requires:
Carp: 0
Exporter: 0
+ Perl::Destruct::Level: 0
POSIX: 0
Test::More: 0
meta-spec:
use ExtUtils::MakeMaker;
my $has_vg = 0;
+my $vg;
print 'Checking for valgrind >= 3.1.0 in PATH... ';
for (split /:/, $ENV{PATH}) {
- my $vg = $_ . '/valgrind';
+ $vg = $_ . '/valgrind';
if (-x $vg) {
my $ver = qx/$vg --version/;
if ($ver =~ s/^valgrind-//) {
return $build_req;
}
-my $supp = 'Test/Valgrind/perlTestValgrind.supp';
+my $supp = 'lib/Test/Valgrind/Suppressions';
+open my $tpl, '<', $supp . '.tpl' or die "open($supp.tpl): $!";
+open my $out, '>', $supp . '.pm' or die "open($supp.pm): $!";
+while (<$tpl>) {
+ s/(VG_PATH\s*=>\s*)undef/$1'$vg'/g;
+ print $out $_;
+}
+close $out;
+close $tpl;
+
+$supp = 'Test/Valgrind/perlTestValgrind.supp';
WriteMakefile(
NAME => 'Test::Valgrind',
'lib/' . $supp => '$(INST_ARCHLIB)/' . $supp,
},
PREREQ_PM => {
- 'Carp' => 0,
- 'Exporter' => 0,
- 'POSIX' => 0,
- 'Test::More' => 0,
+ 'Carp' => 0,
+ 'Exporter' => 0,
+ 'POSIX' => 0,
+ 'Perl::Destruct::Level' => 0,
+ 'Test::More' => 0,
},
dist => {
PREOP => 'pod2text lib/Test/Valgrind.pm > $(DISTVNAME)/README; '
NAME
- Test::Valgrind - Test your code through valgrind.
+ Test::Valgrind - Test Perl code through valgrind.
VERSION
- Version 0.01
+ Version 0.02
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.
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
+
CONFIGURATION
You can pass parameters to "import" as a list of key / value pairs,
where valid keys are :
CAVEATS
You can't use this module to test code given by the "-e" command-line
- switch. 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.
+ 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.
+ In particular, running this module against test files will obliterate
+ their original test results.
DEPENDENCIES
Valgrind 3.1.0 (<http://valgrind.org>).
Carp, POSIX (core modules since perl 5) and Test::More (since 5.6.2).
+ Perl::Destruct::Level.
+
AUTHOR
Vincent Pit, "<perl at profvince.com>", <http://www.profvince.com>.
perldoc Test::Valgrind
+ACKNOWLEDGEMENTS
+ Rafaël Garcia-Suarez, for writing and instructing me about the
+ existence of Perl::Destruct::Level (Elizabeth Mattijsen is a close
+ second).
+
+ H.Merijn Brand, for daring to test this thing.
+
COPYRIGHT & LICENSE
Copyright 2008 Vincent Pit, all rights reserved.
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.
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 :
'--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 $_;
}
}
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 };
=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
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>.
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
-package Test::Valgrind::Suppressions;
-
-use strict;
-use warnings;
-
-=head1 NAME
-
-Test::Valgrind::Suppressions - Placeholder for architecture-dependant perl suppressions.
-
-=head1 VERSION
-
-Version 0.01
-
-=cut
-
-our $VERSION = '0.01';
-
-=head1 DESCRIPTION
-
-L<Test::Valgrind> needs suppressions so that perl's errors aren't reported. However, these suppressions depend widely on the architecture, perl's version and the features it has been build with (e.g. threads). The goal of this module is hence to be installed together with the suppression file generated when the Test-Valgrind distribution was built, and to handle back to L<Test::Valgrind> the path to the suppression file.
-
-=head1 FUNCTIONS
-
-=head2 C<supppath>
-
-Returns the path to the suppression file that applies to the current running perl, or C<undef> when no such file is available.
-
-=cut
-
-sub supppath {
- my $pkg = __PACKAGE__;
- $pkg =~ s!::!/!g;
- $pkg .= '.pm';
- return if not $INC{$pkg};
- my $supp = $INC{$pkg};
- $supp =~ s![^/]*$!perlTestValgrind.supp!;
- return (-f $supp) ? $supp : undef;
-}
-
-=head1 EXPORT
-
-This module exports the L</supppath> function only on demand, either by giving its name, or by the C<:funcs> or C<:all> tags.
-
-=cut
-
-use base qw/Exporter/;
-
-our @EXPORT = ();
-our %EXPORT_TAGS = ( 'funcs' => [ qw/supppath/ ] );
-our @EXPORT_OK = map { @$_ } values %EXPORT_TAGS;
-$EXPORT_TAGS{'all'} = [ @EXPORT_OK ];
-
-=head1 SEE ALSO
-
-L<Test::Valgrind>.
-
-=head1 AUTHOR
-
-Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
-
-You can contact me by mail or on #perl @ FreeNode (vincent or Prof_Vince).
-
-=head1 BUGS
-
-Please report any bugs or feature requests to C<bug-test-valgrind-suppressions at rt.cpan.org>, or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Valgrind>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
-
-=head1 SUPPORT
-
-You can find documentation for this module with the perldoc command.
-
- perldoc Test::Valgrind::Suppressions
-
-=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.
-
-=cut
-
-1; # End of Test::Valgrind::Suppressions
--- /dev/null
+package Test::Valgrind::Suppressions;
+
+use strict;
+use warnings;
+
+=head1 NAME
+
+Test::Valgrind::Suppressions - Placeholder for architecture-dependant perl suppressions.
+
+=head1 VERSION
+
+Version 0.02
+
+=cut
+
+our $VERSION = '0.02';
+
+=head1 DESCRIPTION
+
+L<Test::Valgrind> needs suppressions so that perl's errors aren't reported. However, these suppressions depend widely on the architecture, perl's version and the features it has been build with (e.g. threads). The goal of this module is hence to be installed together with the suppression file generated when the Test-Valgrind distribution was built, and to handle back to L<Test::Valgrind> the path to the suppression file.
+
+=head1 FUNCTIONS
+
+=head2 C<supp_path>
+
+Returns the path to the suppression file that applies to the current running perl, or C<undef> when no such file is available.
+
+=cut
+
+sub supp_path {
+ my $pkg = __PACKAGE__;
+ $pkg =~ s!::!/!g;
+ $pkg .= '.pm';
+ return if not $INC{$pkg};
+ my $supp = $INC{$pkg};
+ $supp =~ s![^/]*$!perlTestValgrind.supp!;
+ return (-f $supp) ? $supp : undef;
+}
+
+=head1 CONSTANTS
+
+=head2 C<VG_PATH>
+
+The path to the valgrind binary from which the suppressions were generated.
+
+=cut
+
+use constant VG_PATH => undef;
+
+=head1 EXPORT
+
+This module exports the L</supp_path> function and the L</VG_PATH> constants only on demand, either by giving their name explicitely or by the C<:funcs>, C<:consts> or C<:all> tags.
+
+=cut
+
+use base qw/Exporter/;
+
+our @EXPORT = ();
+our %EXPORT_TAGS = (
+ 'funcs' => [ qw/supp_path/ ],
+ 'consts' => [ qw/VG_PATH/ ]
+);
+our @EXPORT_OK = map { @$_ } values %EXPORT_TAGS;
+$EXPORT_TAGS{'all'} = [ @EXPORT_OK ];
+
+=head1 SEE ALSO
+
+L<Test::Valgrind>.
+
+=head1 AUTHOR
+
+Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
+
+You can contact me by mail or on #perl @ FreeNode (vincent or Prof_Vince).
+
+=head1 BUGS
+
+Please report any bugs or feature requests to C<bug-test-valgrind-suppressions at rt.cpan.org>, or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Valgrind>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
+
+=head1 SUPPORT
+
+You can find documentation for this module with the perldoc command.
+
+ perldoc Test::Valgrind::Suppressions
+
+=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.
+
+=cut
+
+1; # End of Test::Valgrind::Suppressions
use strict;
use warnings;
-use Test::More tests => 1;
+use Test::More tests => 2;
require Test::Valgrind::Suppressions;
-for (qw/supppath/) {
+for (qw/supp_path VG_PATH/) {
eval { Test::Valgrind::Suppressions->import($_) };
ok(!$@, 'import ' . $_);
}
use strict;
use warnings;
-use Test::More tests => 1;
+use Test::More tests => 2;
-use Test::Valgrind::Suppressions qw/supppath/;
+use Test::Valgrind::Suppressions qw/supp_path VG_PATH/;
-my $path = supppath();
+my $path = supp_path();
like($path, qr!Test/Valgrind/perlTestValgrind\.supp$!,
'supppath() returns the path to the suppression file');
+
+isnt(VG_PATH, undef, 'VG_PATH is defined');