diff options
author | Paul Smith <psmith@gnu.org> | 2022-10-28 15:51:49 -0400 |
---|---|---|
committer | Paul Smith <psmith@gnu.org> | 2022-10-28 17:39:06 -0400 |
commit | b92340a1eab22a3125c1e61850610cd2121457a6 (patch) | |
tree | a222ceb7b8c24b58c6ac77459ac2a9f6ef6370b9 /tests | |
parent | 8064aee4f978ff609e76dd43b3cfaa568174b994 (diff) | |
download | make-git-b92340a1eab22a3125c1e61850610cd2121457a6.tar.gz |
[SV 62174] Force locale to be "C" before retrieving error messages
We attempt to do this with POSIX::setlocale() but apparently on some
systems (AIX) this isn't sufficient. So, in addition force the LC
environment variables to use "C".
Reported by Dmitry Goncharov <dgoncharov@users.sf.net>.
* tests/run_make_tests.pl: Move the global setup into set_default().
Force the %ENV locale variables to use the ones we'll use when running
make, then reset them back again after we find error messages.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/run_make_tests.pl | 147 |
1 files changed, 75 insertions, 72 deletions
diff --git a/tests/run_make_tests.pl b/tests/run_make_tests.pl index feb1f5d7..70dd1821 100644 --- a/tests/run_make_tests.pl +++ b/tests/run_make_tests.pl @@ -110,78 +110,6 @@ $ERR_nonexe_file = undef; $ERR_exe_dir = undef; $ERR_command_not_found = undef; -{ - use locale; - - my $loc = undef; - if ($has_POSIX) { - POSIX->import(qw(locale_h)); - # Windows has POSIX locale, but only LC_ALL not LC_MESSAGES - $loc = POSIX::setlocale(&POSIX::LC_ALL); - POSIX::setlocale(&POSIX::LC_ALL, 'C'); - - # See set_defaults() as this doesn't work right on Windows :( - $! = &POSIX::ERANGE; - } - - if (open(my $F, '<', 'file.none')) { - print "Opened non-existent file! Skipping related tests.\n"; - } else { - $ERR_no_such_file = "$!"; - } - - unlink('file.out'); - touch('file.out'); - - chmod(0444, 'file.out'); - if (open(my $F, '>', 'file.out')) { - print "Opened read-only file! Skipping related tests.\n"; - close($F); - } else { - $ERR_read_only_file = "$!"; - } - - $_ = `./file.out 2>&1`; - if ($? == 0) { - print "Executed non-executable file! Skipping related tests.\n"; - } else { - $ERR_nonexe_file = "$!"; - } - - if ($^O =~ /cygwin/i) { - # For some reason the execute here gives a different answer than make's - print "Skipping directory execution on $^O\n"; - } else { - $_ = `./. 2>&1`; - if ($? == 0) { - print "Executed directory! Skipping related tests.\n"; - } else { - $ERR_exe_dir = "$!"; - } - } - - chmod(0000, 'file.out'); - if (open(my $F, '<', 'file.out')) { - print "Opened unreadable file! Skipping related tests.\n"; - close($F); - } else { - $ERR_unreadable_file = "$!"; - } - - unlink('file.out') or die "Failed to delete file.out: $!\n"; - - $_ = `/bin/sh -c 'bad-command 2>&1'`; - if ($? == 0) { - print "Invoked invalid file! Skipping related tests.\n"; - } else { - chomp($_); - s/bad-command/#CMDNAME#/g; - $ERR_command_not_found = $_; - } - - $loc and POSIX::setlocale(&POSIX::LC_ALL, $loc); -} - #$SIG{INT} = sub { print STDERR "Caught a signal!\n"; die @_; }; sub valid_option @@ -477,6 +405,81 @@ sub set_defaults } else { $scriptsuffix = '.bat'; } + + $ENV{LC_ALL} = $makeENV{LC_ALL}; + $ENV{LANG} = $makeENV{LANG}; + $ENV{LANGUAGE} = $makeENV{LANGUAGE}; + + use locale; + + my $loc = undef; + if ($has_POSIX) { + POSIX->import(qw(locale_h)); + # Windows has POSIX locale, but only LC_ALL not LC_MESSAGES + $loc = POSIX::setlocale(&POSIX::LC_ALL); + POSIX::setlocale(&POSIX::LC_ALL, 'C'); + } + + if (open(my $F, '<', 'file.none')) { + print "Opened non-existent file! Skipping related tests.\n"; + } else { + $ERR_no_such_file = "$!"; + } + + unlink('file.out'); + touch('file.out'); + + chmod(0444, 'file.out'); + if (open(my $F, '>', 'file.out')) { + print "Opened read-only file! Skipping related tests.\n"; + close($F); + } else { + $ERR_read_only_file = "$!"; + } + + $_ = `./file.out 2>&1`; + if ($? == 0) { + print "Executed non-executable file! Skipping related tests.\n"; + } else { + $ERR_nonexe_file = "$!"; + } + + if ($^O =~ /cygwin/i) { + # For some reason the execute here gives a different answer than make's + print "Skipping directory execution on $^O\n"; + } else { + $_ = `./. 2>&1`; + if ($? == 0) { + print "Executed directory! Skipping related tests.\n"; + } else { + $ERR_exe_dir = "$!"; + } + } + + chmod(0000, 'file.out'); + if (open(my $F, '<', 'file.out')) { + print "Opened unreadable file! Skipping related tests.\n"; + close($F); + } else { + $ERR_unreadable_file = "$!"; + } + + unlink('file.out') or die "Failed to delete file.out: $!\n"; + + $_ = `/bin/sh -c 'bad-command 2>&1'`; + if ($? == 0) { + print "Invoked invalid file! Skipping related tests.\n"; + } else { + chomp($_); + s/bad-command/#CMDNAME#/g; + $ERR_command_not_found = $_; + } + + $loc and POSIX::setlocale(&POSIX::LC_ALL, $loc); + + $ENV{LC_ALL} = $origENV{LC_ALL}; + $ENV{LANG} = $origENV{LANG}; + $ENV{LANGUAGE} = $origENV{LANGUAGE}; } # This is no longer used: we import config-flags.pm instead |