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