]> git.vpit.fr Git - perl/modules/Test-Valgrind.git/blobdiff - t/70-session.t
Make sure an absolute path is used in the dummy valgrind script shebang
[perl/modules/Test-Valgrind.git] / t / 70-session.t
index 3bfa7d0de2e2b86d436670255e9167290857b15b..bada708f7fb60e65c83eb1c8d187f3e104891d89 100644 (file)
@@ -21,8 +21,17 @@ 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";
-#!$^X
+#!$perl
 if (\@ARGV == 1 && \$ARGV[0] eq '--version') {
  print "valgrind-$version\n";
 } else {
@@ -31,33 +40,45 @@ if (\@ARGV == 1 && \$ARGV[0] eq '--version') {
  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;
+SKIP: {
+ skip 'Only on linux or darwin' => 5 unless $^O eq 'linux' or $^O eq 'darwin';
 
-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 $fake_vg_code = fake_vg('3.0.0');
+ skip 'Could not generate the dummy valgrind executable' => 5
+                                                   unless defined $fake_vg_code;
 
-my $vg_new = File::Temp->new(UNLINK => 1);
-print $vg_new fake_vg('3.4.0');
-close $vg_new;
-chmod 0755, $vg_new->filename;
+ my $vg_old = File::Temp->new(UNLINK => 1);
+ print $vg_old $fake_vg_code;
+ close $vg_old;
+ chmod 0755, $vg_old->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';
+ my $sess = eval { Test::Valgrind::Session->new(
+  valgrind    => $vg_old->filename,
+  min_version => '3.1.0',
+ ) };
+ like $@, qr/^No appropriate valgrind executable/, 'old valgrind';
 
-$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';
+ $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;
+
+ $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';
+}