moderrs.mk revision 1.41 1 # $NetBSD: moderrs.mk,v 1.41 2024/08/29 20:20:36 rillig Exp $
2 #
3 # various modifier error tests
4
5 VAR= TheVariable
6 # in case we have to change it ;-)
7 MOD_UNKN= Z
8 MOD_TERM= S,V,v
9 MOD_S:= ${MOD_TERM},
10
11 FIB= 1 1 2 3 5 8 13 21 34
12
13 all: mod-unknown-direct mod-unknown-indirect
14 all: unclosed-direct unclosed-indirect
15 all: unfinished-indirect unfinished-loop-{1,2,3}
16 all: loop-close-{1,2}
17 all: words-{1,2,3}
18 all: exclam-{1,2}
19 all: mod-subst-delimiter-{1,2,3,4,5,6,7}
20 all: mod-regex-delimiter-{1,2,3,4,5,6,7}
21 all: mod-ts-parse-{1,2,3,4,5}
22 all: mod-t-parse-{1,2,3,4}
23 all: mod-ifelse-parse-{1,2,3,4,5}
24 all: mod-remember-parse
25 all: mod-sysv-parse-{1,2,3,4}
26
27 mod-unknown-direct:
28 # expect: make: Unknown modifier "Z"
29 @echo 'VAR:Z=before-${VAR:Z}-after'
30
31 mod-unknown-indirect:
32 # expect: make: Unknown modifier "Z"
33 @echo 'VAR:${MOD_UNKN}=before-${VAR:${MOD_UNKN}:inner}-after'
34
35 unclosed-direct:
36 # expect: make: Unclosed expression, expecting '}' for modifier "S,V,v,"
37 @echo VAR:S,V,v,=${VAR:S,V,v,
38
39 unclosed-indirect:
40 # expect: make: Unclosed expression after indirect modifier, expecting '}'
41 @echo VAR:${MOD_TERM},=${VAR:${MOD_S}
42
43 unfinished-indirect:
44 # expect: make: Unfinished modifier (',' missing)
45 -@echo "VAR:${MOD_TERM}=${VAR:${MOD_TERM}}"
46
47 unfinished-loop-1:
48 # expect: make: Unfinished modifier ('@' missing)
49 @echo ${UNDEF:U1 2 3:@var}
50 unfinished-loop-2:
51 # expect: make: Unfinished modifier ('@' missing)
52 @echo ${UNDEF:U1 2 3:@var (a] ...}
53 unfinished-loop-3:
54 @echo ${UNDEF:U1 2 3:@var@${var}@}
55
56 # The closing brace after the ${var} is part of the replacement string.
57 # In ParseModifierPart, braces and parentheses don't have to be balanced.
58 # This is contrary to the :M, :N modifiers, where both parentheses and
59 # braces must be balanced.
60 # This is also contrary to the SysV modifier, where only the actually
61 # used delimiter (either braces or parentheses) must be balanced.
62 loop-close-1:
63 # expect: make: Unclosed expression, expecting '}' for modifier "@var@${var}}...@"
64 @echo ${UNDEF:U1 2 3:@var@${var}}...@
65 loop-close-2:
66 @echo ${UNDEF:U1 2 3:@var@${var}}...@}
67
68 words-1:
69 # expect: make: Unfinished modifier (']' missing)
70 @echo ${UNDEF:U1 2 3:[}
71 words-2:
72 # expect: make: Unfinished modifier (']' missing)
73 @echo ${UNDEF:U1 2 3:[#}
74
75 words-3:
76 # out of bounds => empty
77 @echo 13=${UNDEF:U1 2 3:[13]}
78
79 # Word index out of bounds.
80 #
81 # Until 2020-11-01, the behavior in this case depended upon the size
82 # of unsigned long.
83 #
84 # On LP64I32, strtol returns LONG_MAX, which was then truncated to
85 # int (undefined behavior), typically resulting in -1. This -1 was
86 # interpreted as "the last word".
87 #
88 # On ILP32, strtol returns LONG_MAX, which is a large number. This
89 # resulted in a range from LONG_MAX - 1 to 3, which was empty.
90 #
91 # Since 2020-11-01, the numeric overflow is detected and generates an
92 # error. In the remainder of the text, the '$,' is no longer parsed
93 # as part of a variable modifier, where it would have been interpreted
94 # as an anchor to the :S modifier, but as a normal variable named ','.
95 # That variable is undefined, resulting in an empty string.
96 @echo 12345=${UNDEF:U1 2 3:[123451234512345123451234512345]:S,^$,ok,:S,^3$,ok,}
97
98 exclam-1:
99 # expect: make: Unfinished modifier ('!' missing)
100 @echo ${VARNAME:!echo}
101 # When the final exclamation mark is missing, there is no
102 # fallback to the SysV substitution modifier.
103 # If there were a fallback, the output would be "exclam",
104 # and the above would have produced an "Unknown modifier '!'".
105 exclam-2:
106 # expect: make: Unfinished modifier ('!' missing)
107 @echo ${!:L:!=exclam}
108
109 mod-subst-delimiter-1:
110 # expect: make: Missing delimiter for modifier ':S'
111 @echo 1: ${VAR:S
112 mod-subst-delimiter-2:
113 # expect: make: Unfinished modifier (',' missing)
114 @echo 2: ${VAR:S,
115 mod-subst-delimiter-3:
116 # expect: make: Unfinished modifier (',' missing)
117 @echo 3: ${VAR:S,from
118 mod-subst-delimiter-4:
119 # expect: make: Unfinished modifier (',' missing)
120 @echo 4: ${VAR:S,from,
121 mod-subst-delimiter-5:
122 # expect: make: Unfinished modifier (',' missing)
123 @echo 5: ${VAR:S,from,to
124 mod-subst-delimiter-6:
125 # expect: make: Unclosed expression, expecting '}' for modifier "S,from,to,"
126 @echo 6: ${VAR:S,from,to,
127 mod-subst-delimiter-7:
128 @echo 7: ${VAR:S,from,to,}
129
130 mod-regex-delimiter-1:
131 # expect: make: Missing delimiter for modifier ':C'
132 @echo 1: ${VAR:C
133 mod-regex-delimiter-2:
134 # expect: make: Unfinished modifier (',' missing)
135 @echo 2: ${VAR:C,
136 mod-regex-delimiter-3:
137 # expect: make: Unfinished modifier (',' missing)
138 @echo 3: ${VAR:C,from
139 mod-regex-delimiter-4:
140 # expect: make: Unfinished modifier (',' missing)
141 @echo 4: ${VAR:C,from,
142 mod-regex-delimiter-5:
143 # expect: make: Unfinished modifier (',' missing)
144 @echo 5: ${VAR:C,from,to
145 mod-regex-delimiter-6:
146 # expect: make: Unclosed expression, expecting '}' for modifier "C,from,to,"
147 @echo 6: ${VAR:C,from,to,
148 mod-regex-delimiter-7:
149 @echo 7: ${VAR:C,from,to,}
150
151 mod-ts-parse-1:
152 @echo ${FIB:ts}
153 mod-ts-parse-2:
154 @echo ${FIB:ts\65} # octal 065 == U+0035 == '5'
155 mod-ts-parse-3:
156 # expect: make: Bad modifier ":ts\65oct"
157 @echo ${FIB:ts\65oct} # bad modifier
158 mod-ts-parse-4:
159 # expect: make: Bad modifier ":ts\65oct"
160 @echo ${:U${FIB}:ts\65oct} # bad modifier, variable name is ""
161 mod-ts-parse-5:
162 # expect: make: Bad modifier ":tsxy"
163 @echo ${FIB:tsxy} # modifier too long
164
165 mod-t-parse-1:
166 # expect: make: Bad modifier ":t"
167 @echo ${FIB:t
168 mod-t-parse-2:
169 # expect: make: Bad modifier ":txy"
170 @echo ${FIB:txy}
171 mod-t-parse-3:
172 # expect: make: Bad modifier ":t"
173 @echo ${FIB:t}
174 mod-t-parse-4:
175 # expect: make: Bad modifier ":t"
176 @echo ${FIB:t:M*}
177
178 mod-ifelse-parse-1:
179 # expect: make: Unfinished modifier (':' missing)
180 @echo ${FIB:?
181 mod-ifelse-parse-2:
182 # expect: make: Unfinished modifier (':' missing)
183 @echo ${FIB:?then
184 mod-ifelse-parse-3:
185 # expect: make: Unfinished modifier ('}' missing)
186 @echo ${FIB:?then:
187 mod-ifelse-parse-4:
188 # expect: make: Unfinished modifier ('}' missing)
189 @echo ${FIB:?then:else
190 mod-ifelse-parse-5:
191 @echo ${FIB:?then:else}
192
193 mod-remember-parse:
194 @echo ${FIB:_} # ok
195 # expect: make: Unknown modifier "__"
196 @echo ${FIB:__} # modifier name too long
197
198 mod-sysv-parse-1:
199 # expect: make: Unknown modifier "3"
200 # expect: make: Unclosed expression, expecting '}' for modifier "3"
201 @echo ${FIB:3
202 mod-sysv-parse-2:
203 # expect: make: Unknown modifier "3="
204 # expect: make: Unclosed expression, expecting '}' for modifier "3="
205 @echo ${FIB:3=
206 mod-sysv-parse-3:
207 # expect: make: Unknown modifier "3=x3"
208 # expect: make: Unclosed expression, expecting '}' for modifier "3=x3"
209 @echo ${FIB:3=x3
210 mod-sysv-parse-4:
211 @echo ${FIB:3=x3} # ok
212