diff options
author | Elliott Hughes <enh@google.com> | 2020-01-06 13:34:35 -0800 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2020-01-06 19:53:25 -0600 |
commit | 5854c801a718e92504114dec21038d740498dd65 (patch) | |
tree | 621b71cde993d5f2c3f03e608c556711dcbaa1e2 | |
parent | c25ff2dde84d2af5744a1dc7d0dbd2c14cbaae62 (diff) | |
download | toybox-5854c801a718e92504114dec21038d740498dd65.tar.gz |
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).
-rw-r--r-- | tests/date.test | 4 |
1 files 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" "" "" |