Home | History | Annotate | Line # | Download | only in unit-tests
varparse-errors.mk revision 1.5
      1  1.5  rillig # $NetBSD: varparse-errors.mk,v 1.5 2022/01/24 22:59:49 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 #	VarParseResult
     10  1.1  rillig #	Var_Parse
     11  1.1  rillig #	Var_Subst
     12  1.1  rillig 
     13  1.1  rillig PLAIN=		plain value
     14  1.1  rillig 
     15  1.1  rillig LITERAL_DOLLAR=	To get a dollar, double $$ it.
     16  1.1  rillig 
     17  1.1  rillig INDIRECT=	An ${:Uindirect} value.
     18  1.1  rillig 
     19  1.1  rillig REF_UNDEF=	A reference to an ${UNDEF}undefined variable.
     20  1.1  rillig 
     21  1.1  rillig ERR_UNCLOSED=	An ${UNCLOSED variable expression.
     22  1.1  rillig 
     23  1.1  rillig ERR_BAD_MOD=	An ${:Uindirect:Z} expression with an unknown modifier.
     24  1.1  rillig 
     25  1.1  rillig ERR_EVAL=	An evaluation error ${:Uvalue:C,.,\3,}.
     26  1.1  rillig 
     27  1.1  rillig # In a conditional, a variable expression that is not enclosed in quotes is
     28  1.4  rillig # expanded using the mode VARE_UNDEFERR.
     29  1.1  rillig # The variable itself must be defined.
     30  1.1  rillig # It may refer to undefined variables though.
     31  1.1  rillig .if ${REF_UNDEF} != "A reference to an undefined variable."
     32  1.1  rillig .  error
     33  1.1  rillig .endif
     34  1.1  rillig 
     35  1.2  rillig # As of 2020-12-01, errors in the variable name are silently ignored.
     36  1.3  rillig # Since var.c 1.754 from 2020-12-20, unknown modifiers at parse time result
     37  1.3  rillig # in an error message and a non-zero exit status.
     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.2  rillig VAR.${:U:Z}post=	unknown modifier with text in the variable name
     47  1.2  rillig .if ${VAR.post} != "unknown modifier with text in the variable name"
     48  1.2  rillig .  error
     49  1.2  rillig .endif
     50  1.2  rillig 
     51  1.5  rillig # Demonstrate an edge case in which the 'static' for 'errorReported' in
     52  1.5  rillig # Var_Subst actually makes a difference, preventing "a plethora of messages".
     53  1.5  rillig # Given that this is an edge case and the error message is wrong and thus
     54  1.5  rillig # misleading anyway, that piece of code is probably not necessary.  The wrong
     55  1.5  rillig # condition was added in var.c 1.185 from 2014-05-19.
     56  1.5  rillig #
     57  1.5  rillig # To trigger this difference, the variable assignment must use the assignment
     58  1.5  rillig # operator ':=' to make VarEvalMode_ShouldKeepUndef return true.  There must
     59  1.5  rillig # be 2 expressions that create a parse error, which in this case is ':OX'.
     60  1.5  rillig # These expressions must be nested in some way.  The below expressions are
     61  1.5  rillig # minimal, that is, removing any part of it destroys the effect.
     62  1.5  rillig #
     63  1.5  rillig # Without the 'static', there would be one more message like this:
     64  1.5  rillig #	Undefined variable "${:U:OX"
     65  1.5  rillig #
     66  1.5  rillig #.MAKEFLAGS: -dv
     67  1.5  rillig IND=	${:OX}
     68  1.5  rillig _:=	${:U:OX:U${IND}} ${:U:OX:U${IND}}
     69  1.5  rillig #.MAKEFLAGS: -d0
     70  1.5  rillig 
     71  1.1  rillig all:
     72