xref: /freebsd/contrib/bmake/unit-tests/varparse-errors.mk (revision 06b9b3e0ad0dc3f0166b3e8f26ced68c271cf527)
1*06b9b3e0SSimon J. Gerraty# $NetBSD: varparse-errors.mk,v 1.3 2020/12/20 19:47:34 rillig Exp $
2e2eeea75SSimon J. Gerraty
3e2eeea75SSimon J. Gerraty# Tests for parsing and evaluating all kinds of variable expressions.
4e2eeea75SSimon J. Gerraty#
5e2eeea75SSimon J. Gerraty# This is the basis for redesigning the error handling in Var_Parse and
6e2eeea75SSimon J. Gerraty# Var_Subst, collecting typical and not so typical use cases.
7e2eeea75SSimon J. Gerraty#
8e2eeea75SSimon J. Gerraty# See also:
9e2eeea75SSimon J. Gerraty#	VarParseResult
10e2eeea75SSimon J. Gerraty#	Var_Parse
11e2eeea75SSimon J. Gerraty#	Var_Subst
12e2eeea75SSimon J. Gerraty
13e2eeea75SSimon J. GerratyPLAIN=		plain value
14e2eeea75SSimon J. Gerraty
15e2eeea75SSimon J. GerratyLITERAL_DOLLAR=	To get a dollar, double $$ it.
16e2eeea75SSimon J. Gerraty
17e2eeea75SSimon J. GerratyINDIRECT=	An ${:Uindirect} value.
18e2eeea75SSimon J. Gerraty
19e2eeea75SSimon J. GerratyREF_UNDEF=	A reference to an ${UNDEF}undefined variable.
20e2eeea75SSimon J. Gerraty
21e2eeea75SSimon J. GerratyERR_UNCLOSED=	An ${UNCLOSED variable expression.
22e2eeea75SSimon J. Gerraty
23e2eeea75SSimon J. GerratyERR_BAD_MOD=	An ${:Uindirect:Z} expression with an unknown modifier.
24e2eeea75SSimon J. Gerraty
25e2eeea75SSimon J. GerratyERR_EVAL=	An evaluation error ${:Uvalue:C,.,\3,}.
26e2eeea75SSimon J. Gerraty
27e2eeea75SSimon J. Gerraty# In a conditional, a variable expression that is not enclosed in quotes is
28e2eeea75SSimon J. Gerraty# expanded using the flags VARE_UNDEFERR and VARE_WANTRES.
29e2eeea75SSimon J. Gerraty# The variable itself must be defined.
30e2eeea75SSimon J. Gerraty# It may refer to undefined variables though.
31e2eeea75SSimon J. Gerraty.if ${REF_UNDEF} != "A reference to an undefined variable."
32e2eeea75SSimon J. Gerraty.  error
33e2eeea75SSimon J. Gerraty.endif
34e2eeea75SSimon J. Gerraty
35*06b9b3e0SSimon J. Gerraty# As of 2020-12-01, errors in the variable name are silently ignored.
36*06b9b3e0SSimon J. Gerraty# Since var.c 1.754 from 2020-12-20, unknown modifiers at parse time result
37*06b9b3e0SSimon J. Gerraty# in an error message and a non-zero exit status.
38*06b9b3e0SSimon J. GerratyVAR.${:U:Z}=	unknown modifier in the variable name
39*06b9b3e0SSimon J. Gerraty.if ${VAR.} != "unknown modifier in the variable name"
40*06b9b3e0SSimon J. Gerraty.  error
41*06b9b3e0SSimon J. Gerraty.endif
42*06b9b3e0SSimon J. Gerraty
43*06b9b3e0SSimon J. Gerraty# As of 2020-12-01, errors in the variable name are silently ignored.
44*06b9b3e0SSimon J. Gerraty# Since var.c 1.754 from 2020-12-20, unknown modifiers at parse time result
45*06b9b3e0SSimon J. Gerraty# in an error message and a non-zero exit status.
46*06b9b3e0SSimon J. GerratyVAR.${:U:Z}post=	unknown modifier with text in the variable name
47*06b9b3e0SSimon J. Gerraty.if ${VAR.post} != "unknown modifier with text in the variable name"
48*06b9b3e0SSimon J. Gerraty.  error
49*06b9b3e0SSimon J. Gerraty.endif
50*06b9b3e0SSimon J. Gerraty
51e2eeea75SSimon J. Gerratyall:
52