Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make/unit-tests make(1): add tests for error handlin...



details:   https://anonhg.NetBSD.org/src/rev/c5c2feddeb72
branches:  trunk
changeset: 945520:c5c2feddeb72
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Oct 31 19:48:23 2020 +0000

description:
make(1): add tests for error handling in the :gmtime variable modifier

diffstat:

 usr.bin/make/unit-tests/varmod-gmtime.exp |   9 +++++++
 usr.bin/make/unit-tests/varmod-gmtime.mk  |  36 ++++++++++++++++++++++++++++++-
 2 files changed, 44 insertions(+), 1 deletions(-)

diffs (72 lines):

diff -r a663a1b02684 -r c5c2feddeb72 usr.bin/make/unit-tests/varmod-gmtime.exp
--- a/usr.bin/make/unit-tests/varmod-gmtime.exp Sat Oct 31 18:41:07 2020 +0000
+++ b/usr.bin/make/unit-tests/varmod-gmtime.exp Sat Oct 31 19:48:23 2020 +0000
@@ -6,4 +6,13 @@
 mod-gmtime-indirect:
 make: Unknown modifier '1'
 
+parse-errors:
+: -1 becomes Wed Dec 31 23:59:59 1969.
+: 0 becomes ok.
+: 1 becomes Thu Jan  1 00:00:01 1970.
+: INT32_MAX becomes Tue Jan 19 03:14:07 2038.
+: INT32_MAX + 1 becomes Tue Jan 19 03:14:08 2038.
+: overflow becomes Wed Dec 31 23:59:59 1969.
+make: Unknown modifier 'e'
+: letter becomes .
 exit status 0
diff -r a663a1b02684 -r c5c2feddeb72 usr.bin/make/unit-tests/varmod-gmtime.mk
--- a/usr.bin/make/unit-tests/varmod-gmtime.mk  Sat Oct 31 18:41:07 2020 +0000
+++ b/usr.bin/make/unit-tests/varmod-gmtime.mk  Sat Oct 31 19:48:23 2020 +0000
@@ -1,10 +1,11 @@
-# $NetBSD: varmod-gmtime.mk,v 1.3 2020/10/29 18:59:43 rillig Exp $
+# $NetBSD: varmod-gmtime.mk,v 1.4 2020/10/31 19:48:23 rillig Exp $
 #
 # Tests for the :gmtime variable modifier, which formats a timestamp
 # using strftime(3).
 
 all:   mod-gmtime
 all:   mod-gmtime-indirect
+all:   parse-errors
 
 # Test for the default time format, %c.  Since the time always varies, it's
 # only possible to check for the general format here.  The names of the
@@ -39,5 +40,38 @@
        # ParseModifierPart, this would work.
        @echo ${%Y:L:gmtime=${:U1593536400}}
 
+parse-errors:
+       @echo $@:
+
+       # As of 2020-10-31, it is possible to pass negative time stamps
+       # to the :gmtime modifier, resulting in dates before 1970.
+       # Going back 50 years in the past is not a practical use case for
+       # make.
+       : -1 becomes ${:L:gmtime=-1}.
+
+       # 0 means now; to get consistent test results, the actual value has
+       # to be normalized.
+       : 0 becomes ${:L:gmtime=0:C,^... ... .. ..:..:.. 20..$,ok,W}.
+
+       : 1 becomes ${:L:gmtime=1}.
+
+       : INT32_MAX becomes ${:L:gmtime=2147483647}.
+
+       # This may be different if time_t is still a 32-bit signed integer.
+       : INT32_MAX + 1 becomes ${:L:gmtime=2147483648}.
+
+       # Integer overflow.
+       # Because this modifier is implemented using strtoul, the parsed
+       # time is ULONG_MAX, which gets converted to -1.  This results
+       # in a time stamp of the second before 1970.
+       : overflow becomes ${:L:gmtime=10000000000000000000000000000000}.
+
+       # As of 2020-10-31, there is no error handling while parsing the
+       # :gmtime modifier, thus no error message is printed.  Parsing
+       # stops after the '=', and the remaining string is parsed for
+       # more variable modifiers.  Because of the unknown modifier 'e',
+       # the whole variable value is discarded and thus not printed.
+       : letter becomes ${:L:gmtime=error}.
+
 all:
        @:;



Home | Main Index | Thread Index | Old Index