diff options
author | Juergen Kahrs <Juergen.Kahrs@googlemail.com> | 2014-06-24 13:18:33 +0200 |
---|---|---|
committer | Juergen Kahrs <Juergen.Kahrs@googlemail.com> | 2014-06-24 13:18:33 +0200 |
commit | f1245d04a9f076773c60499b468f44ed9c91b59b (patch) | |
tree | 2b49234400150bfaac7ebf8c017562300edc7471 /test/strftime.awk | |
parent | ee9707cc44eea3ca64cb71666ac3e8ed26a3bb7f (diff) | |
parent | 78ded8ee8f11a321c96417e7d02dac2f5723a221 (diff) | |
download | egawk-f1245d04a9f076773c60499b468f44ed9c91b59b.tar.gz egawk-f1245d04a9f076773c60499b468f44ed9c91b59b.tar.bz2 egawk-f1245d04a9f076773c60499b468f44ed9c91b59b.zip |
Merge remote-tracking branch 'origin/master' into cmake
Diffstat (limited to 'test/strftime.awk')
-rw-r--r-- | test/strftime.awk | 42 |
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 } |