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