From 4a29be29401b7e10c8d628eb6469f41249b0c771 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1draig=20Brady?= Date: Wed, 27 Dec 2023 22:47:48 +0000 Subject: [PATCH 1/3] tests: run locale tests on more systems * tests/misc/numfmt.pl: Determine the thousands grouping character in use, rather than skipping locale tests when it's not a space. For example fr_FR.UTF-8 uses "NARROW NO-BREAK SPACE" as the grouping char on modern glibc systems at least. * tests/sort/sort-h-thousands-sep.sh: Likewise. --- tests/misc/numfmt.pl | 28 +++++++++++++++++++--------- tests/sort/sort-h-thousands-sep.sh | 23 ++++++++++++----------- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/tests/misc/numfmt.pl b/tests/misc/numfmt.pl index 3047f806d..b54f827c3 100755 --- a/tests/misc/numfmt.pl +++ b/tests/misc/numfmt.pl @@ -1011,6 +1011,15 @@ my @Limit_Tests = (system "$prog ---debug 1 2>&1|grep 'MAX_UNSCALED_DIGITS: 18' > /dev/null") == 0 and push @Tests, @Limit_Tests; +my $lg = ' '; +if ($locale ne 'C') + { + open(LOC_GRP, "env LC_ALL=$locale printf \"%'d\" 1111|tr -d 1|") + or die "Can't fork command: $!"; + $lg = ; + close(LOC_GRP) || die "Failed to read locale grouping from printf"; + } + my @Locale_Tests = ( # Locale that supports grouping, but without '--grouping' parameter @@ -1018,11 +1027,12 @@ my @Locale_Tests = {ENV=>"LC_ALL=$locale"}], # Locale with grouping - ['lcl-grp-2', '--from=si --grouping 7M', {OUT=>"7 000 000"}, + ['lcl-grp-2', '--from=si --grouping 7M', {OUT=>"7${lg}000${lg}000"}, {ENV=>"LC_ALL=$locale"}], # Locale with grouping and debug - no debug warning message - ['lcl-grp-3', '--from=si --debug --grouping 7M', {OUT=>"7 000 000"}, + ['lcl-grp-3', '--from=si --debug --grouping 7M', + {OUT=>"7${lg}000${lg}000"}, {ENV=>"LC_ALL=$locale"}], # Input with locale'd decimal-point @@ -1033,21 +1043,21 @@ my @Locale_Tests = {ENV=>"LC_ALL=$locale"}], # Format + Grouping - ['lcl-fmt-1', '--format "%\'f" 50000',{OUT=>"50 000"}, + ['lcl-fmt-1', '--format "%\'f" 50000',{OUT=>"50${lg}000"}, {ENV=>"LC_ALL=$locale"}], - ['lcl-fmt-2', '--format "--%\'10f--" 50000', {OUT=>"-- 50 000--"}, + ['lcl-fmt-2', '--format "--%\'10f--" 50000', {OUT=>"-- 50${lg}000--"}, {ENV=>"LC_ALL=$locale"}], - ['lcl-fmt-3', '--format "--%\'-10f--" 50000',{OUT=>"--50 000 --"}, + ['lcl-fmt-3', '--format "--%\'-10f--" 50000',{OUT=>"--50${lg}000 --"}, {ENV=>"LC_ALL=$locale"}], ['lcl-fmt-4', '--format "--%-10f--" --to=si 5000000', {OUT=>"--5,0M --"}, {ENV=>"LC_ALL=$locale"}], # handle zero/grouping in combination - ['lcl-fmt-5', '--format="%\'06f" 1234',{OUT=>"01 234"}, + ['lcl-fmt-5', '--format="%\'06f" 1234',{OUT=>"01${lg}234"}, {ENV=>"LC_ALL=$locale"}], - ['lcl-fmt-6', '--format="%0\'6f" 1234',{OUT=>"01 234"}, + ['lcl-fmt-6', '--format="%0\'6f" 1234',{OUT=>"01${lg}234"}, {ENV=>"LC_ALL=$locale"}], - ['lcl-fmt-7', '--format="%0\'\'6f" 1234',{OUT=>"01 234"}, + ['lcl-fmt-7', '--format="%0\'\'6f" 1234',{OUT=>"01${lg}234"}, {ENV=>"LC_ALL=$locale"}], ); @@ -1059,7 +1069,7 @@ if ($locale ne 'C') or die "Can't fork command: $!"; my $loc_num = ; close(LOC_NUM) || die "Failed to read grouped number from printf"; - if ($loc_num ne '1 234') + if ($loc_num ne "1${lg}234") { warn "skipping locale grouping tests as 1234 groups like $loc_num\n"; $locale = 'C'; diff --git a/tests/sort/sort-h-thousands-sep.sh b/tests/sort/sort-h-thousands-sep.sh index 5d1ff4f33..447f99f5c 100755 --- a/tests/sort/sort-h-thousands-sep.sh +++ b/tests/sort/sort-h-thousands-sep.sh @@ -21,25 +21,26 @@ print_ver_ sort TEST_LOCALE='sv_SE' -test "$(LC_ALL="$TEST_LOCALE" locale thousands_sep)" = ' ' || +lg="$(LC_ALL="$TEST_LOCALE" locale thousands_sep)" +test "$lg" || skip_ 'The Swedish locale with blank thousands separator is unavailable.' tee exp1 exp3 > in << _EOF_ -1 1k 1 M 4 003 1M -2k 2M 2 k 4 002 2 -3M 3 3 G 4 001 3k +1 1k 1 M 4${lg}003 1M +2k 2M 2 k 4${lg}002 2 +3M 3 3 G 4${lg}001 3k _EOF_ - +cp in /tmp/pb.in cat > exp2 << _EOF_ -3M 3 3 G 4 001 3k -1 1k 1 M 4 003 1M -2k 2M 2 k 4 002 2 +3M 3 3 G 4${lg}001 3k +1 1k 1 M 4${lg}003 1M +2k 2M 2 k 4${lg}002 2 _EOF_ cat > exp5 << _EOF_ -3M 3 3 G 4 001 3k -2k 2M 2 k 4 002 2 -1 1k 1 M 4 003 1M +3M 3 3 G 4${lg}001 3k +2k 2M 2 k 4${lg}002 2 +1 1k 1 M 4${lg}003 1M _EOF_ for i in 1 2 3 5; do -- 2.43.0