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