1*22619282SSimon J. Gerraty# $NetBSD: varparse-errors.mk,v 1.17 2024/07/05 19:47:22 rillig Exp $ 2e2eeea75SSimon J. Gerraty 3d5e0a182SSimon J. Gerraty# Tests for parsing and evaluating all kinds of 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# Var_Parse 10e2eeea75SSimon J. Gerraty# Var_Subst 11e2eeea75SSimon J. Gerraty 12e2eeea75SSimon J. GerratyPLAIN= plain value 13e2eeea75SSimon J. Gerraty 14e2eeea75SSimon J. GerratyLITERAL_DOLLAR= To get a dollar, double $$ it. 15e2eeea75SSimon J. Gerraty 16e2eeea75SSimon J. GerratyINDIRECT= An ${:Uindirect} value. 17e2eeea75SSimon J. Gerraty 18e2eeea75SSimon J. GerratyREF_UNDEF= A reference to an ${UNDEF}undefined variable. 19e2eeea75SSimon J. Gerraty 20d5e0a182SSimon J. GerratyERR_UNCLOSED= An ${UNCLOSED expression. 21e2eeea75SSimon J. Gerraty 22e2eeea75SSimon J. GerratyERR_BAD_MOD= An ${:Uindirect:Z} expression with an unknown modifier. 23e2eeea75SSimon J. Gerraty 24e2eeea75SSimon J. GerratyERR_EVAL= An evaluation error ${:Uvalue:C,.,\3,}. 25e2eeea75SSimon J. Gerraty 26d5e0a182SSimon J. Gerraty# In a conditional, an expression that is not enclosed in quotes is 278d5c8e21SSimon J. Gerraty# expanded using the mode VARE_EVAL_DEFINED. 28e2eeea75SSimon J. Gerraty# The variable itself must be defined. 29e2eeea75SSimon J. Gerraty# It may refer to undefined variables though. 30e2eeea75SSimon J. Gerraty.if ${REF_UNDEF} != "A reference to an undefined variable." 31e2eeea75SSimon J. Gerraty. error 32e2eeea75SSimon J. Gerraty.endif 33e2eeea75SSimon J. Gerraty 3406b9b3e0SSimon J. Gerraty# As of 2020-12-01, errors in the variable name are silently ignored. 3506b9b3e0SSimon J. Gerraty# Since var.c 1.754 from 2020-12-20, unknown modifiers at parse time result 3606b9b3e0SSimon J. Gerraty# in an error message and a non-zero exit status. 37*22619282SSimon J. Gerraty# expect+1: while evaluating "${:U:Z}" with value "": Unknown modifier "Z" 3806b9b3e0SSimon J. GerratyVAR.${:U:Z}= unknown modifier in the variable name 3906b9b3e0SSimon J. Gerraty.if ${VAR.} != "unknown modifier in the variable name" 4006b9b3e0SSimon J. Gerraty. error 4106b9b3e0SSimon J. Gerraty.endif 4206b9b3e0SSimon J. Gerraty 4306b9b3e0SSimon J. Gerraty# As of 2020-12-01, errors in the variable name are silently ignored. 4406b9b3e0SSimon J. Gerraty# Since var.c 1.754 from 2020-12-20, unknown modifiers at parse time result 4506b9b3e0SSimon J. Gerraty# in an error message and a non-zero exit status. 46*22619282SSimon J. Gerraty# expect+1: while evaluating "${:U:Z}post" with value "": Unknown modifier "Z" 4706b9b3e0SSimon J. GerratyVAR.${:U:Z}post= unknown modifier with text in the variable name 4806b9b3e0SSimon J. Gerraty.if ${VAR.post} != "unknown modifier with text in the variable name" 4906b9b3e0SSimon J. Gerraty. error 5006b9b3e0SSimon J. Gerraty.endif 5106b9b3e0SSimon J. Gerraty 529f45a3c8SSimon J. Gerraty# Demonstrate an edge case in which the 'static' for 'errorReported' in 539f45a3c8SSimon J. Gerraty# Var_Subst actually makes a difference, preventing "a plethora of messages". 549f45a3c8SSimon J. Gerraty# Given that this is an edge case and the error message is wrong and thus 559f45a3c8SSimon J. Gerraty# misleading anyway, that piece of code is probably not necessary. The wrong 569f45a3c8SSimon J. Gerraty# condition was added in var.c 1.185 from 2014-05-19. 579f45a3c8SSimon J. Gerraty# 589f45a3c8SSimon J. Gerraty# To trigger this difference, the variable assignment must use the assignment 599f45a3c8SSimon J. Gerraty# operator ':=' to make VarEvalMode_ShouldKeepUndef return true. There must 609f45a3c8SSimon J. Gerraty# be 2 expressions that create a parse error, which in this case is ':OX'. 619f45a3c8SSimon J. Gerraty# These expressions must be nested in some way. The below expressions are 629f45a3c8SSimon J. Gerraty# minimal, that is, removing any part of it destroys the effect. 639f45a3c8SSimon J. Gerraty# 649f45a3c8SSimon J. Gerraty# Without the 'static', there would be one more message like this: 659f45a3c8SSimon J. Gerraty# Undefined variable "${:U:OX" 669f45a3c8SSimon J. Gerraty# 679f45a3c8SSimon J. Gerraty#.MAKEFLAGS: -dv 689f45a3c8SSimon J. GerratyIND= ${:OX} 69*22619282SSimon J. Gerraty# expect+6: while evaluating "${:U:OX:U${IND}} ${:U:OX:U${IND}}" with value "": Bad modifier ":OX" 70*22619282SSimon J. Gerraty# expect+5: while evaluating "${:U:OX:U${IND}}" with value "": Bad modifier ":OX" 71*22619282SSimon J. Gerraty# expect+4: Undefined variable "${:U:OX" 72*22619282SSimon J. Gerraty# expect+3: while evaluating variable "IND" with value "${:OX}": while evaluating "${:OX}" with value "": Bad modifier ":OX" 73148ee845SSimon J. Gerraty# expect+2: Undefined variable "${:U:OX" 74*22619282SSimon J. Gerraty# expect+1: while evaluating variable "IND" with value "${:OX}": while evaluating "${:OX}" with value "": Bad modifier ":OX" 759f45a3c8SSimon J. Gerraty_:= ${:U:OX:U${IND}} ${:U:OX:U${IND}} 769f45a3c8SSimon J. Gerraty#.MAKEFLAGS: -d0 779f45a3c8SSimon J. Gerraty 784fde40d9SSimon J. Gerraty 794fde40d9SSimon J. Gerraty# Before var.c 1.032 from 2022-08-24, make complained about 'Unknown modifier' 804fde40d9SSimon J. Gerraty# or 'Bad modifier' when in fact the modifier was entirely correct, it was 814fde40d9SSimon J. Gerraty# just not delimited by either ':' or '}' but instead by '\0'. 82*22619282SSimon J. Gerraty# expect+1: while evaluating "${:U:Q" with value "": Unclosed expression, expecting '}' for modifier "Q" 834fde40d9SSimon J. GerratyUNCLOSED:= ${:U:Q 84*22619282SSimon J. Gerraty# expect+1: while evaluating "${:U:sh" with value "": Unclosed expression, expecting '}' for modifier "sh" 854fde40d9SSimon J. GerratyUNCLOSED:= ${:U:sh 86*22619282SSimon J. Gerraty# expect+1: while evaluating "${:U:tA" with value "": Unclosed expression, expecting '}' for modifier "tA" 874fde40d9SSimon J. GerratyUNCLOSED:= ${:U:tA 88*22619282SSimon J. Gerraty# expect+1: while evaluating "${:U:tsX" with value "": Unclosed expression, expecting '}' for modifier "tsX" 894fde40d9SSimon J. GerratyUNCLOSED:= ${:U:tsX 90*22619282SSimon J. Gerraty# expect+1: while evaluating "${:U:ts" with value "": Unclosed expression, expecting '}' for modifier "ts" 914fde40d9SSimon J. GerratyUNCLOSED:= ${:U:ts 92*22619282SSimon J. Gerraty# expect+1: while evaluating "${:U:ts\040" with value "": Unclosed expression, expecting '}' for modifier "ts\040" 934fde40d9SSimon J. GerratyUNCLOSED:= ${:U:ts\040 94*22619282SSimon J. Gerraty# expect+1: while evaluating "${:U:u" with value "": Unclosed expression, expecting '}' for modifier "u" 954fde40d9SSimon J. GerratyUNCLOSED:= ${:U:u 96*22619282SSimon J. Gerraty# expect+1: while evaluating "${:U:H" with value ".": Unclosed expression, expecting '}' for modifier "H" 974fde40d9SSimon J. GerratyUNCLOSED:= ${:U:H 98*22619282SSimon J. Gerraty# expect+1: while evaluating "${:U:[1]" with value "": Unclosed expression, expecting '}' for modifier "[1]" 994fde40d9SSimon J. GerratyUNCLOSED:= ${:U:[1] 100*22619282SSimon J. Gerraty# expect+1: while evaluating "${:U:hash" with value "b2af338b": Unclosed expression, expecting '}' for modifier "hash" 1014fde40d9SSimon J. GerratyUNCLOSED:= ${:U:hash 102*22619282SSimon J. Gerraty# expect+1: while evaluating "${:U:range" with value "1": Unclosed expression, expecting '}' for modifier "range" 1034fde40d9SSimon J. GerratyUNCLOSED:= ${:U:range 104*22619282SSimon J. Gerraty# expect+1: while evaluating "${:U:_" with value "": Unclosed expression, expecting '}' for modifier "_" 1054fde40d9SSimon J. GerratyUNCLOSED:= ${:U:_ 106*22619282SSimon J. Gerraty# expect+1: while evaluating "${:U:gmtime" with value "<timestamp>": Unclosed expression, expecting '}' for modifier "gmtime" 1074fde40d9SSimon J. GerratyUNCLOSED:= ${:U:gmtime 108*22619282SSimon J. Gerraty# expect+1: while evaluating "${:U:localtime" with value "<timestamp>": Unclosed expression, expecting '}' for modifier "localtime" 1094fde40d9SSimon J. GerratyUNCLOSED:= ${:U:localtime 110