Skip to content

Commit 70752d1

Browse files
committed
make_executable.t: ensure PATH for test is not too long, as that is incompatible with win2k
1 parent c150e7c commit 70752d1

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

cpan/ExtUtils-PL2Bat/t/make_executable.t

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use Test::More;
88
use ExtUtils::PL2Bat;
99
use Cwd qw/cwd/;
1010

11-
plan($^O eq 'MSWin32' ? (tests => 7) : skip_all => 'Only usable on Windows');
11+
plan($^O eq 'MSWin32' ? (tests => 8) : skip_all => 'Only usable on Windows');
1212

1313
my $filename = 'test_exec';
1414
my @files;
@@ -19,9 +19,10 @@ close $out;
1919

2020
pl2bat(in => $filename);
2121

22+
my $path_with_cwd = construct_test_PATH();
23+
2224
foreach my $i (42, 51, 0) {
23-
my $cwd = cwd;
24-
local $ENV{PATH} = join $Config{path_sep}, $cwd, $ENV{PATH};
25+
local $ENV{PATH} = $path_with_cwd;
2526
my $ret = system $filename, $i;
2627
is $ret & 0xff, 0, 'test_exec executed successfully';
2728
is $ret >> 8, $i, "test_exec $i return value ok";
@@ -31,3 +32,29 @@ push @files, grep { -f } map { $filename.$_ } split / $Config{path_sep} /x, $ENV
3132
is scalar(@files), 1, "Executable file exists";
3233

3334
unlink $filename, @files;
35+
36+
# the test needs CWD in PATH to check the created .bat files, but under win2k
37+
# PATH may not be too long. so to keep any win2k smokers happy, we construct
38+
# a new PATH that contains the dirs which hold cmd.exe, perl.exe, and CWD
39+
40+
sub construct_test_PATH {
41+
my $perl_path = $^X;
42+
my $cmd_path = $ENV{ComSpec} || `where cmd`; # where doesn't seem to work on all windows versions
43+
$_ =~ s/[\\\/][^\\\/]+$// for $perl_path, $cmd_path; # strip executable names
44+
45+
my @path_fallbacks = grep /\Q$ENV{SystemRoot}\E|system32|winnt|windows/i, split $Config{path_sep}, $ENV{PATH};
46+
47+
my $path_with_cwd = join $Config{path_sep}, @path_fallbacks, $cmd_path, $perl_path, cwd();
48+
49+
my ($perl) = ( $^X =~ /[\\\/]([^\\]+)$/ ); # in case the perl executable name differs
50+
note "using perl executable name: $perl";
51+
52+
local $ENV{PATH} = $path_with_cwd;
53+
my $test_out = `$perl -e 1 2>&1`;
54+
is $test_out, "", "perl execution with temp path works"
55+
or diag "make_executable.t tmp path: $path_with_cwd";
56+
diag "make_executable.t PATH likely did not contain cmd.exe"
57+
if !defined $test_out;
58+
59+
return $path_with_cwd;
60+
}

0 commit comments

Comments
 (0)