t/70-session.t
t/80-suppressions.t
t/81-suppressions-demangle.t
+t/lib/Test/Valgrind/FakeValgrind.pm
t/lib/Test/Valgrind/Test/Action.pm
t/supp/no_perl
use Test::Valgrind::Session;
-use File::Temp;
-
use Test::More tests => 7;
+use lib 't/lib';
+use Test::Valgrind::FakeValgrind;
+
my $sess = eval { Test::Valgrind::Session->new(
search_dirs => [ ],
) };
) };
like $@, qr/^No appropriate valgrind executable/, 'nonexistant valgrind';
-sub fake_vg {
- my ($version) = @_;
-
- my $perl = $^X;
- unless (-e $perl and -x $perl) {
- $perl = $Config::Config{perlpath};
- unless (-e $perl and -x $perl) {
- return undef;
- }
- }
-
- return <<" FAKE_VG";
-#!$perl
-if (\@ARGV == 1 && \$ARGV[0] eq '--version') {
- print "valgrind-$version\n";
-} else {
- print "hlagh\n";
-}
- FAKE_VG
-}
-
SKIP: {
skip 'Only on linux or darwin' => 5 unless $^O eq 'linux' or $^O eq 'darwin';
- my $fake_vg_code = fake_vg('3.0.0');
- skip 'Could not generate the dummy valgrind executable' => 5
- unless defined $fake_vg_code;
-
- my $vg_old = File::Temp->new(UNLINK => 1);
- print $vg_old $fake_vg_code;
- close $vg_old;
- chmod 0755, $vg_old->filename;
+ my $old_vg = Test::Valgrind::FakeValgrind->new(
+ version => '3.0.0',
+ );
+ skip $old_vg => 5 unless ref $old_vg;
my $sess = eval { Test::Valgrind::Session->new(
- valgrind => $vg_old->filename,
+ valgrind => $old_vg->path,
min_version => '3.1.0',
) };
like $@, qr/^No appropriate valgrind executable/, 'old valgrind';
- $fake_vg_code = fake_vg('3.4.0');
- skip 'Could not generate the dummy valgrind executable' => 4
- unless defined $fake_vg_code;
-
- my $vg_new = File::Temp->new(UNLINK => 1);
- print $vg_new $fake_vg_code;
- close $vg_new;
- chmod 0755, $vg_new->filename;
+ my $new_vg = Test::Valgrind::FakeValgrind->new(
+ version => '3.4.0',
+ );
+ skip $new_vg => 4 unless ref $new_vg;
$sess = eval { Test::Valgrind::Session->new(
- valgrind => $vg_new->filename,
+ valgrind => $new_vg->path,
min_version => '3.1.0',
) };
is $@, '', 'new valgrind';
$sess = eval { Test::Valgrind::Session->new(
search_dirs => [ ],
- valgrind => [ $vg_old->filename, $vg_new->filename ],
+ valgrind => [ $old_vg->path, $new_vg->path ],
min_version => '3.1.0',
) };
is $@, '', 'old and new valgrind';
use Test::Valgrind::Tool;
use Test::Valgrind::Session;
+use lib 't/lib';
+use Test::Valgrind::FakeValgrind;
+
my $cmd = Test::Valgrind::Command->new(
command => 'Perl',
args => [ '-e1' ],
);
-my $tool = Test::Valgrind::Tool->new(
- tool => 'memcheck',
-);
+{
+ package Test::Valgrind::Parser::Dummy;
+
+ use base 'Test::Valgrind::Parser';
+
+ sub parse { }
+}
+
+{
+ package Test::Valgrind::Tool::Dummy;
+
+ use base 'Test::Valgrind::Tool::memcheck';
+
+ sub parser_class { 'Test::Valgrind::Parser::Dummy' }
+}
+
+my $tool = Test::Valgrind::Tool::Dummy->new();
{
package Test::Valgrind::Action::Dummy;
use base 'Test::Valgrind::Action';
sub do_suppressions { 0 }
+
+ sub report {
+ my ($self, $sess, $report) = @_;
+
+ if ($report->is_diag) {
+ my $contents = $report->data;
+ if ($contents !~ /^(?:Using valgrind |No suppressions used)/) {
+ ::diag($contents);
+ }
+ return;
+ } else {
+ $self->SUPER::report($sess, $report);
+ }
+ }
}
my $dummy_action = Test::Valgrind::Action::Dummy->new();
close $supp_fh;
}
-$sess = eval { Test::Valgrind::Session->new(
- no_def_supp => 1,
- extra_supp => [ 't/supp/no_perl' ],
-)->run(
- tool => $tool,
- command => $cmd,
- action => $dummy_action,
-) };
-like $@, qr/No compatible suppressions available/,
- 'incompatible suppression file';
-
-$sess = eval { Test::Valgrind::Session->new(
- no_def_supp => 1,
- allow_no_supp => 1,
- extra_supp => [ 't/supp/no_perl' ],
-)->run(
- tool => $tool,
- command => $cmd,
- action => $dummy_action,
-) };
-is $@, '', 'incompatible suppression file, but forced';
+SKIP: {
+ my $dummy_vg = Test::Valgrind::FakeValgrind->new();
+ skip $dummy_vg => 2 unless ref $dummy_vg;
+
+ $sess = eval { Test::Valgrind::Session->new(
+ valgrind => $dummy_vg->path,
+ no_def_supp => 1,
+ extra_supp => [ 't/supp/no_perl' ],
+ )->run(
+ tool => $tool,
+ command => $cmd,
+ action => $dummy_action,
+ ) };
+ like $@, qr/No compatible suppressions available/,
+ 'incompatible suppression file';
+
+ $sess = eval { Test::Valgrind::Session->new(
+ valgrind => $dummy_vg->path,
+ no_def_supp => 1,
+ allow_no_supp => 1,
+ extra_supp => [ 't/supp/no_perl' ],
+ )->run(
+ tool => $tool,
+ command => $cmd,
+ action => $dummy_action,
+ ) };
+ is $@, '', 'incompatible suppression file, but forced';
+}
--- /dev/null
+package Test::Valgrind::FakeValgrind;
+
+use strict;
+use warnings;
+
+use Config ();
+use File::Spec;
+use File::Temp;
+
+sub _dummy_valgrind_code {
+ my ($version) = @_;
+
+ my $perl = $^X;
+ unless (-e $perl and -x $perl) {
+ $perl = $Config::Config{perlpath};
+ unless (-e $perl and -x $perl) {
+ return undef;
+ }
+ }
+
+ return <<" FAKE_VG";
+#!$perl
+if (\@ARGV == 1 && \$ARGV[0] eq '--version') {
+ print "valgrind-$version\n";
+}
+ FAKE_VG
+}
+
+sub new {
+ my ($class, %args) = @_;
+
+ my $exe_name = $args{exe_name};
+ my $version = $args{version} || '3.1.0';
+
+ my $self = { };
+
+ if (defined $exe_name) {
+ $self->{tmp_dir_obj} = File::Temp->newdir(CLEANUP => 1);
+ $self->{tmp_dir} = $self->{tmp_dir_obj}->dirname;
+ $self->{tmp_file} = File::Spec->catfile($self->{tmp_dir}, $exe_name);
+ } else {
+ $self->{tmp_file_obj} = File::Temp->new(UNLINK => 1);
+ $self->{tmp_file} = $self->{tmp_file_obj}->filename;
+ my ($vol, $dir) = File::Spec->splitpath($self->{tmp_file});
+ $self->{tmp_dir} = File::Spec->catpath($vol, $dir, '');
+ }
+
+ my $code = _dummy_valgrind_code($version);
+ return 'Could not generate the dummy valgrind executable' unless $code;
+
+ return 'Temporary file already exists' if -s $self->{tmp_file};
+
+ {
+ open my $vg_fh, '>', $self->{tmp_file};
+ print $vg_fh $code;
+ close $vg_fh;
+ chmod 0755, $self->{tmp_file};
+ }
+
+ bless $self, $class;
+}
+
+sub path { $_[0]->{tmp_file} }
+
+sub dir { $_[0]->{tmp_dir} }
+
+1;