From 12e256c877885a56f1d082463fa86c5de3884304 Mon Sep 17 00:00:00 2001 From: rillig Date: Sun, 27 Dec 2020 21:19:13 +0000 Subject: [PATCH] make(1): add more tests for ':=' assignments --- usr.bin/make/unit-tests/var-op-expand.mk | 32 +++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/usr.bin/make/unit-tests/var-op-expand.mk b/usr.bin/make/unit-tests/var-op-expand.mk index 5c5734a53d99..5e928e0451f0 100644 --- a/usr.bin/make/unit-tests/var-op-expand.mk +++ b/usr.bin/make/unit-tests/var-op-expand.mk @@ -1,4 +1,4 @@ -# $NetBSD: var-op-expand.mk,v 1.5 2020/12/27 20:45:52 rillig Exp $ +# $NetBSD: var-op-expand.mk,v 1.6 2020/12/27 21:19:13 rillig Exp $ # # Tests for the := variable assignment operator, which expands its # right-hand side. @@ -86,6 +86,36 @@ UNDEF= Uwas undefined .endif +# In variable assignments using the ':=' operator, undefined variables are +# preserved, no matter how indirectly they are referenced. +.undef REF3 +REF2= <${REF3}> +REF= ${REF2} +VAR:= ${REF} +REF3= too late +.if ${VAR} != "" +. error +.endif + + +# In variable assignments using the ':=' operator, '$$' are preserved, no +# matter how indirectly they are referenced. +REF2= REF2:$$ $$$$ +REF= REF:$$ $$$$ ${REF2} +VAR:= VAR:$$ $$$$ ${REF} +.if ${VAR} != "VAR:\$ \$\$ REF:\$ \$\$ REF2:\$ \$\$" +. error +.endif + + +# In variable assignments using the ':=' operator, '$$' are preserved in the +# expressions of the top level, but not in expressions that are nested. +VAR:= top:$$ ${:Unest1\:\$\$} ${:Unest2${:U\:\$\$}} +.if ${VAR} != "top:\$ nest1:\$ nest2:\$" +. error +.endif + + # XXX: edge case: When a variable name refers to an undefined variable, the # behavior differs between the '=' and the ':=' assignment operators. # This bug exists since var.c 1.42 from 2000-05-11.