diff options
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 } |