moderrs.mk revision 1.13 1 # $Id: moderrs.mk,v 1.13 2020/08/09 15:03:25 rillig Exp $
2 #
3 # various modifier error tests
4
5 VAR=TheVariable
6 # incase 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: modunkn modunknV varterm vartermV modtermV modloop
14 all: modloop-close
15 all: modwords
16 all: modexclam
17 all: mod-subst-delimiter
18 all: mod-regex-delimiter
19 all: mod-regex-undefined-subexpression
20 all: mod-ts-parse
21 all: mod-t-parse
22 all: mod-ifelse-parse
23 all: mod-assign-parse
24 all: mod-remember-parse
25 all: mod-sysv-parse
26
27 modunkn:
28 @echo "Expect: Unknown modifier 'Z'"
29 @echo "VAR:Z=${VAR:Z}"
30
31 modunknV:
32 @echo "Expect: Unknown modifier 'Z'"
33 @echo "VAR:${MOD_UNKN}=${VAR:${MOD_UNKN}}"
34
35 varterm:
36 @echo "Expect: Unclosed variable specification for VAR"
37 @echo VAR:S,V,v,=${VAR:S,V,v,
38
39 vartermV:
40 @echo "Expect: Unclosed variable specification for VAR"
41 @echo VAR:${MOD_TERM},=${VAR:${MOD_S}
42
43 modtermV:
44 @echo "Expect: Unfinished modifier for VAR (',' missing)"
45 -@echo "VAR:${MOD_TERM}=${VAR:${MOD_TERM}}"
46
47 modloop:
48 @echo "Expect: 2 errors about missing @ delimiter"
49 @echo ${UNDEF:U1 2 3:@var}
50 @echo ${UNDEF:U1 2 3:@var (a] ...}
51 @echo ${UNDEF:U1 2 3:@var@${var}@}
52
53 # The closing brace after the ${var} is part of the replacement string.
54 # In ParseModifierPart, braces and parentheses don't have to be balanced.
55 # This is contrary to the :M, :N modifiers, where both parentheses and
56 # braces must be balanced.
57 # This is also contrary to the SysV modifier, where only the actually
58 # used delimiter (either braces or parentheses) must be balanced.
59 modloop-close:
60 @echo $@:
61 @echo ${UNDEF:U1 2 3:@var@${var}}...@
62 @echo ${UNDEF:U1 2 3:@var@${var}}...@}
63
64 modwords:
65 @echo "Expect: 2 errors about missing ] delimiter"
66 @echo ${UNDEF:U1 2 3:[}
67 @echo ${UNDEF:U1 2 3:[#}
68
69 # out of bounds => empty
70 @echo 13=${UNDEF:U1 2 3:[13]}
71
72 # Word index out of bounds.
73 #
74 # On LP64I32, strtol returns LONG_MAX,
75 # which is then truncated to int (undefined behavior),
76 # typically resulting in -1.
77 # This -1 is interpreted as "the last word".
78 #
79 # On ILP32, strtol returns LONG_MAX,
80 # which is a large number.
81 # This results in a range from LONG_MAX - 1 to 3,
82 # which is empty.
83 @echo 12345=${UNDEF:U1 2 3:[123451234512345123451234512345]:S,^$,ok,:S,^3$,ok,}
84
85 modexclam:
86 @echo "Expect: 2 errors about missing ! delimiter"
87 @echo ${VARNAME:!echo}
88 # When the final exclamation mark is missing, there is no
89 # fallback to the SysV substitution modifier.
90 # If there were a fallback, the output would be "exclam",
91 # and the above would have produced an "Unknown modifier '!'".
92 @echo ${!:L:!=exclam}
93
94 mod-subst-delimiter:
95 @echo $@:
96 @echo ${VAR:S
97 @echo ${VAR:S,
98 @echo ${VAR:S,from
99 @echo ${VAR:S,from,
100 @echo ${VAR:S,from,to
101 @echo ${VAR:S,from,to,
102 @echo ${VAR:S,from,to,}
103 @echo 1: ${VAR:S
104 @echo 2: ${VAR:S,
105 @echo 3: ${VAR:S,from
106 @echo ${VAR:S,from,
107 @echo ${VAR:S,from,to
108 @echo ${VAR:S,from,to,
109 @echo ${VAR:S,from,to,}
110
111 mod-regex-delimiter:
112 @echo $@:
113 @echo ${VAR:C
114 @echo ${VAR:C,
115 @echo ${VAR:C,from
116 @echo ${VAR:C,from,
117 @echo ${VAR:C,from,to
118 @echo ${VAR:C,from,to,
119 @echo ${VAR:C,from,to,}
120 @echo 1: ${VAR:C
121 @echo 2: ${VAR:C,
122 @echo 3: ${VAR:C,from
123 @echo ${VAR:C,from,
124 @echo ${VAR:C,from,to
125 @echo ${VAR:C,from,to,
126 @echo ${VAR:C,from,to,}
127
128 # In regular expressions with alternatives, not all capturing groups are
129 # always set; some may be missing. Warn about these.
130 #
131 # Since there is no way to turn off this warning, the combination of
132 # alternative matches and capturing groups is not widely used.
133 #
134 # A newly added modifier 'U' such as in :C,(a.)|(b.),\1\2,U might be added
135 # for treating undefined capturing groups as empty, but that would create a
136 # syntactical ambiguity since the :S and :C modifiers are open-ended (see
137 # mod-subst-chain). Luckily the modifier :U does not make sense after :C,
138 # therefore this case does not happen in practice.
139 # The sub-modifier for the :C modifier would have to be chosen wisely.
140 mod-regex-undefined-subexpression:
141 @echo $@:
142 @echo ${FIB:C,1(.*),one\1,} # all ok
143 @echo ${FIB:C,1(.*)|2(.*),\1+\2,} # no match for subexpression
144
145 mod-ts-parse:
146 @echo $@:
147 @echo ${FIB:ts}
148 @echo ${FIB:ts\65} # octal 065 == U+0035 == '5'
149 @echo ${FIB:ts\65oct} # bad modifier
150 @echo ${FIB:tsxy} # modifier too long
151
152 mod-t-parse:
153 @echo $@:
154 @echo ${FIB:t
155 @echo ${FIB:txy}
156 @echo ${FIB:t}
157 @echo ${FIB:t:M*}
158
159 mod-ifelse-parse:
160 @echo $@:
161 @echo ${FIB:?
162 @echo ${FIB:?then
163 @echo ${FIB:?then:
164 @echo ${FIB:?then:else
165 @echo ${FIB:?then:else}
166
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:
174 @echo $@:
175 @echo ${FIB:_} # ok
176 @echo ${FIB:__} # modifier name too long
177
178 mod-sysv-parse:
179 @echo $@:
180 @echo ${FIB:3
181 @echo ${FIB:3=
182 @echo ${FIB:3=x3
183 @echo ${FIB:3=x3} # ok
184