Module Name:    src
Committed By:   rillig
Date:           Mon Dec 21 20:35:17 UTC 2020

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

Log Message:
make(1): move tests for :gmtime to parse time

It's easier to have both the expressions and the expected values in a
single file.  This also allows for flexible handling of multiple
acceptable outputs, in this case for 32-bit time_t.


To generate a diff of this commit:
cvs rdiff -u -r1.254 -r1.255 src/usr.bin/make/unit-tests/Makefile
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/make/unit-tests/varmod-gmtime.exp
cvs rdiff -u -r1.6 -r1.7 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/Makefile
diff -u src/usr.bin/make/unit-tests/Makefile:1.254 src/usr.bin/make/unit-tests/Makefile:1.255
--- src/usr.bin/make/unit-tests/Makefile:1.254	Mon Dec 21 18:22:31 2020
+++ src/usr.bin/make/unit-tests/Makefile	Mon Dec 21 20:35:17 2020
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.254 2020/12/21 18:22:31 sjg Exp $
+# $NetBSD: Makefile,v 1.255 2020/12/21 20:35:17 rillig Exp $
 #
 # Unit tests for make(1)
 #
@@ -503,9 +503,6 @@ SED_CMDS.var-op-shell+=	\
 	-e 's,^${.SHELL:T}: [ 0-9:]*,,' \
 	-e '/command/s,No such.*,not found,'
 SED_CMDS.vardebug+=	-e 's,${.SHELL},</path/to/shell>,'
-SED_CMDS.varmod-gmtime+=	-e 's,Tue Jan 19 03:14:08 2038,<normalized>,'
-SED_CMDS.varmod-gmtime+=	${:D FreeBSD i386 still has 32-bit time_t. }
-SED_CMDS.varmod-gmtime+=	-e 's,Fri Dec 13 20:45:52 1901,<normalized>,'
 SED_CMDS.varmod-localtime+=	-e 's,Tue Jan 19 04:14:08 2038,<normalized>,'
 SED_CMDS.varmod-localtime+=	${:D FreeBSD i386 still has 32-bit time_t. }
 SED_CMDS.varmod-localtime+=	-e 's,Fri Dec 13 21:45:52 1901,<normalized>,'

Index: src/usr.bin/make/unit-tests/varmod-gmtime.exp
diff -u src/usr.bin/make/unit-tests/varmod-gmtime.exp:1.7 src/usr.bin/make/unit-tests/varmod-gmtime.exp:1.8
--- src/usr.bin/make/unit-tests/varmod-gmtime.exp:1.7	Mon Nov 30 21:10:15 2020
+++ src/usr.bin/make/unit-tests/varmod-gmtime.exp	Mon Dec 21 20:35:17 2020
@@ -1,27 +1,18 @@
-mod-gmtime:
-%Y
-2020
-%Y
-localtime == localtime
-mod-gmtime-indirect:
-make: Invalid time value: ${:U1593536400}}
+make: "varmod-gmtime.mk" line 57: Invalid time value: ${:U1593536400}} != "mtime=11593536400}"
 
-mtime=1593536400}
-parse-errors:
-make: Invalid time value: -1}.
+make: "varmod-gmtime.mk" line 57: Malformed conditional (${%Y:L:gmtime=${:U1593536400}} != "mtime=11593536400}")
+make: "varmod-gmtime.mk" line 67: Invalid time value: -1} != ""
 
-: -1 becomes mtime=-1}.
-make: Invalid time value:  1}.
+make: "varmod-gmtime.mk" line 67: Malformed conditional (${:L:gmtime=-1} != "")
+make: "varmod-gmtime.mk" line 76: Invalid time value:  1} != ""
 
-: space 1 becomes mtime= 1}.
-: 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 <normalized>.
-make: Invalid time value: 10000000000000000000000000000000}.
+make: "varmod-gmtime.mk" line 76: Malformed conditional (${:L:gmtime= 1} != "")
+make: "varmod-gmtime.mk" line 115: Invalid time value: 10000000000000000000000000000000} != ""
 
-: overflow becomes mtime=10000000000000000000000000000000}.
-make: Invalid time value: error}.
+make: "varmod-gmtime.mk" line 115: Malformed conditional (${:L:gmtime=10000000000000000000000000000000} != "")
+make: "varmod-gmtime.mk" line 126: Invalid time value: error} != ""
 
-: letter becomes mtime=error}.
-exit status 0
+make: "varmod-gmtime.mk" line 126: Malformed conditional (${:L:gmtime=error} != "")
+make: Fatal errors encountered -- cannot continue
+make: stopped in unit-tests
+exit status 1

Index: src/usr.bin/make/unit-tests/varmod-gmtime.mk
diff -u src/usr.bin/make/unit-tests/varmod-gmtime.mk:1.6 src/usr.bin/make/unit-tests/varmod-gmtime.mk:1.7
--- src/usr.bin/make/unit-tests/varmod-gmtime.mk:1.6	Sat Oct 31 20:30:06 2020
+++ src/usr.bin/make/unit-tests/varmod-gmtime.mk	Mon Dec 21 20:35:17 2020
@@ -1,11 +1,8 @@
-# $NetBSD: varmod-gmtime.mk,v 1.6 2020/10/31 20:30:06 rillig Exp $
+# $NetBSD: varmod-gmtime.mk,v 1.7 2020/12/21 20:35:17 rillig Exp $
 #
 # Tests for the :gmtime variable modifier, which formats a timestamp
 # using strftime(3) in UTC.
 
-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
@@ -15,73 +12,122 @@ all:	parse-errors
 .  error
 .endif
 
-mod-gmtime:
-	@echo $@:
 
-	# modifier name too short
-	@echo ${%Y:L:gmtim=1593536400}
+# modifier name too short, falling back to the SysV modifier.
+.if ${%Y:L:gmtim=1593536400} != "%Y"
+.  error
+.endif
+
+
+# 2020-07-01T00:00:00Z
+.if ${%Y:L:gmtime=1593536400} != "2020"
+.  error
+.endif
+
+
+# modifier name too long, falling back to the SysV modifier.
+.if ${%Y:L:gmtimer=1593536400} != "%Y"
+.  error
+.endif
+
+
+# If the modifier name is not matched exactly, fall back to the
+# :from=to modifier.
+.if ${gmtime:L:gm%=local%} != "localtime"
+.  error
+.endif
+
+
+# As of 2020-08-16, it is not possible to pass the seconds via a
+# variable expression.  This is because parsing of the :gmtime
+# modifier stops at the '$' and returns to ApplyModifiers.
+#
+# There, a colon would be skipped but not a dollar.
+# Parsing therefore continues at the '$' of the ${:U159...}, looking
+# for an ordinary variable modifier.
+#
+# At this point, the ${:U} is expanded and interpreted as a variable
+# modifier, which results in the error message "Unknown modifier '1'".
+#
+# If ApplyModifier_Gmtime were to pass its argument through
+# ParseModifierPart, this would work.
+#
+# XXX: Where does the empty line 4 in varmod-gmtime.exp come from?
+# TODO: Remove the \n from "Invalid time value: %s\n" in var.c.
+.if ${%Y:L:gmtime=${:U1593536400}} != "mtime=11593536400}"
+.  error
+.endif
+
+
+# Before var.c 1.631 from 2020-10-31 21:40:20, it was 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.  Therefore, since var.c 1.631, negative time stamps produce a
+# parse error.
+.if ${:L:gmtime=-1} != ""
+.  error
+.else
+.  error
+.endif
+
+
+# Spaces were allowed before var.c 1.631, not because it would make sense
+# but just as a side-effect from using strtoul.
+.if ${:L:gmtime= 1} != ""
+.  error
+.endif
+
+
+# 0 means now; this differs from GNode.mtime, where a 0 means nonexistent.
+# Since "now" constantly changes, the strongest possible test is to match the
+# resulting pattern.
+.if !${:L:gmtime=0:tW:M??? ??? ?? ??\:??\:?? 20??}
+.  error
+.endif
+
+
+.if ${:L:gmtime=1} != "Thu Jan  1 00:00:01 1970"
+.  error
+.endif
+
+
+# INT32_MAX
+.if ${:L:gmtime=2147483647} != "Tue Jan 19 03:14:07 2038"
+.  error
+.endif
+
+
+.if ${:L:gmtime=2147483648} == "Tue Jan 19 03:14:08 2038"
+# All systems that have unsigned time_t or 64-bit time_t.
+.elif ${:L:gmtime=2147483648} != "Fri Dec 13 20:45:52 1901"
+# FreeBSD-12.0-i386 still has 32-bit signed time_t.
+.else
+.  error
+.endif
+
+
+# Integer overflow, at least before var.c 1.631 from 2020-10-31.
+# Because this modifier is implemented using strtoul, the parsed time was
+# ULONG_MAX, which got converted to -1.  This resulted in a time stamp of
+# the second before 1970.
+#
+# Since var.c 1.613, the overflow is detected and produces a parse error.
+.if ${:L:gmtime=10000000000000000000000000000000} != ""
+.  error
+.else
+.  error
+.endif
+
+# Before var.c 1.613 from 2020-10-31, there was no error handling while
+# parsing the :gmtime modifier, thus no error message is printed.  Parsing
+# stopped after the '=', and the remaining string was parsed for more variable
+# modifiers.  Because of the unknown modifier 'e' from the 'error', the whole
+# variable value was discarded and thus not printed.
+.if ${:L:gmtime=error} != ""
+.  error
+.else
+.  error
+.endif
 
-	# 2020-07-01T00:00:00Z
-	@echo ${%Y:L:gmtime=1593536400}
 
-	# modifier name too long
-	@echo ${%Y:L:gmtimer=1593536400}
-
-	# If the modifier name is not matched exactly, fall back to the
-	# :from=to modifier.
-	@echo ${gmtime:L:gm%=local%} == localtime
-
-mod-gmtime-indirect:
-	@echo $@:
-
-	# As of 2020-08-16, it is not possible to pass the seconds via a
-	# variable expression.  This is because parsing of the :gmtime
-	# modifier stops at the '$' and returns to ApplyModifiers.
-	#
-	# There, a colon would be skipped but not a dollar.
-	# Parsing therefore continues at the '$' of the ${:U159...}, looking
-	# for an ordinary variable modifier.
-	#
-	# At this point, the ${:U} is expanded and interpreted as a variable
-	# modifier, which results in the error message "Unknown modifier '1'".
-	#
-	# If ApplyModifier_Gmtime were to pass its argument through
-	# 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}.
-
-	# Spaces are allowed, not because it would make sense but just as
-	# a side-effect from using strtoul.
-	: space 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