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