Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make/unit-tests make(1): add test for modifier parts...



details:   https://anonhg.NetBSD.org/src/rev/ec1a8a2f2560
branches:  trunk
changeset: 948363:ec1a8a2f2560
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Dec 27 23:25:33 2020 +0000

description:
make(1): add test for modifier parts in ':=' assignments

diffstat:

 usr.bin/make/unit-tests/var-op-expand.mk |  24 +++++++++++++++++++++++-
 1 files changed, 23 insertions(+), 1 deletions(-)

diffs (38 lines):

diff -r 123daf880616 -r ec1a8a2f2560 usr.bin/make/unit-tests/var-op-expand.mk
--- a/usr.bin/make/unit-tests/var-op-expand.mk  Sun Dec 27 22:29:37 2020 +0000
+++ b/usr.bin/make/unit-tests/var-op-expand.mk  Sun Dec 27 23:25:33 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: var-op-expand.mk,v 1.8 2020/12/27 22:29:37 rillig Exp $
+# $NetBSD: var-op-expand.mk,v 1.9 2020/12/27 23:25:33 rillig Exp $
 #
 # Tests for the := variable assignment operator, which expands its
 # right-hand side.
@@ -116,6 +116,28 @@
 .endif
 
 
+# In variable assignments using the ':=' operator, there may be expressions
+# containing variable modifiers, and these modifiers may refer to other
+# variables.
+#
+# Contrary to the assignment operator '=', the assignment operator ':='
+# consumes the '$' from modifier parts.
+REF.word=      1:$$ 2:$$$$ 4:$$$$$$$$
+VAR:=          ${:Uword:@word@${REF.${word}}@}, direct: ${REF.word}
+.if ${VAR} != "1:2:\$ 4:\$\$, direct: 1:\$ 2:\$\$ 4:\$\$\$\$"
+.  error
+.endif
+
+
+# Just for comparison, the previous example using the assignment operator '='
+# instead of ':='.
+REF.word=      1:$$ 2:$$$$ 4:$$$$$$$$
+VAR=           ${:Uword:@word@${REF.${word}}@}, direct: ${REF.word}
+.if ${VAR} != "1:\$ 2:\$\$ 4:\$\$\$\$, direct: 1:\$ 2:\$\$ 4:\$\$\$\$"
+.  error
+.endif
+
+
 # Between var.c 1.42 from 2000-05-11 and before parse.c 1.520 from 2020-12-27,
 # if the variable name in a ':=' assignment referred to an undefined variable,
 # there were actually 2 assignments to different variables:



Home | Main Index | Thread Index | Old Index