Module Name:    src
Committed By:   rillig
Date:           Sat Oct 31 19:48:23 UTC 2020

Modified Files:
        src/usr.bin/make/unit-tests: varmod-gmtime.exp varmod-gmtime.mk

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


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/varmod-gmtime.exp
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/varmod-gmtime.mk

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/make/unit-tests/varmod-gmtime.exp
diff -u src/usr.bin/make/unit-tests/varmod-gmtime.exp:1.2 src/usr.bin/make/unit-tests/varmod-gmtime.exp:1.3
--- src/usr.bin/make/unit-tests/varmod-gmtime.exp:1.2	Sun Aug 16 12:48:55 2020
+++ src/usr.bin/make/unit-tests/varmod-gmtime.exp	Sat Oct 31 19:48:23 2020
@@ -6,4 +6,13 @@ mod-gmtime:
 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

Index: src/usr.bin/make/unit-tests/varmod-gmtime.mk
diff -u src/usr.bin/make/unit-tests/varmod-gmtime.mk:1.3 src/usr.bin/make/unit-tests/varmod-gmtime.mk:1.4
--- src/usr.bin/make/unit-tests/varmod-gmtime.mk:1.3	Thu Oct 29 18:59:43 2020
+++ src/usr.bin/make/unit-tests/varmod-gmtime.mk	Sat Oct 31 19:48:23 2020
@@ -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 @@ mod-gmtime-indirect:
 	# 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:
 	@:;

Reply via email to