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