Fix Utils.pm's locale-munging so that Perl itself is also affected.
authorTom Lane <[email protected]>
Tue, 18 Apr 2023 17:31:31 +0000 (13:31 -0400)
committerTom Lane <[email protected]>
Tue, 18 Apr 2023 17:31:46 +0000 (13:31 -0400)
Utils.pm has a BEGIN block that editorializes on the locale-related
environment variables, primarily in order to stabilize the behavior
of child programs.  It turns out that if the calling test script
has already done "use locale", this fails to affect the behavior
of Perl itself, causing locale behavior to be different between
Perl and child programs.  That breaks commit cd82e5c79's attempt
to deal with locale-specific behavior in psql.

To fix, we just need to call setlocale() to redo the calculation
of locale.

Per report from Aleksander Alekseev.  No back- for now, since
there are no locale-dependent TAP tests in prior branches, and
I'm not yet convinced that this won't have side-effects of its own.

Discussion: https://postgr.es/m/CAJ7c6TO9KpYYxoVVseWEQB5KtjWDkt8NfyAeKPcHoe2Jq+ykpw@mail.gmail.com

src/test/perl/PostgreSQL/Test/Utils.pm

index 9249954b4995f57c5278d2d8af7b510c0fbf0b93..f03d29309d974843300bca3c617019bc2236d9da 100644 (file)
@@ -55,6 +55,7 @@ use File::Spec;
 use File::stat qw(stat);
 use File::Temp ();
 use IPC::Run;
+use POSIX qw(locale_h);
 use PostgreSQL::Test::SimpleTee;
 
 # We need a version of Test::More recent enough to support subtests
@@ -103,6 +104,7 @@ BEGIN
    delete $ENV{LANGUAGE};
    delete $ENV{LC_ALL};
    $ENV{LC_MESSAGES} = 'C';
+   setlocale(LC_ALL, "");
 
    # This list should be kept in sync with pg_regress.c.
    my @envkeys = qw (