Module Name: src Committed By: rillig Date: Fri Dec 29 15:47:03 UTC 2023
Modified Files: src/usr.bin/make/unit-tests: varmod-assign.exp varmod-assign.mk Log Message: tests/make: test the '::=' assignment modifier To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 src/usr.bin/make/unit-tests/varmod-assign.exp cvs rdiff -u -r1.16 -r1.17 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.17 src/usr.bin/make/unit-tests/varmod-assign.exp:1.18 --- src/usr.bin/make/unit-tests/varmod-assign.exp:1.17 Tue Nov 30 20:48:01 2021 +++ src/usr.bin/make/unit-tests/varmod-assign.exp Fri Dec 29 15:47:03 2023 @@ -12,6 +12,31 @@ Var_Parse: ${${VARNAME}} != "assigned-va Var_Parse: ${VARNAME}} != "assigned-value" (eval-defined) Global: .MAKEFLAGS = -r -k -d v -d Global: .MAKEFLAGS = -r -k -d v -d 0 +Var_Parse: ${CMD_CMD_VAR::=new-value} || ${CMD_GLOBAL_VAR::=new-value} || ${CMD_ENV_VAR::=new-value} || "${CMD_NEW_VAR::=new-value}" (eval-defined) +Evaluating modifier ${CMD_CMD_VAR::...} on value "cmd-value" +Modifier part: "new-value" +Command: CMD_CMD_VAR = new-value +Global: .MAKEOVERRIDES = FIRST LAST LAST LAST APPENDED RAN RAN RAN IT1 THEN1 IE2 ELSE2 CMD_CMD_VAR CMD_CMD_VAR +Result of ${CMD_CMD_VAR::=new-value} is "" +Var_Parse: ${CMD_GLOBAL_VAR::=new-value} || ${CMD_ENV_VAR::=new-value} || "${CMD_NEW_VAR::=new-value}" (eval-defined) +Evaluating modifier ${CMD_GLOBAL_VAR::...} on value "global-value" +Modifier part: "new-value" +Global: CMD_GLOBAL_VAR = new-value +Result of ${CMD_GLOBAL_VAR::=new-value} is "" +Var_Parse: ${CMD_ENV_VAR::=new-value} || "${CMD_NEW_VAR::=new-value}" (eval-defined) +Evaluating modifier ${CMD_ENV_VAR::...} on value "env-value" +Modifier part: "new-value" +Global: CMD_ENV_VAR = new-value +Result of ${CMD_ENV_VAR::=new-value} is "" +Var_Parse: ${CMD_NEW_VAR::=new-value}" (eval) +Evaluating modifier ${CMD_NEW_VAR::...} on value "" (eval, undefined) +Modifier part: "new-value" +Global: ignoring delete 'CMD_NEW_VAR' as it is not found +Command: CMD_NEW_VAR = new-value +Global: .MAKEOVERRIDES = FIRST LAST LAST LAST APPENDED RAN RAN RAN IT1 THEN1 IE2 ELSE2 CMD_CMD_VAR CMD_CMD_VAR CMD_NEW_VAR +Result of ${CMD_NEW_VAR::=new-value} is "" (eval, undefined) +Global: .MAKEFLAGS = -r -k -d v -d 0 -d v -d +Global: .MAKEFLAGS = -r -k -d v -d 0 -d v -d 0 make: Bad modifier ":" for variable "" mod-assign-empty: value} make: Bad modifier ":" for variable "" Index: src/usr.bin/make/unit-tests/varmod-assign.mk diff -u src/usr.bin/make/unit-tests/varmod-assign.mk:1.16 src/usr.bin/make/unit-tests/varmod-assign.mk:1.17 --- src/usr.bin/make/unit-tests/varmod-assign.mk:1.16 Sun Nov 19 21:47:52 2023 +++ src/usr.bin/make/unit-tests/varmod-assign.mk Fri Dec 29 15:47:03 2023 @@ -1,4 +1,4 @@ -# $NetBSD: varmod-assign.mk,v 1.16 2023/11/19 21:47:52 rillig Exp $ +# $NetBSD: varmod-assign.mk,v 1.17 2023/12/29 15:47:03 rillig Exp $ # # Tests for the obscure ::= variable modifiers, which perform variable # assignments during evaluation, just like the = operator in C. @@ -7,34 +7,38 @@ all: mod-assign-empty all: mod-assign-parse all: mod-assign-shell-error -# The modifier '::?=' applies the assignment operator '?=' 3 times. The +# In the following loop expression, +# the '::?=' modifier applies the assignment operator '?=' 3 times. The # operator '?=' only has an effect for the first time, therefore the variable # FIRST ends up with the value 1. .if "${1 2 3:L:@i@${FIRST::?=$i}@} first=${FIRST}" != " first=1" . error .endif -# The modifier '::=' applies the assignment operator '=' 3 times. The +# In the following loop expression, +# the modifier '::=' applies the assignment operator '=' 3 times. The # operator '=' overwrites the previous value, therefore the variable LAST ends # up with the value 3. .if "${1 2 3:L:@i@${LAST::=$i}@} last=${LAST}" != " last=3" . error .endif -# The modifier '::+=' applies the assignment operator '+=' 3 times. The +# In the following loop expression, +# the modifier '::+=' applies the assignment operator '+=' 3 times. The # operator '+=' appends 3 times to the variable, therefore the variable # APPENDED ends up with the value "1 2 3". .if "${1 2 3:L:@i@${APPENDED::+=$i}@} appended=${APPENDED}" != " appended=1 2 3" . error .endif -# The modifier '::!=' applies the assignment operator '!=' 3 times. Just as +# In the following loop expression, +# the modifier '::!=' applies the assignment operator '!=' 3 times. Just as # with the modifier '::=', the last value is stored in the RAN variable. .if "${1 2 3:L:@i@${RAN::!=${i:%=echo '<%>';}}@} ran=${RAN}" != " ran=<3>" . error .endif -# The assignments were performed as part of .if conditions and thus happened +# When a '::=' modifier is evaluated as part of an .if condition, it happens # in the command line scope. .if "${FIRST}, ${LAST}, ${APPENDED}, ${RAN}" != "1, 3, 1 2 3, <3>" . error @@ -149,3 +153,47 @@ ${VARNAME}= initial-value # Sets 'VAR.${ . error .endif .MAKEFLAGS: -d0 + + +# Conditional directives are evaluated in command line scope. Any assignment +# modifiers in these conditions create or +.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 +# expect: Global: CMD_GLOBAL_VAR = new-value +# expect: Global: CMD_ENV_VAR = new-value +# expect: Global: ignoring delete 'CMD_NEW_VAR' as it is not found +# expect: Command: CMD_NEW_VAR = new-value +.if ${CMD_CMD_VAR::=new-value} \ + || ${CMD_GLOBAL_VAR::=new-value} \ + || ${CMD_ENV_VAR::=new-value} \ + || "${CMD_NEW_VAR::=new-value}" +. error +.endif +.MAKEFLAGS: -d0 + + +# 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. +# +# Running './make -r -f varmod-assign.mk target' results in: +# 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 +.MAKEFLAGS: TARGET_CMD_VAR=cmd-value +TARGET_GLOBAL_VAR=global-value +export TARGET_ENV_VAR=env-value +.MAKEFLAGS: ${make(target):?-dv:} +target: 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}