]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tests: du: test --block-size with thousands separators
authorCollin Funk <collin.funk1@gmail.com>
Fri, 31 Jul 2026 06:30:05 +0000 (23:30 -0700)
committerCollin Funk <collin.funk1@gmail.com>
Sat, 1 Aug 2026 04:54:29 +0000 (21:54 -0700)
* tests/du/block-size.sh (test_unit): Test that the locales thousands
separator is used if we can determine it.

tests/du/block-size.sh

index 4d2b93b3b1efbbfe5eb82b9e0d3d7f0553210698..63f5da4361ccceae674f38a5d5da8da03b829ab7 100755 (executable)
@@ -56,16 +56,39 @@ test_unit ()
   # When there is a prefix of 1, the unit is not printed.  Setup a file
   # to compare to.
   sed 's/^\([0-9][0-9]*\)'"$upper"'/\1/g' <exp >exp1 || framework_failure_
-  for opt in BLOCK_SIZE -B --block-size=; do
-    for c in $lower $upper; do
-      for prefix in '' 1; do
-        case $opt in
-          -*) env=; arg=$opt$prefix$c ;;
-          *) arg=; env=$opt=$prefix$c ;;
-        esac
-        env $env du -A $arg 1* >out 2>err || fail=1
-        compare exp$prefix out || fail=1
-        compare /dev/null err || fail=1
+  for loc in C "$LOCALE_FR" "$LOCALE_FR_UTF8"; do
+    test -z "$loc" && continue
+    if test $loc != C; then
+      thousands_sep=$(LC_ALL=$loc locale thousands_sep)
+      grouping=$(LC_ALL=$loc locale grouping)
+      test -z "$thousands_sep" && continue
+      test "$grouping" != 3 && continue
+    fi
+    for f in exp exp1; do
+      LC_ALL=$loc \
+        sed 's/^\([0-9][0-9]*\)\([0-9]\{3\}\)/\1'"$thousands_sep"'\2/g' $f \
+          >$loc$f || framework_failure_
+    done
+    for opt in BLOCK_SIZE -B --block-size=; do
+      for c in $lower $upper; do
+        for prefix1 in '' "'"; do
+          # Without the apostrophe thousands separators aren't used,
+          # regardless of locale.
+          if test $loc = C || test -z "$prefix1"; then
+            exp=exp
+          else
+            exp="$loc"exp
+          fi
+          for prefix2 in '' 1; do
+            case $opt in
+              -*) env=; arg=$opt$prefix1$prefix2$c ;;
+              *) arg=; env=$opt=$prefix1$prefix2$c ;;
+            esac
+            env LC_ALL=$loc $env du -A $arg 1* >out 2>err || fail=1
+            compare $exp$prefix2 out || fail=1
+            compare /dev/null err || fail=1
+          done
+        done
       done
     done
   done