X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2Flib%2FTest%2FValgrind%2FFakeValgrind.pm;h=ad7abfd347e61b96094a3a9080762885827e4500;hb=1d0c26d755a760ddc41b203a1dd8ec215aaa8593;hp=3f61ba6c32f05d87321ccd0e7589bc47b509905d;hpb=4a52e05da21e9ca5e27ab7c79898fda44b74ec2c;p=perl%2Fmodules%2FTest-Valgrind.git diff --git a/t/lib/Test/Valgrind/FakeValgrind.pm b/t/lib/Test/Valgrind/FakeValgrind.pm index 3f61ba6..ad7abfd 100644 --- a/t/lib/Test/Valgrind/FakeValgrind.pm +++ b/t/lib/Test/Valgrind/FakeValgrind.pm @@ -33,32 +33,54 @@ if (\@ARGV == 1 && \$ARGV[0] eq '--version') { FAKE_VG } +my $good_enough_file_temp; +BEGIN { + $good_enough_file_temp = do { + no warnings; + local $@; + eval { File::Temp->VERSION('0.19'); 1 } + } +} + 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) { - $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); + 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, ); - $self->{tmp_file} = $tmp_file; - my ($vol, $dir) = File::Spec->splitpath($self->{tmp_file}); - $self->{tmp_dir} = File::Spec->catpath($vol, $dir, ''); + $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, ''); } my $code = _dummy_valgrind_code($version, $body);