]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tests: fix new date/resolution.sh test on macOS
authorPádraig Brady <P@draigBrady.com>
Tue, 28 Oct 2025 12:52:55 +0000 (12:52 +0000)
committerPádraig Brady <P@draigBrady.com>
Tue, 28 Oct 2025 12:56:26 +0000 (12:56 +0000)
* tests/date/resolution.sh: Fix comparison on systems with less than
nano second reslution, where we use sed to discard the redundant
trailing zeros output by date --resolution.
Reported by Bruno Haible on macOS.

tests/date/resolution.sh

index 730983dc99397a54a030de300f5b5426ca413e16..4fbf4501f093c94b076c3c91a23e3f4e6e28cc92 100755 (executable)
 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
 print_ver_ date
 
-# Ensure --resolution is supported
+# Ensure --resolution is supported (prints to full nano second resolution)
 res=$(date --resolution) || fail=1
 
-# Ensure %-N format is supported
-subsec1=$(printf "%s" "$res" | cut -d. -f2- | wc -c) || framework_failure_
+# Ensure %-N format is supported (prints to most concise resolution)
+subsec1=$(printf '%s\n' "$res" | sed 's/.*\.//; s/0*$//' | wc -c) ||
+  framework_failure_
 subsec2=$(date +%-N | wc -c) || framework_failure_
 test "$subsec1" = "$subsec2" || fail=1