@@ -8,7 +8,7 @@ use Test::More;
8
8
use ExtUtils::PL2Bat;
9
9
use Cwd qw/ cwd/ ;
10
10
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' );
12
12
13
13
my $filename = ' test_exec' ;
14
14
my @files ;
@@ -19,9 +19,10 @@ close $out;
19
19
20
20
pl2bat(in => $filename );
21
21
22
+ my $path_with_cwd = construct_test_PATH();
23
+
22
24
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 ;
25
26
my $ret = system $filename , $i ;
26
27
is $ret & 0xff, 0, ' test_exec executed successfully' ;
27
28
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
31
32
is scalar (@files ), 1, " Executable file exists" ;
32
33
33
34
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