X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FTest-Valgrind.git;a=blobdiff_plain;f=t%2F70-session.t;h=1ce46c53a728206a1af257f25c47309acf929651;hp=bada708f7fb60e65c83eb1c8d187f3e104891d89;hb=15e7706165e33a1e52fba63877a92613ff1794a8;hpb=592fa78810e50cd5c9376dc493dfbe0891890080 diff --git a/t/70-session.t b/t/70-session.t index bada708..1ce46c5 100644 --- a/t/70-session.t +++ b/t/70-session.t @@ -5,10 +5,11 @@ use warnings; 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 => [ ], ) }; @@ -19,56 +20,27 @@ $sess = eval { Test::Valgrind::Session->new( ) }; 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'; @@ -76,7 +48,7 @@ SKIP: { $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';