Skip to content

Commit

Permalink
Use locale pragma instead of POSIX::set_locale()
Browse files Browse the repository at this point in the history
The Pragma is more likely to do the right thing, as confirmed by new
tests, which fail with the use of the French locale when using
`set_locale` and now succeed with `use locale`.

Resolves #806.
  • Loading branch information
theory committed Dec 30, 2023
1 parent 7edc536 commit 78b4ead
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 22 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/os.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
include:
- { icon: 🐧, os: ubuntu, name: Linux }
- { icon: 🍎, os: macos, name: macOS }
- { icon: 🪟, os: windows, name: Windows }
# - { icon: 🪟, os: windows, name: Windows }
name: ${{ matrix.icon }} ${{ matrix.name }}
runs-on: ${{ matrix.os }}-latest
steps:
Expand All @@ -24,14 +24,19 @@ jobs:
uses: shogo82148/actions-setup-perl@v1
with: { perl-version: latest }
- run: perl -V
- if: runner.os == 'Linux'
name: Install Locales
run: |
sudo apt-get update -qq
sudo env DEBIAN_FRONTEND=noninteractive apt-get install -qq locales-all aspell-en libicu-dev gettext software-properties-common
- name: Cache CPAN Modules
uses: actions/cache@v3
with:
path: local
key: perl-${{ steps.perl.outputs.perl-hash }}
- run: cpm install --verbose --show-build-log-on-failure --no-test --with-recommends ExtUtils::MakeMaker List::MoreUtils::XS
# Remove Locale::TextDomain if https://github.com/gflohr/libintl-perl/issues/7 fixed and released.
- if: ${{ matrix.os == 'windows' }}
- if: runner.os == 'Windows'
run: cpm install --verbose --show-build-log-on-failure --no-test --with-recommends Encode Win32::Console::ANSI Win32API::Net Win32::Locale Win32::ShellQuote DateTime::TimeZone::Local::Win32 Locale::[email protected]
- run: cpm install --verbose --show-build-log-on-failure --no-test --with-recommends --cpanfile dist/cpanfile
- run: cpm install --verbose --show-build-log-on-failure --no-test --with-recommends Test::Spelling Test::Pod Test::Pod::Coverage
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/perl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,18 @@ jobs:
uses: shogo82148/actions-setup-perl@v1
with: { perl-version: "${{ matrix.perl }}" }
- run: perl -V
- if: runner.os == 'Linux'
name: Install Locales
run: |
sudo apt-get update -qq
sudo env DEBIAN_FRONTEND=noninteractive apt-get install -qq locales-all aspell-en libicu-dev gettext software-properties-common
- name: Cache CPAN Modules
uses: actions/cache@v3
with:
path: local
key: perl-${{ steps.perl.outputs.perl-hash }}
# Remove Locale::TextDomain if https://github.com/gflohr/libintl-perl/issues/7 fixed and released.
- if: ${{ matrix.os[1] == 'windows' }}
- if: runner.os == 'Windows
run: cpm install --verbose --show-build-log-on-failure --no-test --with-recommends Encode Win32::Console::ANSI Win32API::Net Win32::Locale Win32::ShellQuote DateTime::TimeZone::Local::Win32 Locale::[email protected]
- run: cpm install --verbose --show-build-log-on-failure --no-test --with-recommends --cpanfile dist/cpanfile
- run: cpm install --verbose --show-build-log-on-failure --no-test --with-recommends Test::Spelling Test::Pod Test::Pod::Coverage
Expand Down
3 changes: 3 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ Revision history for Perl extension App::Sqitch
(#795)!
- Fixed Oracle and Firebird test failures due to incorrect use of `chmod`.
Thanks to Slaven Rezić for the report and the fix (#807)!
- Updated the locale configuration to fix issues in more recent versions
of Perl, and added tests to ensure that the sqitch CLI executes and
properly emits localized messages.

1.4.0 2023-08-01T23:37:30Z
- Fixed Snowflake warehouse and role setup to properly quote identifiers
Expand Down
11 changes: 1 addition & 10 deletions bin/sqitch
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
#!perl -w -CAS

# VERSION
use POSIX qw(setlocale);
BEGIN {
if ($^O eq 'MSWin32') {
require Win32::Locale;
setlocale POSIX::LC_ALL, Win32::Locale::get_locale();
} else {
setlocale POSIX::LC_ALL, '';
}
}
use locale;
use App::Sqitch;

exit App::Sqitch->go;
10 changes: 1 addition & 9 deletions t/sqitch
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
#!/usr/bin/env perl -CAS

use POSIX qw(setlocale);
BEGIN {
if ($^O eq 'MSWin32') {
require Win32::Locale;
setlocale POSIX::LC_ALL, Win32::Locale::get_locale();
} else {
setlocale POSIX::LC_ALL, '';
}
}
use locale;
use FindBin;
use lib "$FindBin::Bin/../lib";
use App::Sqitch;
Expand Down
33 changes: 33 additions & 0 deletions xt/release/cli.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/perl -w

use strict;
use warnings;
use Test::More tests => 3;
use File::Spec;
use Capture::Tiny qw(:all);

# LANG=de_DE.UTF-8 perl -Ilib -CAS -I. bin/sqitch help
my @cli = (qw(-Ilib -CAS -I.), File::Spec->catfile(qw(bin sqitch)));

# Each locale must be installed on the local system.
for my $tc (
{ lang => '', err => q{"nonesuch" is not a valid command} },
{ lang => 'en_US', err => q{"nonesuch" is not a valid command} },
{ lang => 'fr_FR', err => q{"nonesuch" n'est pas une commande valide} },
) {
subtest $tc->{lang} || 'default' => sub {
local $ENV{LANG} = "$tc->{lang}.UTF-8" if $tc->{lang};

# Test successful run.
my ($stdout, $stderr, $exit) = capture { system $^X, @cli, 'help' };
is $exit >> 8, 0, 'Should have exited normally';
like $stdout, qr/\AUsage\b/, 'Should have usage statement in STDOUT';
is $stderr, '', 'Should have no STDERR';

# Test localized error.
($stdout, $stderr, $exit) = capture { system $^X, @cli, 'nonesuch' };
is $stdout, '', 'Should have no STDOUT';
like $stderr, qr/\A\Q$tc->{err}/,
'Should have localized error message in STDERR';
};
}

0 comments on commit 78b4ead

Please sign in to comment.