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