xref: /freebsd/contrib/bmake/unit-tests/varparse-dynamic.mk (revision 7ef62cebc2f965b0f640263e179276928885e33d)
1# $NetBSD: varparse-dynamic.mk,v 1.7 2023/06/01 20:56:35 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 had to be undefined.
6.if ${.TARGET}			# exact match, may be undefined
7.endif
8# expect+1: Malformed conditional (${.TARGEX})
9.if ${.TARGEX}			# 1 character difference, must be defined
10.endif
11# expect+1: Malformed conditional (${.TARGXX})
12.if ${.TARGXX}			# 2 characters difference, must be defined
13.endif
14
15# When a dynamic variable (such as .TARGET) is evaluated in the global
16# scope, it is not yet ready to be expanded.  Therefore the complete
17# expression is returned as the variable value, hoping that it can be
18# resolved at a later point.
19#
20# This test covers the code in Var_Parse that deals with DEF_UNDEF but not
21# DEF_DEFINED for dynamic variables.
22.if ${.TARGET:S,^,,} != "\${.TARGET:S,^,,}"
23.  error
24.endif
25
26# If a dynamic variable is expanded in a non-local scope, the expression
27# based on this variable is not expanded.  But there may be nested variable
28# expressions in the modifiers, and these are kept unexpanded as well.
29.if ${.TARGET:M${:Ufallback}} != "\${.TARGET:M\${:Ufallback}}"
30.  error
31.endif
32.if ${.TARGET:M${UNDEF}} != "\${.TARGET:M\${UNDEF}}"
33.  error
34.endif
35