From 5854c801a718e92504114dec21038d740498dd65 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Mon, 6 Jan 2020 13:34:35 -0800 Subject: date.test: defuse a time bomb. One of these tests fails in the gap between the locale it's run in changing the year and Europe/Berlin's changeover (caught by our automated testing, which tends to celebrate every new year by finding mistakes in tests like this). Another test has been failing consistently since 2020 because the default date output format includes the day of the week. Rather than implement Zeller's Congruence in the shell, explicitly use a format that doesn't include the day of the week for that test (and reuse the now-fixed calculation of the current year used by the other year-sensitive test). --- tests/date.test | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/date.test b/tests/date.test index 3be10425..2b865349 100644 --- a/tests/date.test +++ b/tests/date.test @@ -7,6 +7,7 @@ # Use a consistent TZ for these tests, but not GMT/UTC because that # makes mistakes harder to spot. tz=Europe/Berlin +this_year=$(TZ=$tz date +%Y) # Unix date parsing. testing "-d @0" "TZ=$tz date -d @0" "Thu Jan 1 01:00:00 CET 1970\n" "" "" @@ -16,7 +17,7 @@ testing "-d @0x123 invalid" "TZ=$tz date -d @0x123 2>/dev/null || echo expected # All toyonly because coreutils rejects POSIX format dates supplied to -d. # These expected values are from running on the host without -d (not as root!). toyonly testing "-d MMDDhhmm" \ - "TZ=$tz date -d 06021234" "Sun Jun 2 12:34:00 CEST $(date +%Y)\n" "" "" + "TZ=$tz date -d 06021234 +'%F %T'" "$this_year-06-02 12:34:00\n" "" "" toyonly testing "-d MMDDhhmmYY.SS" \ "TZ=$tz date -d 1110143115.30" "Tue Nov 10 14:31:30 CET 2015\n" "" "" # busybox thinks this is the year 603 (ISO time 0602-12-34 19:82 with out of range fields normalized). @@ -35,7 +36,6 @@ testing "Unix time missing @" "TZ=$tz date 1438053157 2>/dev/null || echo no" \ "no\n" "" "" # Test just hour and minute (accepted by coreutils and busybox, presumably for setting the time). -this_year=$(date +%Y) testing "-d 12:34" 'TZ=UTC date -d 12:34 | grep -q " 12:34:00 UTC $this_year" && echo OK' "OK\n" "" "" testing "-d 12:34:56" 'TZ=UTC date -d 12:34:56 | grep -q " 12:34:56 UTC $this_year" && echo OK' "OK\n" "" "" -- cgit v1.2.3