moderrs.mk revision 1.8 1 # $Id: moderrs.mk,v 1.8 2020/07/29 20:33:38 rillig Exp $
2 #
3 # various modifier error tests
4
5 VAR=TheVariable
6 # incase we have to change it ;-)
7 MOD_UNKN=Z
8 MOD_TERM=S,V,v
9 MOD_S:= ${MOD_TERM},
10
11 FIB= 1 1 2 3 5 8 13 21 34
12
13 all: modunkn modunknV varterm vartermV modtermV modloop
14 all: modloop-close
15 all: modwords
16 all: modexclam
17 all: mod-subst-delimiter
18 all: mod-regex-delimiter
19 all: mod-ts-parse
20 all: mod-t-parse
21 all: mod-ifelse-parse
22 all: mod-assign-parse
23 all: mod-remember-parse
24 all: mod-sysv-parse
25
26 modunkn:
27 @echo "Expect: Unknown modifier 'Z'"
28 @echo "VAR:Z=${VAR:Z}"
29
30 modunknV:
31 @echo "Expect: Unknown modifier 'Z'"
32 @echo "VAR:${MOD_UNKN}=${VAR:${MOD_UNKN}}"
33
34 varterm:
35 @echo "Expect: Unclosed variable specification for VAR"
36 @echo VAR:S,V,v,=${VAR:S,V,v,
37
38 vartermV:
39 @echo "Expect: Unclosed variable specification for VAR"
40 @echo VAR:${MOD_TERM},=${VAR:${MOD_S}
41
42 modtermV:
43 @echo "Expect: Unclosed substitution for VAR (, missing)"
44 -@echo "VAR:${MOD_TERM}=${VAR:${MOD_TERM}}"
45
46 modloop:
47 @echo "Expect: 2 errors about missing @ delimiter"
48 @echo ${UNDEF:U1 2 3:@var}
49 @echo ${UNDEF:U1 2 3:@var (a] ...}
50 @echo ${UNDEF:U1 2 3:@var@${var}@}
51
52 # The closing brace after the ${var} is part of the replacement string.
53 # In ParseModifierPart, braces and parentheses don't have to be balanced.
54 # This is contrary to the :M, :N modifiers, where both parentheses and
55 # braces must be balanced.
56 # This is also contrary to the SysV modifier, where only the actually
57 # used delimiter (either braces or parentheses) must be balanced.
58 modloop-close:
59 @echo $@:
60 @echo ${UNDEF:U1 2 3:@var@${var}}...@
61 @echo ${UNDEF:U1 2 3:@var@${var}}...@}
62
63 modwords:
64 @echo "Expect: 2 errors about missing ] delimiter"
65 @echo ${UNDEF:U1 2 3:[}
66 @echo ${UNDEF:U1 2 3:[#}
67
68 # out of bounds => empty
69 @echo 13=${UNDEF:U1 2 3:[13]}
70
71 # Word index out of bounds.
72 #
73 # On LP64I32, strtol returns LONG_MAX,
74 # which is then truncated to int (undefined behavior),
75 # typically resulting in -1.
76 # This -1 is interpreted as "the last word".
77 #
78 # On ILP32, strtol returns LONG_MAX,
79 # which is a large number.
80 # This results in a range from LONG_MAX - 1 to 3,
81 # which is empty.
82 @echo 12345=${UNDEF:U1 2 3:[123451234512345123451234512345]:S,^$,ok,:S,^3$,ok,}
83
84 modexclam:
85 @echo "Expect: 2 errors about missing ! delimiter"
86 @echo ${VARNAME:!echo}
87 # When the final exclamation mark is missing, there is no
88 # fallback to the SysV substitution modifier.
89 # If there were a fallback, the output would be "exclam",
90 # and the above would have produced an "Unknown modifier '!'".
91 @echo ${!:L:!=exclam}
92
93 # XXX: For "${VAR:S", I wonder where the "(@ missing)" comes from.
94 # This could be undefined behavior, but it's reproducible.
95 mod-subst-delimiter:
96 @echo $@:
97 @echo ${VAR:S
98 @echo ${VAR:S,
99 @echo ${VAR:S,from
100 @echo ${VAR:S,from,
101 @echo ${VAR:S,from,to
102 @echo ${VAR:S,from,to,
103 @echo ${VAR:S,from,to,}
104 @echo 1: ${VAR:S
105 @echo 2: ${VAR:S,
106 @echo 3: ${VAR:S,from
107 @echo ${VAR:S,from,
108 @echo ${VAR:S,from,to
109 @echo ${VAR:S,from,to,
110 @echo ${VAR:S,from,to,}
111
112 # XXX: Where does the "echo" in the output of "${VAR:C" come from?
113 mod-regex-delimiter:
114 @echo $@:
115 @echo ${VAR:C
116 @echo ${VAR:C,
117 @echo ${VAR:C,from
118 @echo ${VAR:C,from,
119 @echo ${VAR:C,from,to
120 @echo ${VAR:C,from,to,
121 @echo ${VAR:C,from,to,}
122 @echo 1: ${VAR:C
123 @echo 2: ${VAR:C,
124 @echo 3: ${VAR:C,from
125 @echo ${VAR:C,from,
126 @echo ${VAR:C,from,to
127 @echo ${VAR:C,from,to,
128 @echo ${VAR:C,from,to,}
129
130 mod-ts-parse:
131 @echo $@:
132 @echo ${FIB:ts}
133 @echo ${FIB:ts\65} # octal 065 == U+0035 == '5'
134 @echo ${FIB:ts\65oct} # bad modifier
135 @echo ${FIB:tsxy} # modifier too long
136
137 mod-t-parse:
138 @echo $@:
139 @echo ${FIB:txy}
140 @echo ${FIB:t}
141 @echo ${FIB:t:M*}
142
143 mod-ifelse-parse:
144 @echo $@:
145 @echo ${FIB:?
146 @echo ${FIB:?then
147 @echo ${FIB:?then:
148 @echo ${FIB:?then:else
149 @echo ${FIB:?then:else}
150
151 mod-assign-parse:
152 @echo $@:
153 @echo ${ASSIGN::x} # 'x' is an unknown assignment operator
154 @echo ${::=value} # trying to set the empty variable
155 @echo ${ASSIGN::=value # missing closing brace
156
157 mod-remember-parse:
158 @echo $@:
159 @echo ${FIB:_} # ok
160 @echo ${FIB:__} # modifier name too long
161
162 mod-sysv-parse:
163 @echo $@:
164 @echo ${FIB:3
165 @echo ${FIB:3=
166 @echo ${FIB:3=x3
167 @echo ${FIB:3=x3} # ok
168