Module Name: src
Committed By: rillig
Date: Thu Aug 17 18:48:33 UTC 2023
Modified Files:
src/usr.bin/make/unit-tests: Makefile varmod-mtime.exp varmod-mtime.mk
Log Message:
tests/make: extend tests for the ':mtime' modifier
To generate a diff of this commit:
cvs rdiff -u -r1.339 -r1.340 src/usr.bin/make/unit-tests/Makefile
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/varmod-mtime.exp \
src/usr.bin/make/unit-tests/varmod-mtime.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.339 src/usr.bin/make/unit-tests/Makefile:1.340
--- src/usr.bin/make/unit-tests/Makefile:1.339 Tue Jun 20 09:25:34 2023
+++ src/usr.bin/make/unit-tests/Makefile Thu Aug 17 18:48:32 2023
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.339 2023/06/20 09:25:34 rillig Exp $
+# $NetBSD: Makefile,v 1.340 2023/08/17 18:48:32 rillig Exp $
#
# Unit tests for make(1)
#
@@ -559,6 +559,7 @@ SED_CMDS.suff-transform-debug+= ${STD_SE
SED_CMDS.var-op-shell+= ${STD_SED_CMDS.shell}
SED_CMDS.var-op-shell+= -e '/command/s,No such.*,not found,'
SED_CMDS.vardebug+= -e 's,${.SHELL},</path/to/shell>,'
+SED_CMDS.varmod-mtime+= -e "s,': .*,': <ENOENT>,"
SED_CMDS.varmod-subst-regex+= ${STD_SED_CMDS.regex}
SED_CMDS.varparse-errors+= ${STD_SED_CMDS.timestamp}
SED_CMDS.varname-dot-make-meta-ignore_filter+= ${SED_CMDS.meta-ignore}
Index: src/usr.bin/make/unit-tests/varmod-mtime.exp
diff -u src/usr.bin/make/unit-tests/varmod-mtime.exp:1.1 src/usr.bin/make/unit-tests/varmod-mtime.exp:1.2
--- src/usr.bin/make/unit-tests/varmod-mtime.exp:1.1 Tue May 9 20:14:27 2023
+++ src/usr.bin/make/unit-tests/varmod-mtime.exp Thu Aug 17 18:48:32 2023
@@ -1 +1,8 @@
-exit status 0
+make: "varmod-mtime.mk" line 58: Cannot determine mtime for 'no/such/file1': <ENOENT>
+make: "varmod-mtime.mk" line 58: Cannot determine mtime for 'no/such/file2': <ENOENT>
+make: "varmod-mtime.mk" line 58: Malformed conditional (${no/such/file1 no/such/file2:L:mtime=error})
+make: "varmod-mtime.mk" line 69: Unknown modifier "handler-no"
+make: "varmod-mtime.mk" line 69: Malformed conditional (${MAKEFILE:mtime=errorhandler-no} > 0)
+make: Fatal errors encountered -- cannot continue
+make: stopped in unit-tests
+exit status 1
Index: src/usr.bin/make/unit-tests/varmod-mtime.mk
diff -u src/usr.bin/make/unit-tests/varmod-mtime.mk:1.1 src/usr.bin/make/unit-tests/varmod-mtime.mk:1.2
--- src/usr.bin/make/unit-tests/varmod-mtime.mk:1.1 Tue May 9 20:14:27 2023
+++ src/usr.bin/make/unit-tests/varmod-mtime.mk Thu Aug 17 18:48:32 2023
@@ -1,30 +1,80 @@
-# $NetBSD: varmod-mtime.mk,v 1.1 2023/05/09 20:14:27 sjg Exp $
+# $NetBSD: varmod-mtime.mk,v 1.2 2023/08/17 18:48:32 rillig Exp $
#
-# Tests for the :mtime variable modifier, which provides mtime
-# of variable value assumed to be a pathname.
+# Tests for the ':mtime' variable modifier, which maps each word of the
+# expression to that file's modification time.
-all:
+start:= ${%s:L:gmtime}
-# mtime of this makefile
-mtime:= ${MAKEFILE:mtime}
-# if pathname does not exist and timestamp is provided
-# that is the result
-.if ${no/such:L:mtime=0} != "0"
+# Ensure that this makefile exists and has a modification time. If the file
+# didn't exist, the ':mtime' modifier would return the current time.
+.if ${MAKEFILE:mtime} >= ${start}
. error
.endif
-.if ${no/such:L:mtime=42} != "42"
+
+# For a file that doesn't exist, the ':mtime' modifier returns the current
+# time, without an error or warning message. The returned timestamp differs
+# from the 'now' that is used when updating the timestamps in archives or for
+# touching files using the '-t' option, which is taken once when make is
+# started.
+not_found_mtime:= ${no/such/file:L:mtime}
+.if ${not_found_mtime} < ${start}
+. error
+.endif
+
+
+# The ':mtime' modifier accepts a timestamp in seconds as an optional
+# argument. This timestamp is used as a fallback in case the file's time
+# cannot be determined, without any error or warning message.
+.if ${no/such/file:L:mtime=0} != "0"
+. error
+.endif
+
+
+# The fallback timestamp must start with a digit, and it is interpreted as a
+# decimal integer.
+.if ${no/such/file:L:mtime=00042} != "42"
+. error
+.endif
+
+
+# The timestamp of a newly created file must be at least as great as the
+# timestamp when parsing of this makefile started.
+COOKIE= ${TMPDIR:U/tmp}/varmod-mtime.cookie
+_!= touch ${COOKIE}
+.if ${COOKIE:mtime=0} < ${start}
+. error ${COOKIE:mtime=0} < ${start}
+.endif
+_!= rm -f ${COOKIE}
+
+
+# If the optional argument of the ':mtime' modifier is the word 'error', the
+# modifier fails with an error message, once for each affected file.
+#
+# expect+3: Cannot determine mtime for 'no/such/file1': <ENOENT>
+# expect+2: Cannot determine mtime for 'no/such/file2': <ENOENT>
+# expect+1: Malformed conditional (${no/such/file1 no/such/file2:L:mtime=error})
+.if ${no/such/file1 no/such/file2:L:mtime=error}
+. error
+.else
. error
.endif
-# if no timestamp is provided and stat(2) fails use current time
-.if ${no/such:L:mtime} < ${mtime}
-. error no/such:L:mtime ${no/such:L:mtime} < ${mtime}
+
+# TODO: Only the word 'error' is a special argument to the ':mtime' modifier,
+# all other words should result in a parse error.
+# expect+2: Unknown modifier "handler-no"
+# expect+1: Malformed conditional (${MAKEFILE:mtime=errorhandler-no} > 0)
+.if ${MAKEFILE:mtime=errorhandler-no} > 0
+.else
+. error
.endif
-COOKIE = ${TMPDIR}/varmod-mtime.cookie
-x!= touch ${COOKIE}
-.if ${COOKIE:mtime=0} < ${mtime}
-. error COOKIE:mtime=0 ${COOKIE:mtime=0} < ${mtime}
+
+# Ensure that the fallback for a missing modification time is indeed the
+# current time, and not any later time.
+end:= ${%s:L:gmtime}
+.if ${not_found_mtime} > ${end}
+. error
.endif