Pádraig Brady <[email protected]> writes: >> +# and that it uses it by default when no format string is given. >> +for locale in $(locale -a); do >> + export LC_ALL=$locale >> + date -d '2025-10-11T13:00' +"$(locale date_fmt)" > $locale.exp || fail=1 >> + date -d '2025-10-11T13:00' > $locale.out || fail=1 >> + compare $locale.exp $locale.out || fail=1 >> +done > > It might be a little overkill? > > $ locale -a | wc -l 890 > > Maybe `locale -a | shuf -n10`
It was fast on my system, at least. It is also good at testing strftime because I don't think we have coverage for the 'E' and 'O' flags. But testing 10 locales should be enough, so that is fine with me. > Also this outputs nothing: > $ date -d '2025-10-11T13:00' + > > I.e. we'd want to verify that `locale date_fmt` actually returns something, > as otherwise there would be a mismatch. I would hope that is never the case. But the systems locales are out of our control, so we can add that check. I pushed the attached v2 patch, which also addresses Grisha's comments. Thanks both for the review. Collin
>From 18405cb51a372a34785e6d5051b89e667000451c Mon Sep 17 00:00:00 2001 Message-ID: <18405cb51a372a34785e6d5051b89e667000451c.1766630550.git.collin.fu...@gmail.com> From: Collin Funk <[email protected]> Date: Tue, 23 Dec 2025 20:03:49 -0800 Subject: [PATCH v2] tests: date: improve locale tests * tests/date/date-locale-hour.sh: Test that the default format of 10 random supported locales is the same as 'locale date_fmt'. --- tests/date/date-locale-hour.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/date/date-locale-hour.sh b/tests/date/date-locale-hour.sh index 409091080..791d73f0d 100755 --- a/tests/date/date-locale-hour.sh +++ b/tests/date/date-locale-hour.sh @@ -56,5 +56,15 @@ for loc in "$LOCALE_FR_UTF8" 'en_US.UTF-8'; do esac done +# Make sure 'date' can use the format string given by 'locale date_fmt' +# and that it uses it by default when no format string is given. +for loc in $(locale -a | shuf -n 10); do + fmt=$(LC_ALL=$loc locale date_fmt) + if test -n "$fmt"; then + LC_ALL=$loc date -d '2025-10-11T13:00' +"$fmt" > $loc.exp || fail=1 + LC_ALL=$loc date -d '2025-10-11T13:00' > $loc.out || fail=1 + compare $loc.exp $loc.out || fail=1 + fi +done Exit $fail -- 2.52.0
