Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ensure PATH for test is not too long, as that is incompatible with win2k #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 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,29 @@ 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 must 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();

my ($perl) = ( $^X =~ /[\\\/]([^\\]+)$/ ); # in case the perl executable name differs
note "using perl executable name: $perl";

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;
}