xref: /src/contrib/bmake/unit-tests/varparse-dynamic.mk (revision 6a7405f5a6b639682cacf01e35d561411ff556aa)
15ad769f6SSimon J. Gerraty# $NetBSD: varparse-dynamic.mk,v 1.10 2025/01/11 21:21:34 rillig Exp $
26bbc783fSSimon J. Gerraty
36bbc783fSSimon J. Gerraty# Before 2020-07-27, there was an off-by-one error in Var_Parse that skipped
46bbc783fSSimon J. Gerraty# the last character in the variable name.
53e39ce56SSimon J. Gerraty# To trigger the bug, the variable had to be undefined.
66bbc783fSSimon J. Gerraty.if ${.TARGET}			# exact match, may be undefined
76bbc783fSSimon J. Gerraty.endif
85ad769f6SSimon J. Gerraty# expect+1: Variable ".TARGEX" is undefined
96bbc783fSSimon J. Gerraty.if ${.TARGEX}			# 1 character difference, must be defined
106bbc783fSSimon J. Gerraty.endif
115ad769f6SSimon J. Gerraty# expect+1: Variable ".TARGXX" is undefined
126bbc783fSSimon J. Gerraty.if ${.TARGXX}			# 2 characters difference, must be defined
136bbc783fSSimon J. Gerraty.endif
146bbc783fSSimon J. Gerraty
15302da1a3SSimon J. Gerraty# When a dynamic variable (such as .TARGET) is evaluated in the global
168b6f73e3SSimon J. Gerraty# scope, it is not yet ready to be expanded.  Therefore the complete
17302da1a3SSimon J. Gerraty# expression is returned as the variable value, hoping that it can be
18302da1a3SSimon J. Gerraty# resolved at a later point.
19302da1a3SSimon J. Gerraty#
20ee914ef9SSimon J. Gerraty# This test covers the code in Var_Parse that deals with DEF_UNDEF but not
21ee914ef9SSimon J. Gerraty# DEF_DEFINED for dynamic variables.
22302da1a3SSimon J. Gerraty.if ${.TARGET:S,^,,} != "\${.TARGET:S,^,,}"
23302da1a3SSimon J. Gerraty.  error
24302da1a3SSimon J. Gerraty.endif
25302da1a3SSimon J. Gerraty
268b6f73e3SSimon J. Gerraty# If a dynamic variable is expanded in a non-local scope, the expression
277a05a715SSimon J. Gerraty# based on this variable is not expanded.  But there may be nested
288e11a9b4SSimon J. Gerraty# expressions in the modifiers, and these are kept unexpanded as well.
298e11a9b4SSimon J. Gerraty.if ${.TARGET:M${:Ufallback}} != "\${.TARGET:M\${:Ufallback}}"
308e11a9b4SSimon J. Gerraty.  error
318e11a9b4SSimon J. Gerraty.endif
328e11a9b4SSimon J. Gerraty.if ${.TARGET:M${UNDEF}} != "\${.TARGET:M\${UNDEF}}"
338e11a9b4SSimon J. Gerraty.  error
348e11a9b4SSimon J. Gerraty.endif
35