make(1): move test for the ::= modifier to varmod-assigndiff -r1.15 -r1.16 src/usr.bin/make/unit-tests/moderrs.exp
(rillig)
--- src/usr.bin/make/unit-tests/moderrs.exp 2020/08/09 15:15:29 1.15
+++ src/usr.bin/make/unit-tests/moderrs.exp 2020/08/25 20:49:40 1.16
@@ -113,33 +113,26 @@ make: Bad modifier `:t' for FIB | @@ -113,33 +113,26 @@ make: Bad modifier `:t' for FIB | |||
113 | 113 | |||
114 | make: Bad modifier `:t' for FIB | 114 | make: Bad modifier `:t' for FIB | |
115 | M*} | 115 | M*} | |
116 | mod-ifelse-parse: | 116 | mod-ifelse-parse: | |
117 | make: Unfinished modifier for FIB (':' missing) | 117 | make: Unfinished modifier for FIB (':' missing) | |
118 | 118 | |||
119 | make: Unfinished modifier for FIB (':' missing) | 119 | make: Unfinished modifier for FIB (':' missing) | |
120 | 120 | |||
121 | make: Unfinished modifier for FIB ('}' missing) | 121 | make: Unfinished modifier for FIB ('}' missing) | |
122 | 122 | |||
123 | make: Unfinished modifier for FIB ('}' missing) | 123 | make: Unfinished modifier for FIB ('}' missing) | |
124 | 124 | |||
125 | then | 125 | then | |
126 | mod-assign-parse: | |||
127 | make: Unknown modifier ':' | |||
128 | ||||
129 | make: Bad modifier `:' for | |||
130 | value} | |||
131 | make: Unfinished modifier for ASSIGN ('}' missing) | |||
132 | ||||
133 | mod-remember-parse: | 126 | mod-remember-parse: | |
134 | 1 1 2 3 5 8 13 21 34 | 127 | 1 1 2 3 5 8 13 21 34 | |
135 | make: Unknown modifier '_' | 128 | make: Unknown modifier '_' | |
136 | 129 | |||
137 | mod-sysv-parse: | 130 | mod-sysv-parse: | |
138 | make: Unknown modifier '3' | 131 | make: Unknown modifier '3' | |
139 | make: Unclosed variable specification (expecting '}') for "FIB" (value "") modifier 3 | 132 | make: Unclosed variable specification (expecting '}') for "FIB" (value "") modifier 3 | |
140 | 133 | |||
141 | make: Unknown modifier '3' | 134 | make: Unknown modifier '3' | |
142 | make: Unclosed variable specification (expecting '}') for "FIB" (value "") modifier 3 | 135 | make: Unclosed variable specification (expecting '}') for "FIB" (value "") modifier 3 | |
143 | 136 | |||
144 | make: Unknown modifier '3' | 137 | make: Unknown modifier '3' | |
145 | make: Unclosed variable specification (expecting '}') for "FIB" (value "") modifier 3 | 138 | make: Unclosed variable specification (expecting '}') for "FIB" (value "") modifier 3 |
--- src/usr.bin/make/unit-tests/moderrs.mk 2020/08/09 15:15:29 1.14
+++ src/usr.bin/make/unit-tests/moderrs.mk 2020/08/25 20:49:40 1.15
@@ -1,36 +1,35 @@ | @@ -1,36 +1,35 @@ | |||
1 | # $Id: moderrs.mk,v 1.14 2020/08/09 15:15:29 rillig Exp $ | 1 | # $Id: moderrs.mk,v 1.15 2020/08/25 20:49:40 rillig Exp $ | |
2 | # | 2 | # | |
3 | # various modifier error tests | 3 | # various modifier error tests | |
4 | 4 | |||
5 | VAR=TheVariable | 5 | VAR=TheVariable | |
6 | # incase we have to change it ;-) | 6 | # incase we have to change it ;-) | |
7 | MOD_UNKN=Z | 7 | MOD_UNKN=Z | |
8 | MOD_TERM=S,V,v | 8 | MOD_TERM=S,V,v | |
9 | MOD_S:= ${MOD_TERM}, | 9 | MOD_S:= ${MOD_TERM}, | |
10 | 10 | |||
11 | FIB= 1 1 2 3 5 8 13 21 34 | 11 | FIB= 1 1 2 3 5 8 13 21 34 | |
12 | 12 | |||
13 | all: modunkn modunknV varterm vartermV modtermV modloop | 13 | all: modunkn modunknV varterm vartermV modtermV modloop | |
14 | all: modloop-close | 14 | all: modloop-close | |
15 | all: modwords | 15 | all: modwords | |
16 | all: modexclam | 16 | all: modexclam | |
17 | all: mod-subst-delimiter | 17 | all: mod-subst-delimiter | |
18 | all: mod-regex-delimiter | 18 | all: mod-regex-delimiter | |
19 | all: mod-regex-undefined-subexpression | 19 | all: mod-regex-undefined-subexpression | |
20 | all: mod-ts-parse | 20 | all: mod-ts-parse | |
21 | all: mod-t-parse | 21 | all: mod-t-parse | |
22 | all: mod-ifelse-parse | 22 | all: mod-ifelse-parse | |
23 | all: mod-assign-parse | |||
24 | all: mod-remember-parse | 23 | all: mod-remember-parse | |
25 | all: mod-sysv-parse | 24 | all: mod-sysv-parse | |
26 | 25 | |||
27 | modunkn: | 26 | modunkn: | |
28 | @echo "Expect: Unknown modifier 'Z'" | 27 | @echo "Expect: Unknown modifier 'Z'" | |
29 | @echo "VAR:Z=${VAR:Z}" | 28 | @echo "VAR:Z=${VAR:Z}" | |
30 | 29 | |||
31 | modunknV: | 30 | modunknV: | |
32 | @echo "Expect: Unknown modifier 'Z'" | 31 | @echo "Expect: Unknown modifier 'Z'" | |
33 | @echo "VAR:${MOD_UNKN}=${VAR:${MOD_UNKN}}" | 32 | @echo "VAR:${MOD_UNKN}=${VAR:${MOD_UNKN}}" | |
34 | 33 | |||
35 | varterm: | 34 | varterm: | |
36 | @echo "Expect: Unclosed variable specification for VAR" | 35 | @echo "Expect: Unclosed variable specification for VAR" | |
@@ -154,30 +153,24 @@ mod-t-parse: | @@ -154,30 +153,24 @@ mod-t-parse: | |||
154 | @echo ${FIB:t | 153 | @echo ${FIB:t | |
155 | @echo ${FIB:txy} | 154 | @echo ${FIB:txy} | |
156 | @echo ${FIB:t} | 155 | @echo ${FIB:t} | |
157 | @echo ${FIB:t:M*} | 156 | @echo ${FIB:t:M*} | |
158 | 157 | |||
159 | mod-ifelse-parse: | 158 | mod-ifelse-parse: | |
160 | @echo $@: | 159 | @echo $@: | |
161 | @echo ${FIB:? | 160 | @echo ${FIB:? | |
162 | @echo ${FIB:?then | 161 | @echo ${FIB:?then | |
163 | @echo ${FIB:?then: | 162 | @echo ${FIB:?then: | |
164 | @echo ${FIB:?then:else | 163 | @echo ${FIB:?then:else | |
165 | @echo ${FIB:?then:else} | 164 | @echo ${FIB:?then:else} | |
166 | 165 | |||
167 | mod-assign-parse: | |||
168 | @echo $@: | |||
169 | @echo ${ASSIGN::x} # 'x' is an unknown assignment operator | |||
170 | @echo ${::=value} # trying to set the empty variable | |||
171 | @echo ${ASSIGN::=value # missing closing brace | |||
172 | ||||
173 | mod-remember-parse: | 166 | mod-remember-parse: | |
174 | @echo $@: | 167 | @echo $@: | |
175 | @echo ${FIB:_} # ok | 168 | @echo ${FIB:_} # ok | |
176 | @echo ${FIB:__} # modifier name too long | 169 | @echo ${FIB:__} # modifier name too long | |
177 | 170 | |||
178 | mod-sysv-parse: | 171 | mod-sysv-parse: | |
179 | @echo $@: | 172 | @echo $@: | |
180 | @echo ${FIB:3 | 173 | @echo ${FIB:3 | |
181 | @echo ${FIB:3= | 174 | @echo ${FIB:3= | |
182 | @echo ${FIB:3=x3 | 175 | @echo ${FIB:3=x3 | |
183 | @echo ${FIB:3=x3} # ok | 176 | @echo ${FIB:3=x3} # ok |
--- src/usr.bin/make/unit-tests/varmod-assign.exp 2020/08/16 12:48:55 1.2
+++ src/usr.bin/make/unit-tests/varmod-assign.exp 2020/08/25 20:49:40 1.3
@@ -1,13 +1,23 @@ | @@ -1,13 +1,23 @@ | |||
1 | mod-assign: first=1. | 1 | mod-assign: first=1. | |
2 | mod-assign: last=3. | 2 | mod-assign: last=3. | |
3 | mod-assign: appended=1 2 3. | 3 | mod-assign: appended=1 2 3. | |
4 | 1 | 4 | 1 | |
5 | 2 | 5 | 2 | |
6 | 3 | 6 | 3 | |
7 | mod-assign: ran:3. | 7 | mod-assign: ran:3. | |
8 | mod-assign: global: 1, 3, 1 2 3, 3. | 8 | mod-assign: global: 1, 3, 1 2 3, 3. | |
9 | mod-assign-nested: then1t1 | 9 | mod-assign-nested: then1t1 | |
10 | mod-assign-nested: else2e2 | 10 | mod-assign-nested: else2e2 | |
11 | mod-assign-nested: then3t3 | 11 | mod-assign-nested: then3t3 | |
12 | mod-assign-nested: else4e4 | 12 | mod-assign-nested: else4e4 | |
13 | make: Bad modifier `:' for | |||
14 | value} | |||
15 | make: Bad modifier `:' for | |||
16 | mod-assign-empty: overwritten} | |||
17 | mod-assign-empty: VAR=overwritten | |||
18 | make: Unknown modifier ':' | |||
19 | ||||
20 | sysv:y | |||
21 | make: Unfinished modifier for ASSIGN ('}' missing) | |||
22 | ||||
13 | exit status 0 | 23 | exit status 0 |
--- src/usr.bin/make/unit-tests/varmod-assign.mk 2020/08/25 18:59:30 1.3
+++ src/usr.bin/make/unit-tests/varmod-assign.mk 2020/08/25 20:49:40 1.4
@@ -1,20 +1,22 @@ | @@ -1,20 +1,22 @@ | |||
1 | # $NetBSD: varmod-assign.mk,v 1.3 2020/08/25 18:59:30 rillig Exp $ | 1 | # $NetBSD: varmod-assign.mk,v 1.4 2020/08/25 20:49:40 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 | |||
6 | all: mod-assign | 6 | all: mod-assign | |
7 | all: mod-assign-nested | 7 | all: mod-assign-nested | |
8 | all: mod-assign-empty | |||
9 | all: mod-assign-parse | |||
8 | 10 | |||
9 | mod-assign: | 11 | mod-assign: | |
10 | # The ::?= modifier applies the ?= assignment operator 3 times. | 12 | # The ::?= modifier applies the ?= assignment operator 3 times. | |
11 | # The ?= operator only has an effect for the first time, therefore | 13 | # The ?= operator only has an effect for the first time, therefore | |
12 | # the variable FIRST ends up with the value 1. | 14 | # the variable FIRST ends up with the value 1. | |
13 | @echo $@: ${1 2 3:L:@i@${FIRST::?=$i}@} first=${FIRST}. | 15 | @echo $@: ${1 2 3:L:@i@${FIRST::?=$i}@} first=${FIRST}. | |
14 | 16 | |||
15 | # The ::= modifier applies the = assignment operator 3 times. | 17 | # The ::= modifier applies the = assignment operator 3 times. | |
16 | # The = operator overwrites the previous value, therefore the | 18 | # The = operator overwrites the previous value, therefore the | |
17 | # variable LAST ends up with the value 3. | 19 | # variable LAST ends up with the value 3. | |
18 | @echo $@: ${1 2 3:L:@i@${LAST::=$i}@} last=${LAST}. | 20 | @echo $@: ${1 2 3:L:@i@${LAST::=$i}@} last=${LAST}. | |
19 | 21 | |||
20 | # The ::+= modifier applies the += assignment operator 3 times. | 22 | # The ::+= modifier applies the += assignment operator 3 times. | |
@@ -36,13 +38,34 @@ mod-assign-nested: | @@ -36,13 +38,34 @@ mod-assign-nested: | |||
36 | # The condition "1" is true, therefore THEN1 gets assigned a value, | 38 | # The condition "1" is true, therefore THEN1 gets assigned a value, | |
37 | # and IT1 as well. Nothing surprising here. | 39 | # and IT1 as well. Nothing surprising here. | |
38 | @echo $@: ${1:?${THEN1::=then1${IT1::=t1}}:${ELSE1::=else1${IE1::=e1}}}${THEN1}${ELSE1}${IT1}${IE1} | 40 | @echo $@: ${1:?${THEN1::=then1${IT1::=t1}}:${ELSE1::=else1${IE1::=e1}}}${THEN1}${ELSE1}${IT1}${IE1} | |
39 | 41 | |||
40 | # The condition "0" is false, therefore ELSE1 gets assigned a value, | 42 | # The condition "0" is false, therefore ELSE1 gets assigned a value, | |
41 | # and IE1 as well. Nothing surprising here as well. | 43 | # and IE1 as well. Nothing surprising here as well. | |
42 | @echo $@: ${0:?${THEN2::=then2${IT2::=t2}}:${ELSE2::=else2${IE2::=e2}}}${THEN2}${ELSE2}${IT2}${IE2} | 44 | @echo $@: ${0:?${THEN2::=then2${IT2::=t2}}:${ELSE2::=else2${IE2::=e2}}}${THEN2}${ELSE2}${IT2}${IE2} | |
43 | 45 | |||
44 | # The same effects happen when the variables are defined elsewhere. | 46 | # The same effects happen when the variables are defined elsewhere. | |
45 | @echo $@: ${SINK3:Q} | 47 | @echo $@: ${SINK3:Q} | |
46 | @echo $@: ${SINK4:Q} | 48 | @echo $@: ${SINK4:Q} | |
47 | SINK3:= ${1:?${THEN3::=then3${IT3::=t3}}:${ELSE3::=else3${IE3::=e3}}}${THEN3}${ELSE3}${IT3}${IE3} | 49 | SINK3:= ${1:?${THEN3::=then3${IT3::=t3}}:${ELSE3::=else3${IE3::=e3}}}${THEN3}${ELSE3}${IT3}${IE3} | |
48 | SINK4:= ${0:?${THEN4::=then4${IT4::=t4}}:${ELSE4::=else4${IE4::=e4}}}${THEN4}${ELSE4}${IT4}${IE4} | 50 | SINK4:= ${0:?${THEN4::=then4${IT4::=t4}}:${ELSE4::=else4${IE4::=e4}}}${THEN4}${ELSE4}${IT4}${IE4} | |
51 | ||||
52 | mod-assign-empty: | |||
53 | # Assigning to the empty variable would obviously not work since that variable | |||
54 | # is write-protected. Therefore it is rejected early as a "bad modifier". | |||
55 | @echo ${::=value} | |||
56 | @echo $@: ${:Uvalue::=overwritten} | |||
57 | ||||
58 | # The :L modifier sets the variable's value to its name. | |||
59 | # Since the name is still "VAR", assigning to that variable works. | |||
60 | @echo $@: ${VAR:L::=overwritten} VAR=${VAR} | |||
61 | ||||
62 | mod-assign-parse: | |||
63 | # The modifier for assignment operators starts with a ':'. | |||
64 | # An 'x' after that is an invalid modifier. | |||
65 | @echo ${ASSIGN::x} # 'x' is an unknown assignment operator | |||
66 | ||||
67 | # When parsing an assignment operator fails because the operator is | |||
68 | # incomplete, make falls back to the SysV modifier. | |||
69 | @echo ${SYSV::=sysv\:x}${SYSV::x=:y} | |||
70 | ||||
71 | @echo ${ASSIGN::=value # missing closing brace |