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