]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tests: run locale tests on more systems
authorPádraig Brady <P@draigBrady.com>
Wed, 27 Dec 2023 22:47:48 +0000 (22:47 +0000)
committerPádraig Brady <P@draigBrady.com>
Fri, 29 Dec 2023 18:04:29 +0000 (18:04 +0000)
* 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
tests/sort/sort-h-thousands-sep.sh

index 3047f806dbef4329eb37f0b8cccb114baf839f48..b54f827c3943e9eb3dc11c216541f51a31c7703a 100755 (executable)
@@ -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 = <LOC_GRP>;
+    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 = <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';
index 5d1ff4f33d529d74f79fd6495f5a8e80a0b73b11..43d187fa93af1d3336eb270574dce14f8ce692b0 100755 (executable)
@@ -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_
 
 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