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