Module Name: src
Committed By: rillig
Date: Sun Jan 7 11:42:22 UTC 2024
Modified Files:
src/usr.bin/make/unit-tests: varmod-assign.exp varmod-assign.mk
Log Message:
tests/make: test the '::=' modifier in target scope
To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/usr.bin/make/unit-tests/varmod-assign.exp \
src/usr.bin/make/unit-tests/varmod-assign.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-assign.exp
diff -u src/usr.bin/make/unit-tests/varmod-assign.exp:1.18 src/usr.bin/make/unit-tests/varmod-assign.exp:1.19
--- src/usr.bin/make/unit-tests/varmod-assign.exp:1.18 Fri Dec 29 15:47:03 2023
+++ src/usr.bin/make/unit-tests/varmod-assign.exp Sun Jan 7 11:42:22 2024
@@ -50,4 +50,11 @@ make: Unfinished modifier for "ASSIGN" (
ok=word
make: " echo word; false " returned non-zero status
err=previous
+Command: TARGET_CMD_VAR = cmd-value
+Global: TARGET_GLOBAL_VAR = global-value
+target: TARGET_TARGET_VAR = target-value
+target: TARGET_TARGET_VAR = new-value
+Global: TARGET_GLOBAL_VAR = new-value
+Global: TARGET_ENV_VAR = new-value
+target: TARGET_NEW_VAR = new-value
exit status 0
Index: src/usr.bin/make/unit-tests/varmod-assign.mk
diff -u src/usr.bin/make/unit-tests/varmod-assign.mk:1.18 src/usr.bin/make/unit-tests/varmod-assign.mk:1.19
--- src/usr.bin/make/unit-tests/varmod-assign.mk:1.18 Sun Dec 31 10:09:01 2023
+++ src/usr.bin/make/unit-tests/varmod-assign.mk Sun Jan 7 11:42:22 2024
@@ -1,8 +1,10 @@
-# $NetBSD: varmod-assign.mk,v 1.18 2023/12/31 10:09:01 rillig Exp $
+# $NetBSD: varmod-assign.mk,v 1.19 2024/01/07 11:42:22 rillig Exp $
#
# Tests for the obscure ::= variable modifiers, which perform variable
# assignments during evaluation, just like the = operator in C.
+.if !make(target)
+
all: mod-assign-empty
all: mod-assign-parse
all: mod-assign-shell-error
@@ -162,7 +164,6 @@ ${VARNAME}= initial-value # Sets 'VAR.${
.MAKEFLAGS: CMD_CMD_VAR=cmd-value
CMD_GLOBAL_VAR=global-value
export CMD_ENV_VAR=env-value
-
.MAKEFLAGS: -dv
# expect-reset
# expect: Command: CMD_CMD_VAR = new-value
@@ -178,23 +179,30 @@ export CMD_ENV_VAR=env-value
.endif
.MAKEFLAGS: -d0
+# Run the 'target' test in a separate sub-make, with reduced debug logging.
+all: run-target
+run-target: .PHONY
+ @${MAKE} -r -f ${MAKEFILE} -dv target 2>&1 | grep ': TARGET_'
-# In target scope, assignments only happen in a few cases. To extract the
-# debug log for this test, the debug log would have to be enabled for the
-# other targets as well, thus producing lots of irrelevant output.
+.else # make(target)
+
+# The commands of a target are evaluated in target scope. An assignment
+# modifier that creates a new variable creates it in the target scope.
+# Existing variables are updated in their previous scope, and environment
+# variables are created in the global scope, as in other situations.
#
-# Running './make -r -f varmod-assign.mk target | grep ": TARGET"' results in:
-# target: TARGET_TARGET_VAR = new-value
-# Global: TARGET_GLOBAL_VAR = new-value
-# Global: TARGET_ENV_VAR = new-value
-# target: TARGET_NEW_VAR = new-value
+# expect: target: TARGET_TARGET_VAR = new-value
+# expect: Global: TARGET_GLOBAL_VAR = new-value
+# expect: Global: TARGET_ENV_VAR = new-value
+# expect: target: TARGET_NEW_VAR = new-value
.MAKEFLAGS: TARGET_CMD_VAR=cmd-value
TARGET_GLOBAL_VAR=global-value
export TARGET_ENV_VAR=env-value
-.MAKEFLAGS: ${make(target):?-dv:}
target: .PHONY TARGET_TARGET_VAR=target-value
: ${TARGET_TARGET_VAR::=new-value}
: ${TARGET_CMD_VAR::=new-value}
: ${TARGET_GLOBAL_VAR::=new-value}
: ${TARGET_ENV_VAR::=new-value}
: ${TARGET_NEW_VAR::=new-value}
+
+.endif