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 c0c5a0a
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 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,10 @@ 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 $path_with_cwd = construct_test_PATH();

foreach my $input_val ( @test_vals ) {
my $cwd = cwd;
local $ENV{PATH} = join $Config{path_sep}, $cwd, $ENV{PATH};
local $ENV{PATH} = $path_with_cwd;
my $qx_output = q//;
my $qx_retval = 0;
my $error_level = 0;
Expand Down Expand Up @@ -60,3 +61,26 @@ foreach my $input_val ( @test_vals ) {
}

unlink $perl_in_fname, $batch_out_fname;

# the test needs CWD in PATH to check the created .bat files, but under win2k
# PATH may not be too long. so to keep any win2k smokers happy, we construct
# a new PATH that contains the dirs which hold cmd.exe, perl.exe, and CWD

sub construct_test_PATH {
my $perl_path = $^X;
my $cmd_path = $ENV{ComSpec} || `where cmd`; # doesn't seem to work on all windows versions
$_ =~ s/[\\\/][^\\\/]+$// for $perl_path, $cmd_path; # strip executable name

my @path_fallbacks = grep /\Q$ENV{SystemRoot}\E|system32|winnt|windows/i, split $Config{path_sep}, $ENV{PATH};

my $path_with_cwd = join $Config{path_sep}, @path_fallbacks, $cmd_path, $perl_path, cwd();

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

return $path_with_cwd;
}

0 comments on commit c0c5a0a

Please sign in to comment.