diff options
author | Karl Williamson <public@khwilliamson.com> | 2014-02-15 13:23:36 -0700 |
---|---|---|
committer | Karl Williamson <public@khwilliamson.com> | 2014-02-15 15:50:35 -0700 |
commit | 65ebb05984db179833ff252f547043f32184d893 (patch) | |
tree | 01add0d78d2ea2ee30a4098977f5f1c943cf89f1 /t | |
parent | 0e92a118111cc7fdf7a2bf58c8e45ef7b2b85ef4 (diff) | |
download | perl-65ebb05984db179833ff252f547043f32184d893.tar.gz |
Improve fallback during locale initialization
If Perl encounters a problem during startup trying to initialize the
locales from the environment it has immediately reverted to the "C"
locale.
This commit generalizes that so it tries each of the applicable
environment variables in order of priority until it works, or it gives
up and uses the "C" locale. For example, if LC_ALL is set to something
that is invalid, but LANG is valid, LANG will be used. This was
motivated by trying to get the Windows system default locale used in
preference to "C" if all else fails.
Diffstat (limited to 't')
-rw-r--r-- | t/run/locale.t | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/t/run/locale.t b/t/run/locale.t index 6e9852610a..b678fede8b 100644 --- a/t/run/locale.t +++ b/t/run/locale.t @@ -186,6 +186,45 @@ EOF } for ($different) { + local $ENV{LC_ALL} = "invalid"; + local $ENV{LC_NUMERIC} = "invalid"; + local $ENV{LANG} = $_; + + # Can't turn off the warnings, so send them to /dev/null + fresh_perl_is(<<'EOF', "$difference", { stderr => "devnull" }, + use locale; + use POSIX qw(locale_h); + setlocale(LC_NUMERIC, ""); + my $in = 4.2; + printf("%g", $in); +EOF + "LANG is used if LC_ALL, LC_NUMERIC are invalid"); + } + + SKIP: { + if ($^O eq 'MSWin32') { + skip("Win32 uses system default locale in preference to \"C\"", 1); + } + else { + for ($different) { + local $ENV{LC_ALL} = "invalid"; + local $ENV{LC_NUMERIC} = "invalid"; + local $ENV{LANG} = "invalid"; + + # Can't turn off the warnings, so send them to /dev/null + fresh_perl_is(<<'EOF', 4.2, { stderr => "devnull" }, + use locale; + use POSIX qw(locale_h); + setlocale(LC_NUMERIC, ""); + my $in = 4.2; + printf("%g", $in); +EOF + 'C locale is used if LC_ALL, LC_NUMERIC, LANG are invalid'); + } + } + } + + for ($different) { local $ENV{LC_NUMERIC} = $_; local $ENV{LC_ALL}; # so it never overrides LC_NUMERIC fresh_perl_is(<<"EOF", @@ -201,7 +240,7 @@ EOF } unless ($comma) { - skip("no locale available where LC_NUMERIC is a comma", 2); + skip("no locale available where LC_NUMERIC is a comma", 3); } else { @@ -270,4 +309,4 @@ EOF } # SKIP -sub last { 16 } +sub last { 18 } |