diff options
Diffstat (limited to 'unit-tests/varname.mk')
-rw-r--r-- | unit-tests/varname.mk | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/unit-tests/varname.mk b/unit-tests/varname.mk index e9fbc89873ca..f586c7602cb7 100644 --- a/unit-tests/varname.mk +++ b/unit-tests/varname.mk @@ -1,8 +1,44 @@ -# $NetBSD: varname.mk,v 1.4 2020/10/18 08:47:54 rillig Exp $ +# $NetBSD: varname.mk,v 1.8 2020/11/02 22:59:48 rillig Exp $ # # Tests for special variables, such as .MAKE or .PARSEDIR. +# And for variable names in general. -# TODO: Implementation +.MAKEFLAGS: -dv + +# In variable names, braces are allowed, but they must be balanced. +# Parentheses and braces may be mixed. +VAR{{{}}}= 3 braces +.if "${VAR{{{}}}}" != "3 braces" +. error +.endif + +# In variable expressions, the parser works differently. It doesn't treat +# braces and parentheses equally, therefore the first closing brace already +# marks the end of the variable name. +VARNAME= VAR((( +${VARNAME}= 3 open parentheses +.if "${VAR(((}}}}" != "3 open parentheses}}}" +. error +.endif + +# In the above test, the variable name is constructed indirectly. Neither +# of the following expressions produces the intended effect. +# +# This is not a variable assignment since the parentheses and braces are not +# balanced. At the end of the line, there are still 3 levels open, which +# means the variable name is not finished. +${:UVAR(((}= try1 +# On the left-hand side of a variable assignments, the backslash is not parsed +# as an escape character, therefore the parentheses still count to the nesting +# level, which at the end of the line is still 3. Therefore this is not a +# variable assignment as well. +${:UVAR\(\(\(}= try2 +# To assign to a variable with an arbitrary name, the variable name has to +# come from an external source, not the text that is parsed in the assignment +# itself. This is exactly the reason why further above, the indirect +# ${VARNAME} works, while all other attempts fail. +${VARNAME}= try3 + +.MAKEFLAGS: -d0 all: - @:; |