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