-
Notifications
You must be signed in to change notification settings - Fork 565
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
make_executable.t: ensure PATH for test is not too long, as that is incompatible with win2k #18118
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ use Test::More; | |
use ExtUtils::PL2Bat; | ||
use Cwd qw/cwd/; | ||
|
||
plan($^O eq 'MSWin32' ? (tests => 7) : skip_all => 'Only usable on Windows'); | ||
plan($^O eq 'MSWin32' ? (tests => 8) : skip_all => 'Only usable on Windows'); | ||
|
||
my $filename = 'test_exec'; | ||
my @files; | ||
|
@@ -19,9 +19,10 @@ close $out; | |
|
||
pl2bat(in => $filename); | ||
|
||
my $path_with_cwd = construct_test_PATH(); | ||
|
||
foreach my $i (42, 51, 0) { | ||
my $cwd = cwd; | ||
local $ENV{PATH} = join $Config{path_sep}, $cwd, $ENV{PATH}; | ||
local $ENV{PATH} = $path_with_cwd; | ||
my $ret = system $filename, $i; | ||
is $ret & 0xff, 0, 'test_exec executed successfully'; | ||
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 | |
is scalar(@files), 1, "Executable file exists"; | ||
|
||
unlink $filename, @files; | ||
|
||
# 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`; # where doesn't seem to work on all windows versions | ||
$_ =~ s/[\\\/][^\\\/]+$// for $perl_path, $cmd_path; # strip executable names | ||
|
||
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 | ||
wchristian marked this conversation as resolved.
Show resolved
Hide resolved
|
||
note "using perl executable name: $perl"; | ||
|
||
local $ENV{PATH} = $path_with_cwd; | ||
my $test_out = `$perl -e 1 2>&1`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe check There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, i can add that. |
||
is $test_out, "", "perl execution with temp path works" | ||
or diag "make_executable.t tmp path: $path_with_cwd"; | ||
diag "make_executable.t PATH likely did not contain cmd.exe" | ||
if !defined $test_out; | ||
|
||
return $path_with_cwd; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should not we check for
$?
when it fails?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sensible too.