Module Name:    src
Committed By:   rillig
Date:           Sun Nov 19 12:11:34 UTC 2023

Modified Files:
        src/usr.bin/make: var.c
        src/usr.bin/make/unit-tests: varmod-mtime.exp varmod-mtime.mk

Log Message:
tests/make: cover all code paths for the ':mtime' modifier


To generate a diff of this commit:
cvs rdiff -u -r1.1072 -r1.1073 src/usr.bin/make/var.c
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/make/unit-tests/varmod-mtime.exp
cvs rdiff -u -r1.7 -r1.8 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/var.c
diff -u src/usr.bin/make/var.c:1.1072 src/usr.bin/make/var.c:1.1073
--- src/usr.bin/make/var.c:1.1072	Sun Nov 19 11:47:49 2023
+++ src/usr.bin/make/var.c	Sun Nov 19 12:11:34 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.1072 2023/11/19 11:47:49 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.1073 2023/11/19 12:11:34 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -139,7 +139,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.1072 2023/11/19 11:47:49 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.1073 2023/11/19 12:11:34 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -2897,9 +2897,8 @@ ApplyModifier_Mtime(const char **pp, Mod
 			goto invalid_argument;
 		*pp = p;
 	}
-	if (!ModChain_ShouldEval(ch))
-		return AMR_OK;
-	ModifyWords(ch, ModifyWord_Mtime, &args, ch->oneBigWord);
+	if (ModChain_ShouldEval(ch))
+		ModifyWords(ch, ModifyWord_Mtime, &args, ch->oneBigWord);
 	return args.rc;
 
 invalid_argument:

Index: src/usr.bin/make/unit-tests/varmod-mtime.exp
diff -u src/usr.bin/make/unit-tests/varmod-mtime.exp:1.6 src/usr.bin/make/unit-tests/varmod-mtime.exp:1.7
--- src/usr.bin/make/unit-tests/varmod-mtime.exp:1.6	Sun Nov 19 11:47:49 2023
+++ src/usr.bin/make/unit-tests/varmod-mtime.exp	Sun Nov 19 12:11:34 2023
@@ -5,6 +5,10 @@ make: "varmod-mtime.mk" line 70: Cannot 
 make: "varmod-mtime.mk" line 70: Malformed conditional (${no/such/file1 no/such/file2:L:mtime=error})
 make: "varmod-mtime.mk" line 81: Invalid argument 'errorhandler-no' for modifier ':mtime'
 make: "varmod-mtime.mk" line 81: Malformed conditional (${MAKEFILE:mtime=errorhandler-no} > 0)
+make: "varmod-mtime.mk" line 90: Invalid argument 'warn' for modifier ':mtime'
+make: "varmod-mtime.mk" line 90: Malformed conditional (${MAKEFILE:mtime=warn} > 0)
+make: "varmod-mtime.mk" line 115: Unknown modifier "mtim"
+make: "varmod-mtime.mk" line 115: Malformed conditional (${anything:L:mtim})
 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.7 src/usr.bin/make/unit-tests/varmod-mtime.mk:1.8
--- src/usr.bin/make/unit-tests/varmod-mtime.mk:1.7	Sun Nov 19 11:47:49 2023
+++ src/usr.bin/make/unit-tests/varmod-mtime.mk	Sun Nov 19 12:11:34 2023
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-mtime.mk,v 1.7 2023/11/19 11:47:49 rillig Exp $
+# $NetBSD: varmod-mtime.mk,v 1.8 2023/11/19 12:11:34 rillig Exp $
 #
 # Tests for the ':mtime' variable modifier, which maps each word of the
 # expression to that file's modification time.
@@ -84,9 +84,36 @@ _!=	rm -f ${COOKIE}
 .endif
 
 
+# Only the word 'error' can be used as a fallback argument to the modifier.
+# expect+2: Invalid argument 'warn' for modifier ':mtime'
+# expect+1: Malformed conditional (${MAKEFILE:mtime=warn} > 0)
+.if ${MAKEFILE:mtime=warn} > 0
+.  error
+.else
+.  error
+.endif
+
+
 # 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
+
+
+# If the expression is irrelevant, the ':mtime' modifier is only parsed, it
+# does not perform any filesystem operations.
+.if 0 && ${anything:L:mtime}
+.  error
+.endif
+
+
+# If there is a typo in the modifier name, it does not match.
+# expect+2: Unknown modifier "mtim"
+# expect+1: Malformed conditional (${anything:L:mtim})
+.if ${anything:L:mtim}
+.  error
+.else
+.  error
+.endif

Reply via email to