1 # $NetBSD: moderrs.mk,v 1.24 2020/11/01 14:36:25 rillig Exp $
3 # various modifier error tests
7 # in case we have to change it ;-)
12 FIB= 1 1 2 3 5 8 13 21 34
14 all: mod-unknown-direct mod-unknown-indirect
15 all: unclosed-direct unclosed-indirect
16 all: unfinished-indirect unfinished-loop
20 all: mod-subst-delimiter
21 all: mod-regex-delimiter
22 all: mod-regex-undefined-subexpression
26 all: mod-remember-parse
29 mod-unknown-direct: print-header print-footer
30 @echo 'want: Unknown modifier $'Z$''
31 @echo 'VAR:Z=before-${VAR:Z}-after'
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'
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,
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}
45 unfinished-indirect: print-header print-footer
46 @echo 'want: Unfinished modifier for VAR ($',$' missing)'
47 -@echo "VAR:${MOD_TERM}=${VAR:${MOD_TERM}}"
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@...}
54 @echo ${UNDEF:U1 2 3:@var@${var}@}
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}}...@}
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:[#}
72 # out of bounds => empty
73 @echo 13=${UNDEF:U1 2 3:[13]}
75 # Word index out of bounds.
77 # Until 2020-11-01, the behavior in this case depended upon the size
80 # On LP64I32, strtol returns LONG_MAX, which was then truncated to
81 # int (undefined behavior), typically resulting in -1. This -1 was
82 # interpreted as "the last word".
84 # On ILP32, strtol returns LONG_MAX, which is a large number. This
85 # resulted in a range from LONG_MAX - 1 to 3, which was empty.
87 # Since 2020-11-01, the numeric overflow is detected and generates an
88 # error. In the remainder of the text, the '$,' is no longer parsed
89 # as part of a variable modifier, where it would have been interpreted
90 # as an anchor to the :S modifier, but as a normal variable named ','.
91 # That variable is undefined, resulting in an empty string.
92 @echo 12345=${UNDEF:U1 2 3:[123451234512345123451234512345]:S,^$,ok,:S,^3$,ok,}
94 exclam: print-header print-footer
95 @echo 'want: Unfinished modifier for VARNAME ($'!$' missing)'
96 @echo ${VARNAME:!echo}
97 # When the final exclamation mark is missing, there is no
98 # fallback to the SysV substitution modifier.
99 # If there were a fallback, the output would be "exclam",
100 # and the above would have produced an "Unknown modifier '!'".
101 @echo 'want: Unfinished modifier for ! ($'!$' missing)'
102 @echo ${!:L:!=exclam}
104 mod-subst-delimiter: print-header print-footer
107 @echo 3: ${VAR:S,from
108 @echo 4: ${VAR:S,from,
109 @echo 5: ${VAR:S,from,to
110 @echo 6: ${VAR:S,from,to,
111 @echo 7: ${VAR:S,from,to,}
113 mod-regex-delimiter: print-header print-footer
116 @echo 3: ${VAR:C,from
117 @echo 4: ${VAR:C,from,
118 @echo 5: ${VAR:C,from,to
119 @echo 6: ${VAR:C,from,to,
120 @echo 7: ${VAR:C,from,to,}
122 # In regular expressions with alternatives, not all capturing groups are
123 # always set; some may be missing. Warn about these.
125 # Since there is no way to turn off this warning, the combination of
126 # alternative matches and capturing groups is not widely used.
128 # A newly added modifier 'U' such as in :C,(a.)|(b.),\1\2,U might be added
129 # for treating undefined capturing groups as empty, but that would create a
130 # syntactical ambiguity since the :S and :C modifiers are open-ended (see
131 # mod-subst-chain). Luckily the modifier :U does not make sense after :C,
132 # therefore this case does not happen in practice.
133 # The sub-modifier for the :S and :C modifiers would have to be chosen
134 # wisely, to not create ambiguities while parsing.
135 mod-regex-undefined-subexpression: print-header print-footer
136 @echo ${FIB:C,1(.*),one\1,} # all ok
137 @echo ${FIB:C,1(.*)|2(.*),(\1)+(\2),:Q} # no match for subexpression
139 mod-ts-parse: print-header print-footer
141 @echo ${FIB:ts\65} # octal 065 == U+0035 == '5'
142 @echo ${FIB:ts\65oct} # bad modifier
143 @echo ${FIB:tsxy} # modifier too long
145 mod-t-parse: print-header print-footer
151 mod-ifelse-parse: print-header print-footer
155 @echo ${FIB:?then:else
156 @echo ${FIB:?then:else}
158 mod-remember-parse: print-header print-footer
160 @echo ${FIB:__} # modifier name too long
162 mod-sysv-parse: print-header print-footer
166 @echo ${FIB:3=x3} # ok
168 print-header: .USEBEFORE