'Carp' => 0,
'Digest::MD5' => 0,
'Env::Sanctify' => 0,
+ 'ExtUtils::MM' => 0,
'File::HomeDir' => '0.86',
'File::Path' => 0,
'File::Spec' => 0,
=cut
+use Config ();
use File::Spec ();
+use ExtUtils::MM (); # MM->maybe_command()
use Scalar::Util ();
use Fcntl (); # F_SETFD
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;
}
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;
}
}
}
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',
}
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',
like $out, qr/^1\.\.0 # (?:SKIP|Skip) No compatible suppressions available/,
'correctly skip when no compatible suppressions were available';
}
-
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',
);
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, '');