xref: /freebsd/contrib/bmake/unit-tests/varparse-dynamic.mk (revision 9f44a47fd07924afc035991af15d84e6585dea4f)
1# $NetBSD: varparse-dynamic.mk,v 1.5 2021/02/22 20:38:55 rillig Exp $
2
3# Before 2020-07-27, there was an off-by-one error in Var_Parse that skipped
4# the last character in the variable name.
5# To trigger the bug, the variable must not be defined.
6.if ${.TARGET}			# exact match, may be undefined
7.endif
8.if ${.TARGEX}			# 1 character difference, must be defined
9.endif
10.if ${.TARGXX}			# 2 characters difference, must be defined
11.endif
12
13# When a dynamic variable (such as .TARGET) is evaluated in the global
14# scope, it is not yet ready to be expanded.  Therefore the complete
15# expression is returned as the variable value, hoping that it can be
16# resolved at a later point.
17#
18# This test covers the code in Var_Parse that deals with DEF_UNDEF but not
19# DEF_DEFINED for dynamic variables.
20.if ${.TARGET:S,^,,} != "\${.TARGET:S,^,,}"
21.  error
22.endif
23
24# If a dynamic variable is expanded in a non-local scope, the expression
25# based on this variable is not expanded.  But there may be nested variable
26# expressions in the modifiers, and these are kept unexpanded as well.
27.if ${.TARGET:M${:Ufallback}} != "\${.TARGET:M\${:Ufallback}}"
28.  error
29.endif
30.if ${.TARGET:M${UNDEF}} != "\${.TARGET:M\${UNDEF}}"
31.  error
32.endif
33
34all:
35	@:
36