1*148ee845SSimon J. Gerraty# $NetBSD: varparse-errors.mk,v 1.9 2023/06/01 20:56:35 rillig Exp $ 2e2eeea75SSimon J. Gerraty 3e2eeea75SSimon J. Gerraty# Tests for parsing and evaluating all kinds of variable 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 20e2eeea75SSimon J. GerratyERR_UNCLOSED= An ${UNCLOSED variable 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 26e2eeea75SSimon J. Gerraty# In a conditional, a variable expression that is not enclosed in quotes is 27b0c40a00SSimon J. Gerraty# expanded using the mode VARE_UNDEFERR. 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*148ee845SSimon J. Gerraty# expect+1: 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*148ee845SSimon J. Gerraty# expect+1: 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*148ee845SSimon J. Gerraty# expect+2: Undefined variable "${:U:OX" 70*148ee845SSimon J. Gerraty# expect+1: Undefined variable "${:U:OX" 719f45a3c8SSimon J. Gerraty_:= ${:U:OX:U${IND}} ${:U:OX:U${IND}} 729f45a3c8SSimon J. Gerraty#.MAKEFLAGS: -d0 739f45a3c8SSimon J. Gerraty 744fde40d9SSimon J. Gerraty 754fde40d9SSimon J. Gerraty# Before var.c 1.032 from 2022-08-24, make complained about 'Unknown modifier' 764fde40d9SSimon J. Gerraty# or 'Bad modifier' when in fact the modifier was entirely correct, it was 774fde40d9SSimon J. Gerraty# just not delimited by either ':' or '}' but instead by '\0'. 784fde40d9SSimon J. GerratyUNCLOSED:= ${:U:Q 794fde40d9SSimon J. GerratyUNCLOSED:= ${:U:sh 804fde40d9SSimon J. GerratyUNCLOSED:= ${:U:tA 814fde40d9SSimon J. GerratyUNCLOSED:= ${:U:tsX 824fde40d9SSimon J. GerratyUNCLOSED:= ${:U:ts 834fde40d9SSimon J. GerratyUNCLOSED:= ${:U:ts\040 844fde40d9SSimon J. GerratyUNCLOSED:= ${:U:u 854fde40d9SSimon J. GerratyUNCLOSED:= ${:U:H 864fde40d9SSimon J. GerratyUNCLOSED:= ${:U:[1] 874fde40d9SSimon J. GerratyUNCLOSED:= ${:U:hash 884fde40d9SSimon J. GerratyUNCLOSED:= ${:U:range 894fde40d9SSimon J. GerratyUNCLOSED:= ${:U:_ 904fde40d9SSimon J. GerratyUNCLOSED:= ${:U:gmtime 914fde40d9SSimon J. GerratyUNCLOSED:= ${:U:localtime 92