Skip to content

Commit

Permalink
ensure PATH for test is not too long, as that is incompatible with win2k
Browse files Browse the repository at this point in the history
  • Loading branch information
wchristian committed Sep 10, 2020
1 parent f6ce9f6 commit 27b7ed9
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions t/make_executable.t
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use Cwd qw/cwd/;

my @test_vals = ( 0, 1, 2, 3, -1, -2, 65535, 65536, 65537, 47, 100, 200, 255, 256, 257, 258, 511, 512, 513, -255, -256, -20012001 );

plan($OSNAME eq 'MSWin32' ? ( tests => (($#test_vals+1)*5)+1 ) : ( skip_all => 'Only usable on Windows' ));
plan($OSNAME eq 'MSWin32' ? ( tests => (($#test_vals+1)*5)+2 ) : ( skip_all => 'Only usable on Windows' ));

my $perl_in_fname = 'test_perl_source';

Expand All @@ -28,9 +28,25 @@ ok (-e "$batch_out_fname", qq{Executable file exists ("$batch_out_fname")});
my $int_max_8bit = 2**8;
my $int_max_16bit = 2**16;

my $tmp_path = do { # keep PATH from going above 1023 chars (incompatible on win2k)
my $perl_path = $^X;
my $cmd_path = $ENV{ComSpec} || `where cmd`; # doesn't seem to work on all windows versions
my @path_fallbacks = grep /\Q$ENV{SystemRoot}\E|system32|winnt|windows/i, split $Config{path_sep}, $ENV{PATH};
$_ =~ s/[\\\/][^\\\/]+$// for $perl_path, $cmd_path; # strip executable name
join $Config{path_sep}, @path_fallbacks, $cmd_path, $perl_path, cwd();
};

{
local $ENV{PATH} = $tmp_path;
my $test_out = `perl -e 1 2>&1`;
is $test_out, "", "perl execution with temp path works"
or print STDERR "make_executable.t tmp path: $tmp_path\n";
print STDERR "make_executable.t PATH likely did not contain cmd.exe\n"
if !defined $test_out;
}

foreach my $input_val ( @test_vals ) {
my $cwd = cwd;
local $ENV{PATH} = join $Config{path_sep}, $cwd, $ENV{PATH};
local $ENV{PATH} = $tmp_path;
my $qx_output = q//;
my $qx_retval = 0;
my $error_level = 0;
Expand Down

0 comments on commit 27b7ed9

Please sign in to comment.