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