aboutsummaryrefslogtreecommitdiffstats
path: root/test/strftime.awk
diff options
context:
space:
mode:
authorAndrew J. Schorr <aschorr@telemetry-investments.com>2014-04-13 14:30:56 -0400
committerAndrew J. Schorr <aschorr@telemetry-investments.com>2014-04-13 14:30:56 -0400
commit94e3f93395de538d73826e128281a3ea9591a5a9 (patch)
tree45257e4b024537c5e0e5a3037a99ea9765583c99 /test/strftime.awk
parentc4300d657ba49db0b6d0f0884f41a29622edc58b (diff)
parenta4b59faf911743b30f2e6e979c4f9c1ea0669ac3 (diff)
downloadegawk-94e3f93395de538d73826e128281a3ea9591a5a9.tar.gz
egawk-94e3f93395de538d73826e128281a3ea9591a5a9.tar.bz2
egawk-94e3f93395de538d73826e128281a3ea9591a5a9.zip
Merge branch 'master' into select
Diffstat (limited to 'test/strftime.awk')
-rw-r--r--test/strftime.awk42
1 files changed, 29 insertions, 13 deletions
diff --git a/test/strftime.awk b/test/strftime.awk
index 775cd4e5..f1276c15 100644
--- a/test/strftime.awk
+++ b/test/strftime.awk
@@ -1,19 +1,35 @@
# strftime.awk ; test the strftime code
#
# input is the output of `date', see Makefile.in
-#
-# The mucking about with $0 and $N is to avoid problems
-# on cygwin, where the timezone field is empty and there
-# are two consecutive blanks.
-# Additional mucking about to lop off the seconds field;
-# helps decrease chance of difference due to a second boundary
+BEGIN {
+ maxtries = 10
+ # On DOS/Windows, DATECMD is set by the Makefile to point to
+ # Unix-like 'date' command.
+ datecmd = DATECMD
+ if (datecmd == "")
+ datecmd = "date"
+ fmt = "%a %b %e %H:%M:%S %Z %Y"
-{
- $3 = sprintf("%02d", $3 + 0)
- $4 = substr($4, 1, 5)
- print > "strftime.ok"
- $0 = strftime("%a %b %d %H:%M %Z %Y")
- $NF = $NF
- print > OUTPUT
+ # loop until before equals after, thereby protecting
+ # against a race condition where the seconds field might have
+ # incremented between running date and strftime
+ i = 0
+ while (1) {
+ if (++i > maxtries) {
+ printf "Warning: this system is so slow that after %d attempts, we could never get two sequential invocations of strftime to give the same result!\n", maxtries > "/dev/stderr"
+ break
+ }
+ before = strftime(fmt)
+ datecmd | getline sd
+ after = strftime(fmt)
+ close(datecmd)
+ if (before == after) {
+ if (i > 1)
+ printf "Notice: it took %d loops to get the before and after strftime values to match\n", i > "/dev/stderr"
+ break
+ }
+ }
+ print sd > "strftime.ok"
+ print after > OUTPUT
}