]> git.vpit.fr Git - perl/modules/Test-Valgrind.git/blob - 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
1 #!perl
2
3 use strict;
4 use warnings;
5
6 use Test::Valgrind::Session;
7
8 use File::Temp;
9
10 use Test::More tests => 7;
11
12 my $sess = eval { Test::Valgrind::Session->new(
13  search_dirs => [ ],
14 ) };
15 like $@, qr/^Empty valgrind candidates list/, 'no search_dirs';
16
17 $sess = eval { Test::Valgrind::Session->new(
18  valgrind => 'wut',
19 ) };
20 like $@, qr/^No appropriate valgrind executable/, 'nonexistant valgrind';
21
22 sub fake_vg {
23  my ($version) = @_;
24
25  my $perl = $^X;
26  unless (-e $perl and -x $perl) {
27   $perl = $Config::Config{perlpath};
28   unless (-e $perl and -x $perl) {
29    return undef;
30   }
31  }
32
33  return <<" FAKE_VG";
34 #!$perl
35 if (\@ARGV == 1 && \$ARGV[0] eq '--version') {
36  print "valgrind-$version\n";
37 } else {
38  print "hlagh\n";
39 }
40  FAKE_VG
41 }
42
43 SKIP: {
44  skip 'Only on linux or darwin' => 5 unless $^O eq 'linux' or $^O eq 'darwin';
45
46  my $fake_vg_code = fake_vg('3.0.0');
47  skip 'Could not generate the dummy valgrind executable' => 5
48                                                    unless defined $fake_vg_code;
49
50  my $vg_old = File::Temp->new(UNLINK => 1);
51  print $vg_old $fake_vg_code;
52  close $vg_old;
53  chmod 0755, $vg_old->filename;
54
55  my $sess = eval { Test::Valgrind::Session->new(
56   valgrind    => $vg_old->filename,
57   min_version => '3.1.0',
58  ) };
59  like $@, qr/^No appropriate valgrind executable/, 'old valgrind';
60
61  $fake_vg_code = fake_vg('3.4.0');
62  skip 'Could not generate the dummy valgrind executable' => 4
63                                                    unless defined $fake_vg_code;
64
65  my $vg_new = File::Temp->new(UNLINK => 1);
66  print $vg_new $fake_vg_code;
67  close $vg_new;
68  chmod 0755, $vg_new->filename;
69
70  $sess = eval { Test::Valgrind::Session->new(
71   valgrind    => $vg_new->filename,
72   min_version => '3.1.0',
73  ) };
74  is     $@,    '',                        'new valgrind';
75  isa_ok $sess, 'Test::Valgrind::Session', 'new valgrind isa Test::Valgrind::Session';
76
77  $sess = eval { Test::Valgrind::Session->new(
78   search_dirs => [ ],
79   valgrind    => [ $vg_old->filename, $vg_new->filename ],
80   min_version => '3.1.0',
81  ) };
82  is     $@,    '',                        'old and new valgrind';
83  isa_ok $sess, 'Test::Valgrind::Session', 'old and new valgrind isa Test::Valgrind::Session';
84 }