]> git.vpit.fr Git - perl/modules/Test-Valgrind.git/blobdiff - t/70-session.t
Factor the fake valgrind test helper into a separate class
[perl/modules/Test-Valgrind.git] / t / 70-session.t
index 3bfa7d0de2e2b86d436670255e9167290857b15b..1ce46c53a728206a1af257f25c47309acf929651 100644 (file)
@@ -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,45 +20,37 @@ $sess = eval { Test::Valgrind::Session->new(
 ) };
 like $@, qr/^No appropriate valgrind executable/, 'nonexistant valgrind';
 
-sub fake_vg {
- my ($version) = @_;
- return <<" FAKE_VG";
-#!$^X
-if (\@ARGV == 1 && \$ARGV[0] eq '--version') {
- print "valgrind-$version\n";
-} else {
- print "hlagh\n";
+SKIP: {
+ skip 'Only on linux or darwin' => 5 unless $^O eq 'linux' or $^O eq 'darwin';
+
+ 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    => $old_vg->path,
+  min_version => '3.1.0',
+ ) };
+ like $@, qr/^No appropriate valgrind executable/, 'old valgrind';
+
+ 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    => $new_vg->path,
+  min_version => '3.1.0',
+ ) };
+ is     $@,    '',                        'new valgrind';
+ isa_ok $sess, 'Test::Valgrind::Session', 'new valgrind isa Test::Valgrind::Session';
+
+ $sess = eval { Test::Valgrind::Session->new(
+  search_dirs => [ ],
+  valgrind    => [ $old_vg->path, $new_vg->path ],
+  min_version => '3.1.0',
+ ) };
+ is     $@,    '',                        'old and new valgrind';
+ isa_ok $sess, 'Test::Valgrind::Session', 'old and new valgrind isa Test::Valgrind::Session';
 }
- FAKE_VG
-}
-
-my $vg_old = File::Temp->new(UNLINK => 1);
-print $vg_old fake_vg('3.0.0');
-close $vg_old;
-chmod 0755, $vg_old->filename;
-
-my $sess = eval { Test::Valgrind::Session->new(
- valgrind    => $vg_old->filename,
- min_version => '3.1.0',
-) };
-like $@, qr/^No appropriate valgrind executable/, 'old valgrind';
-
-my $vg_new = File::Temp->new(UNLINK => 1);
-print $vg_new fake_vg('3.4.0');
-close $vg_new;
-chmod 0755, $vg_new->filename;
-
-$sess = eval { Test::Valgrind::Session->new(
- valgrind    => $vg_new->filename,
- min_version => '3.1.0',
-) };
-is     $@,    '',                        'new valgrind';
-isa_ok $sess, 'Test::Valgrind::Session', 'new valgrind isa Test::Valgrind::Session';
-
-$sess = eval { Test::Valgrind::Session->new(
- search_dirs => [ ],
- valgrind    => [ $vg_old->filename, $vg_new->filename ],
- min_version => '3.1.0',
-) };
-is     $@,    '',                        'old and new valgrind';
-isa_ok $sess, 'Test::Valgrind::Session', 'old and new valgrind isa Test::Valgrind::Session';