xref: /freebsd/contrib/bmake/unit-tests/varparse-errors.mk (revision 6580f5c38dd5b01aeeaed16b370f1a12423437f0)
1# $NetBSD: varparse-errors.mk,v 1.12 2024/04/20 10:18:56 rillig Exp $
2
3# Tests for parsing and evaluating all kinds of expressions.
4#
5# This is the basis for redesigning the error handling in Var_Parse and
6# Var_Subst, collecting typical and not so typical use cases.
7#
8# See also:
9#	Var_Parse
10#	Var_Subst
11
12PLAIN=		plain value
13
14LITERAL_DOLLAR=	To get a dollar, double $$ it.
15
16INDIRECT=	An ${:Uindirect} value.
17
18REF_UNDEF=	A reference to an ${UNDEF}undefined variable.
19
20ERR_UNCLOSED=	An ${UNCLOSED expression.
21
22ERR_BAD_MOD=	An ${:Uindirect:Z} expression with an unknown modifier.
23
24ERR_EVAL=	An evaluation error ${:Uvalue:C,.,\3,}.
25
26# In a conditional, an expression that is not enclosed in quotes is
27# expanded using the mode VARE_UNDEFERR.
28# The variable itself must be defined.
29# It may refer to undefined variables though.
30.if ${REF_UNDEF} != "A reference to an undefined variable."
31.  error
32.endif
33
34# As of 2020-12-01, errors in the variable name are silently ignored.
35# Since var.c 1.754 from 2020-12-20, unknown modifiers at parse time result
36# in an error message and a non-zero exit status.
37# expect+1: while evaluating "${:U:Z}": Unknown modifier "Z"
38VAR.${:U:Z}=	unknown modifier in the variable name
39.if ${VAR.} != "unknown modifier in the variable name"
40.  error
41.endif
42
43# As of 2020-12-01, errors in the variable name are silently ignored.
44# Since var.c 1.754 from 2020-12-20, unknown modifiers at parse time result
45# in an error message and a non-zero exit status.
46# expect+1: while evaluating "${:U:Z}post": Unknown modifier "Z"
47VAR.${:U:Z}post=	unknown modifier with text in the variable name
48.if ${VAR.post} != "unknown modifier with text in the variable name"
49.  error
50.endif
51
52# Demonstrate an edge case in which the 'static' for 'errorReported' in
53# Var_Subst actually makes a difference, preventing "a plethora of messages".
54# Given that this is an edge case and the error message is wrong and thus
55# misleading anyway, that piece of code is probably not necessary.  The wrong
56# condition was added in var.c 1.185 from 2014-05-19.
57#
58# To trigger this difference, the variable assignment must use the assignment
59# operator ':=' to make VarEvalMode_ShouldKeepUndef return true.  There must
60# be 2 expressions that create a parse error, which in this case is ':OX'.
61# These expressions must be nested in some way.  The below expressions are
62# minimal, that is, removing any part of it destroys the effect.
63#
64# Without the 'static', there would be one more message like this:
65#	Undefined variable "${:U:OX"
66#
67#.MAKEFLAGS: -dv
68IND=	${:OX}
69# expect+2: Undefined variable "${:U:OX"
70# expect+1: Undefined variable "${:U:OX"
71_:=	${:U:OX:U${IND}} ${:U:OX:U${IND}}
72#.MAKEFLAGS: -d0
73
74
75# Before var.c 1.032 from 2022-08-24, make complained about 'Unknown modifier'
76# or 'Bad modifier' when in fact the modifier was entirely correct, it was
77# just not delimited by either ':' or '}' but instead by '\0'.
78UNCLOSED:=	${:U:Q
79UNCLOSED:=	${:U:sh
80UNCLOSED:=	${:U:tA
81UNCLOSED:=	${:U:tsX
82UNCLOSED:=	${:U:ts
83UNCLOSED:=	${:U:ts\040
84UNCLOSED:=	${:U:u
85UNCLOSED:=	${:U:H
86UNCLOSED:=	${:U:[1]
87UNCLOSED:=	${:U:hash
88UNCLOSED:=	${:U:range
89UNCLOSED:=	${:U:_
90UNCLOSED:=	${:U:gmtime
91UNCLOSED:=	${:U:localtime
92