Discussion:
[Toybox] [PATCH] date.test: add some tests.
enh
2018-10-05 22:18:55 UTC
Permalink
These are reasonable examples I found in AOSP.

I also came across "today" (which is the same as the more obvious "now"),
"yesterday", "7 days ago" and "1 month ago". I'm not sure how far down
that rabbit hole we want to go. But these ones at least seem reasonable.
---
tests/date.test | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/tests/date.test b/tests/date.test
index be80d45..431b35a 100644
--- a/tests/date.test
+++ b/tests/date.test
@@ -13,6 +13,7 @@ testing "-d @0x123" "TZ=UTC date -d @0x123 2>&1"
"date: bad date '@0x123'\n" ""
testing "-d 06021234" "TZ=UTC date -d 06021234 2>&1" "Sun Jun 2
12:34:00 UTC 1900\n" "" ""
testing "-d 060212341982" "TZ=UTC date -d 060212341982 2>&1" "Sun Jun
2 12:34:00 UTC 1982\n" "" ""
testing "-d 123" "TZ=UTC date -d 123 2>&1" "date: bad date '123'\n" "" ""
+testing "-d 2018-10-04" "TZ=UTC date -d 2018-10-04 2>&1" "Thu Oct 4
00:00:00 UTC 2018\n" "" ""

# Test parsing 2- and 4-digit years.
testing "-d 1110143115.30" "TZ=UTC date -d 1110143115.30 2>&1" "Sun
Nov 10 14:31:30 UTC 1915\n" "" ""
@@ -32,3 +33,7 @@ testing "%%N" "touch -d
2012-01-23T12:34:56.123456789 f && date -r f +%Y%m%d-%H%
testing "trailing %" "touch -d 2012-01-23T12:34:56.123456789 f &&
date -r f +%Y%m%d-%H%M%S.%" "20120123-123456.%\n" "" ""
testing "just %" "touch -d 2012-01-23T12:34:56.123456789 f && date -r
f +%" "%\n" "" ""
rm -f f
+
+# Test embedded TZ to take a date in one time zone and display it in another.
+testing "TZ=" "TZ='America/Los_Angeles' date -d 'TZ=\"Europe/London\"
2018-10-04 08:00'" "Thu Oct 4 00:00:00 PDT 2018\n" "" ""
+testing "TZ= @" "TZ='America/Los_Angeles' date -d 'TZ=\"GMT\"
@1533427200'" "Sat Aug 4 17:00:00 PDT 2018\n" "" ""
--
2.19.0.605.g01d371f741-goog
enh
2018-10-05 22:19:19 UTC
Permalink
see: here's a much bigger can of worms for your weekend :-)
Post by enh
These are reasonable examples I found in AOSP.
I also came across "today" (which is the same as the more obvious "now"),
"yesterday", "7 days ago" and "1 month ago". I'm not sure how far down
that rabbit hole we want to go. But these ones at least seem reasonable.
---
tests/date.test | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/tests/date.test b/tests/date.test
index be80d45..431b35a 100644
--- a/tests/date.test
+++ b/tests/date.test
@@ -13,6 +13,7 @@ testing "-d @0x123" "TZ=UTC date -d @0x123 2>&1" "date: bad date '@0x123'\n" ""
testing "-d 06021234" "TZ=UTC date -d 06021234 2>&1" "Sun Jun 2 12:34:00 UTC 1900\n" "" ""
testing "-d 060212341982" "TZ=UTC date -d 060212341982 2>&1" "Sun Jun 2 12:34:00 UTC 1982\n" "" ""
testing "-d 123" "TZ=UTC date -d 123 2>&1" "date: bad date '123'\n" "" ""
+testing "-d 2018-10-04" "TZ=UTC date -d 2018-10-04 2>&1" "Thu Oct 4 00:00:00 UTC 2018\n" "" ""
# Test parsing 2- and 4-digit years.
testing "-d 1110143115.30" "TZ=UTC date -d 1110143115.30 2>&1" "Sun Nov 10 14:31:30 UTC 1915\n" "" ""
@@ -32,3 +33,7 @@ testing "%%N" "touch -d 2012-01-23T12:34:56.123456789 f && date -r f +%Y%m%d-%H%
testing "trailing %" "touch -d 2012-01-23T12:34:56.123456789 f && date -r f +%Y%m%d-%H%M%S.%" "20120123-123456.%\n" "" ""
testing "just %" "touch -d 2012-01-23T12:34:56.123456789 f && date -r f +%" "%\n" "" ""
rm -f f
+
+# Test embedded TZ to take a date in one time zone and display it in another.
+testing "TZ=" "TZ='America/Los_Angeles' date -d 'TZ=\"Europe/London\" 2018-10-04 08:00'" "Thu Oct 4 00:00:00 PDT 2018\n" "" ""
--
2.19.0.605.g01d371f741-goog
Rob Landley
2018-10-06 18:29:20 UTC
Permalink
Post by enh
see: here's a much bigger can of worms for your weekend :-)
I'm trying to cut a toybox release and a mkroot release, and over in mkroot I've
been fighting with adding x32 support (which broke my "short name" convention
for toolchains and required me to add plumbing to mcm-buildall.sh and _then_
doesn't work in the kernel for some reason...), and THEN when I built toybox
with the x32 toolchain it broke because timeout.c feeds &timeval.tv_usec to
xparsetime(long *frac) and this is the first field where suseconds_t is _not_
long (I just now noticed it's got its own type)...

Also, I really need to finish toys/example/demo_pty.c because testing stuff like
tab spacing not wrapping the screen for watch.c requires implementing a pty
master I can run tty programs under. (I should really do that for a proper less
test but that's subsumed under "ps test is hard to do because the background
context is constantly moving and is different each run"...)

It would also be really nice if I could figure out how to _not_ have to log in
to gmail's web interface to fish half your messages out of the spam folder (4
miscategorized just today, gmail _really_ hates you specifically for some reason).

My weekend's booked. Next weekend Fuzzy's in town for a fencing tournament and
crashing on my floor. Maybe the weekend after that...

Rob

P.S. it sounds like what you're testing there is mostly libc? "today" applies to
what how...?
Rob Landley
2018-10-06 18:20:06 UTC
Permalink
Post by enh
These are reasonable examples I found in AOSP.
+
+# Test embedded TZ to take a date in one time zone and display it in another.
+testing "TZ=" "TZ='America/Los_Angeles' date -d 'TZ=\"Europe/London\"
2018-10-04 08:00'" "Thu Oct 4 00:00:00 PDT 2018\n" "" ""
@1533427200'" "Sat Aug 4 17:00:00 PDT 2018\n" "" ""
Hmmm, slight concern that I'm not sure how many timezones we should expect to be
installed in a test environment.

I'm back poking at mkroot and trying to turn it into a test environment that can
run the full toybox test suite under qemu, so I can finally have some proper
tests for mount and insmod and such. It's a musl-based environment, and I dunno
what musl does about timezones? (Glibc needs horrible generation and files and
such, and uClibc _copied_glibc's_data_at_install_time_ off the build system,
which was just crazy from a licensing perspective.)

Hey Rich: musl timezones? Do I have to do anything special, or what?

Rob
Rich Felker
2018-10-06 20:46:18 UTC
Permalink
Post by Rob Landley
Post by enh
These are reasonable examples I found in AOSP.
+
+# Test embedded TZ to take a date in one time zone and display it in another.
+testing "TZ=" "TZ='America/Los_Angeles' date -d 'TZ=\"Europe/London\"
2018-10-04 08:00'" "Thu Oct 4 00:00:00 PDT 2018\n" "" ""
@1533427200'" "Sat Aug 4 17:00:00 PDT 2018\n" "" ""
Hmmm, slight concern that I'm not sure how many timezones we should expect to be
installed in a test environment.
You can use POSIX TZ strings rather than zoneinfo files for testing if
you don't know what will be installed. The format is:

stdoffset[dst[offset][,start[/time],end[/time]]]

with offsets in the format:

hh[:mm[:ss]]

start and end in the format:

Jn - one-based julian day number not counting leap days
n - zero-based julian day number counting leap days
Mm,n,d - the d'th day (0=Synday) of week n (1-5) of month m (1-12)

Optional /time specifies the hour of the dst change.

For example, current US/Eastern is:

TZ=EST5EDT,M3.2.0/2,M11.1.0/2

Full detail is here:

http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html#tag_08_03
Post by Rob Landley
I'm back poking at mkroot and trying to turn it into a test environment that can
run the full toybox test suite under qemu, so I can finally have some proper
tests for mount and insmod and such. It's a musl-based environment, and I dunno
what musl does about timezones? (Glibc needs horrible generation and files and
such, and uClibc _copied_glibc's_data_at_install_time_ off the build system,
which was just crazy from a licensing perspective.)
Hey Rich: musl timezones? Do I have to do anything special, or what?
Most implementations including glibc and musl (not sure about Bionic)
use the standard zoneinfo format and data from:

https://www.iana.org/time-zones

and, if you don't want to have them installed in the standard system
locations ([/usr]/share/zoneinfo; musl also searches /etc/zoneinfo)
they also support setting TZ to an absolute zoneinfo file pathname as
long as the program was not invoked suid/sgid/setcap.

Rich

Loading...