From: Vincent Pit Date: Mon, 16 Nov 2015 13:25:56 +0000 (-0200) Subject: Improve detection of executables X-Git-Tag: v1.18~3 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=5f7c59874ed712bf2787c3b0dbbaaf899fdd508c;p=perl%2Fmodules%2FTest-Valgrind.git Improve detection of executables Also make Test::Valgrind::FakeValgrind decide if the test should be skipped or not depending on the operating system. --- diff --git a/Makefile.PL b/Makefile.PL index 35627d2..39d91ce 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -124,6 +124,7 @@ my %PREREQ_PM = ( 'Carp' => 0, 'Digest::MD5' => 0, 'Env::Sanctify' => 0, + 'ExtUtils::MM' => 0, 'File::HomeDir' => '0.86', 'File::Path' => 0, 'File::Spec' => 0, diff --git a/lib/Test/Valgrind/Session.pm b/lib/Test/Valgrind/Session.pm index ba00ee2..d222f11 100644 --- a/lib/Test/Valgrind/Session.pm +++ b/lib/Test/Valgrind/Session.pm @@ -22,7 +22,9 @@ It also acts as a dispatcher between the different components. =cut +use Config (); use File::Spec (); +use ExtUtils::MM (); # MM->maybe_command() use Scalar::Util (); use Fcntl (); # F_SETFD @@ -111,10 +113,12 @@ sub new { if (defined $vg and not ref $vg) { @paths = ($vg); } else { - push @paths, @$vg if $vg and ref $vg eq 'ARRAY'; + push @paths, @$vg if defined $vg and ref $vg eq 'ARRAY'; my $dirs = delete $args{search_dirs}; - $dirs = [ File::Spec->path ] unless $dirs; - push @paths, map File::Spec->catfile($_, 'valgrind'), @$dirs + $dirs = [ File::Spec->path ] unless defined $dirs; + my $exe_name = 'valgrind'; + $exe_name .= $Config::Config{exe_ext} if defined $Config::Config{exe_ext}; + push @paths, map File::Spec->catfile($_, $exe_name), @$dirs if ref $dirs eq 'ARRAY'; } $class->_croak('Empty valgrind candidates list') unless @paths; @@ -125,16 +129,16 @@ sub new { } my ($valgrind, $version); - for (@paths) { - next unless -x; - my $output = qx/$_ --version/; + for my $path (@paths) { + next unless defined($path) and MM->maybe_command($path); + my $output = qx/$path --version/; $version = do { local $@; eval { Test::Valgrind::Version->new(command_output => $output) }; }; if (defined $version) { next if defined $min_version and $version < $min_version; - $valgrind = $_; + $valgrind = $path; last; } } diff --git a/t/30-skip.t b/t/30-skip.t index b758af1..5a35a2c 100644 --- a/t/30-skip.t +++ b/t/30-skip.t @@ -20,8 +20,6 @@ SKIP: { } SKIP: { - skip 'Only on linux or darwin' => 1 unless $^O eq 'linux' or $^O eq 'darwin'; - my $old_vg = Test::Valgrind::FakeValgrind->new( exe_name => 'valgrind', version => '3.0.0', @@ -35,8 +33,6 @@ SKIP: { } SKIP: { - skip 'Only on linux or darwin' => 1 unless $^O eq 'linux' or $^O eq 'darwin'; - my $new_vg = Test::Valgrind::FakeValgrind->new( exe_name => 'valgrind', version => '3.4.0', @@ -49,4 +45,3 @@ SKIP: { like $out, qr/^1\.\.0 # (?:SKIP|Skip) No compatible suppressions available/, 'correctly skip when no compatible suppressions were available'; } - diff --git a/t/70-session.t b/t/70-session.t index c9c3cc4..f39285f 100644 --- a/t/70-session.t +++ b/t/70-session.t @@ -23,8 +23,6 @@ $sess = eval { Test::Valgrind::Session->new( like $@, qr/^No appropriate valgrind executable/, 'nonexistant valgrind'; 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', ); diff --git a/t/lib/Test/Valgrind/FakeValgrind.pm b/t/lib/Test/Valgrind/FakeValgrind.pm index 067309b..0d13a0d 100644 --- a/t/lib/Test/Valgrind/FakeValgrind.pm +++ b/t/lib/Test/Valgrind/FakeValgrind.pm @@ -45,28 +45,39 @@ BEGIN { sub new { my ($class, %args) = @_; + return 'Temporary executables do not work on Windows' if $^O eq 'MSWin32'; + my $exe_name = $args{exe_name}; my $version = $args{version} || '3.1.0'; my $body = $args{body}; my $self = { }; + my $exe_ext = $Config::Config{exe_ext}; + $exe_ext = '' unless defined $exe_ext; if (defined $exe_name) { return 'File::Temp 0.19 is required to make a proper temporary directory' unless $good_enough_file_temp; + if (length $exe_ext and $exe_name !~ /\Q$exe_ext\E$/) { + $exe_name .= $exe_ext; + } $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 { # Can't use the OO interface if we don't wan't the file to be opened by # default, but then we have to deal with cleanup ourselves. - local $^W = 0; - (undef, my $tmp_file) = File::Temp::tempfile( + my %args = ( TEMPLATE => 'fakevgXXXX', TMPDIR => 1, CLEANUP => 0, OPEN => 0, ); + $args{SUFFIX} = $exe_ext if length $exe_ext; + my $tmp_file = do { + local $^W = 0; + (File::Temp::tempfile(%args))[1] + }; $self->{tmp_file} = $tmp_file; my ($vol, $dir) = File::Spec->splitpath($self->{tmp_file}); $self->{tmp_dir} = File::Spec->catpath($vol, $dir, '');