Sun Oct 18 21:36:22 2020 UTC ()
make(1): explain existing tests for the ::= assignment modifiers


(rillig)
diff -r1.5 -r1.6 src/usr.bin/make/unit-tests/varmod-assign.exp
diff -r1.6 -r1.7 src/usr.bin/make/unit-tests/varmod-assign.mk

cvs diff -r1.5 -r1.6 src/usr.bin/make/unit-tests/varmod-assign.exp (expand / switch to unified diff)

--- src/usr.bin/make/unit-tests/varmod-assign.exp 2020/08/25 21:16:53 1.5
+++ src/usr.bin/make/unit-tests/varmod-assign.exp 2020/10/18 21:36:22 1.6
@@ -1,26 +1,26 @@ @@ -1,26 +1,26 @@
1mod-assign: first=1. 1mod-assign: first=1.
2mod-assign: last=3. 2mod-assign: last=3.
3mod-assign: appended=1 2 3. 3mod-assign: appended=1 2 3.
41 41
52 52
63 63
7mod-assign: ran:3. 7mod-assign: ran:3.
8mod-assign: global: 1, 3, 1 2 3, 3. 8mod-assign: global: 1, 3, 1 2 3, 3.
9mod-assign-nested: then1t1 9mod-assign-nested: then1t1
10mod-assign-nested: else2e2 10mod-assign-nested: else2e2
11mod-assign-nested: then3t3 11mod-assign-nested: then3t3
12mod-assign-nested: else4e4 12mod-assign-nested: else4e4
13make: Bad modifier `:' for  13make: Bad modifier `:' for
14value} 14mod-assign-empty: value}
15make: Bad modifier `:' for  15make: Bad modifier `:' for
16mod-assign-empty: overwritten} 16mod-assign-empty: overwritten}
17mod-assign-empty: VAR=overwritten 17mod-assign-empty: VAR=overwritten
18make: Unknown modifier ':' 18make: Unknown modifier ':'
19 19
20sysv:y 20sysv:y
21make: Unfinished modifier for ASSIGN ('}' missing) 21make: Unfinished modifier for ASSIGN ('}' missing)
22 22
23ok=word 23ok=word
24make: " echo word; false " returned non-zero status 24make: " echo word; false " returned non-zero status
25err=previous 25err=previous
26exit status 0 26exit status 0

cvs diff -r1.6 -r1.7 src/usr.bin/make/unit-tests/varmod-assign.mk (expand / switch to unified diff)

--- src/usr.bin/make/unit-tests/varmod-assign.mk 2020/08/25 21:16:53 1.6
+++ src/usr.bin/make/unit-tests/varmod-assign.mk 2020/10/18 21:36:22 1.7
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1# $NetBSD: varmod-assign.mk,v 1.6 2020/08/25 21:16:53 rillig Exp $ 1# $NetBSD: varmod-assign.mk,v 1.7 2020/10/18 21:36:22 rillig Exp $
2# 2#
3# Tests for the obscure ::= variable modifiers, which perform variable 3# Tests for the obscure ::= variable modifiers, which perform variable
4# assignments during evaluation, just like the = operator in C. 4# assignments during evaluation, just like the = operator in C.
5 5
6all: mod-assign 6all: mod-assign
7all: mod-assign-nested 7all: mod-assign-nested
8all: mod-assign-empty 8all: mod-assign-empty
9all: mod-assign-parse 9all: mod-assign-parse
10all: mod-assign-shell-error 10all: mod-assign-shell-error
11 11
12mod-assign: 12mod-assign:
13 # The ::?= modifier applies the ?= assignment operator 3 times. 13 # The ::?= modifier applies the ?= assignment operator 3 times.
14 # The ?= operator only has an effect for the first time, therefore 14 # The ?= operator only has an effect for the first time, therefore
@@ -41,33 +41,45 @@ mod-assign-nested: @@ -41,33 +41,45 @@ mod-assign-nested:
41 @echo $@: ${1:?${THEN1::=then1${IT1::=t1}}:${ELSE1::=else1${IE1::=e1}}}${THEN1}${ELSE1}${IT1}${IE1} 41 @echo $@: ${1:?${THEN1::=then1${IT1::=t1}}:${ELSE1::=else1${IE1::=e1}}}${THEN1}${ELSE1}${IT1}${IE1}
42 42
43 # The condition "0" is false, therefore ELSE1 gets assigned a value, 43 # The condition "0" is false, therefore ELSE1 gets assigned a value,
44 # and IE1 as well. Nothing surprising here as well. 44 # and IE1 as well. Nothing surprising here as well.
45 @echo $@: ${0:?${THEN2::=then2${IT2::=t2}}:${ELSE2::=else2${IE2::=e2}}}${THEN2}${ELSE2}${IT2}${IE2} 45 @echo $@: ${0:?${THEN2::=then2${IT2::=t2}}:${ELSE2::=else2${IE2::=e2}}}${THEN2}${ELSE2}${IT2}${IE2}
46 46
47 # The same effects happen when the variables are defined elsewhere. 47 # The same effects happen when the variables are defined elsewhere.
48 @echo $@: ${SINK3:Q} 48 @echo $@: ${SINK3:Q}
49 @echo $@: ${SINK4:Q} 49 @echo $@: ${SINK4:Q}
50SINK3:= ${1:?${THEN3::=then3${IT3::=t3}}:${ELSE3::=else3${IE3::=e3}}}${THEN3}${ELSE3}${IT3}${IE3} 50SINK3:= ${1:?${THEN3::=then3${IT3::=t3}}:${ELSE3::=else3${IE3::=e3}}}${THEN3}${ELSE3}${IT3}${IE3}
51SINK4:= ${0:?${THEN4::=then4${IT4::=t4}}:${ELSE4::=else4${IE4::=e4}}}${THEN4}${ELSE4}${IT4}${IE4} 51SINK4:= ${0:?${THEN4::=then4${IT4::=t4}}:${ELSE4::=else4${IE4::=e4}}}${THEN4}${ELSE4}${IT4}${IE4}
52 52
53mod-assign-empty: 53mod-assign-empty:
54 # Assigning to the empty variable would obviously not work since that variable 54 # Assigning to the empty variable would obviously not work since that
55 # is write-protected. Therefore it is rejected early as a "bad modifier". 55 # variable is write-protected. Therefore it is rejected early with a
56 @echo ${::=value} 56 # "Bad modifier" message.
 57 #
 58 # XXX: The error message is hard to read since the variable name is
 59 # empty. This leads to a trailing space in the error message.
 60 @echo $@: ${::=value}
 61
 62 # In this variant, it is not as obvious that the name of the
 63 # expression is empty. Assigning to it is rejected as well, with the
 64 # same "Bad modifier" message.
 65 #
 66 # XXX: The error message is hard to read since the variable name is
 67 # empty. This leads to a trailing space in the error message.
57 @echo $@: ${:Uvalue::=overwritten} 68 @echo $@: ${:Uvalue::=overwritten}
58 69
59 # The :L modifier sets the variable's value to its name. 70 # The :L modifier sets the value of the expression to its variable
60 # Since the name is still "VAR", assigning to that variable works. 71 # name. The name of the expression is "VAR", therefore assigning to
 72 # that variable works.
61 @echo $@: ${VAR:L::=overwritten} VAR=${VAR} 73 @echo $@: ${VAR:L::=overwritten} VAR=${VAR}
62 74
63mod-assign-parse: 75mod-assign-parse:
64 # The modifier for assignment operators starts with a ':'. 76 # The modifier for assignment operators starts with a ':'.
65 # An 'x' after that is an invalid modifier. 77 # An 'x' after that is an invalid modifier.
66 @echo ${ASSIGN::x} # 'x' is an unknown assignment operator 78 @echo ${ASSIGN::x} # 'x' is an unknown assignment operator
67 79
68 # When parsing an assignment operator fails because the operator is 80 # When parsing an assignment operator fails because the operator is
69 # incomplete, make falls back to the SysV modifier. 81 # incomplete, make falls back to the SysV modifier.
70 @echo ${SYSV::=sysv\:x}${SYSV::x=:y} 82 @echo ${SYSV::=sysv\:x}${SYSV::x=:y}
71 83
72 @echo ${ASSIGN::=value # missing closing brace 84 @echo ${ASSIGN::=value # missing closing brace
73 85