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