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 tests/make: demonstrate that the mod...



details:   https://anonhg.NetBSD.org/src/rev/ae3e2b0f3ed8
branches:  trunk
changeset: 1019616:ae3e2b0f3ed8
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Mar 15 18:46:05 2021 +0000

description:
tests/make: demonstrate that the modifier '::=' expands the varname

diffstat:

 usr.bin/make/unit-tests/varmod-assign.exp |  17 +++++++++++++++++
 usr.bin/make/unit-tests/varmod-assign.mk  |  30 +++++++++++++++++++++++++++++-
 2 files changed, 46 insertions(+), 1 deletions(-)

diffs (65 lines):

diff -r 7f12d7256efb -r ae3e2b0f3ed8 usr.bin/make/unit-tests/varmod-assign.exp
--- a/usr.bin/make/unit-tests/varmod-assign.exp Mon Mar 15 18:44:04 2021 +0000
+++ b/usr.bin/make/unit-tests/varmod-assign.exp Mon Mar 15 18:46:05 2021 +0000
@@ -1,3 +1,20 @@
+Global:param = twice
+Global:VARNAME = VAR.$${param}
+Var_Parse: ${VARNAME} (eval)
+Global:VAR.${param} = initial-value
+Var_Parse: ${${VARNAME}::=assigned-value} (eval-defined)
+Var_Parse: ${VARNAME}::=assigned-value} (eval-defined)
+Applying ${VAR.${param}::...} to "initial-value" (eval-defined, none, regular)
+Modifier part: "assigned-value"
+Var_Parse: ${param} (eval)
+Global:VAR.twice = assigned-value
+Result of ${VAR.${param}::=assigned-value} is "" (eval-defined, none, regular)
+Var_Parse: $ for symmetry with the usual assignment operators. (eval)
+make: "varmod-assign.mk" line 139: FIXME: don't expand the variable name twice here, for symmetry with the usual assignment operators.
+Var_Parse: ${${VARNAME}} != "initial-value" (eval-defined)
+Var_Parse: ${VARNAME}} != "initial-value" (eval-defined)
+Global:.MAKEFLAGS =  -r -k -d v -d
+Global:.MAKEFLAGS =  -r -k -d v -d 0
 mod-assign: first=1.
 mod-assign: last=3.
 mod-assign: appended=1 2 3.
diff -r 7f12d7256efb -r ae3e2b0f3ed8 usr.bin/make/unit-tests/varmod-assign.mk
--- a/usr.bin/make/unit-tests/varmod-assign.mk  Mon Mar 15 18:44:04 2021 +0000
+++ b/usr.bin/make/unit-tests/varmod-assign.mk  Mon Mar 15 18:46:05 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-assign.mk,v 1.10 2021/02/14 12:14:37 rillig Exp $
+# $NetBSD: varmod-assign.mk,v 1.11 2021/03/15 18:46:05 rillig Exp $
 #
 # Tests for the obscure ::= variable modifiers, which perform variable
 # assignments during evaluation, just like the = operator in C.
@@ -114,3 +114,31 @@
 .if ${VAR} != "current}"
 .  error
 .endif
+
+
+# Before var.c 1.888 from 2021-03-15, an expression using the modifier '::='
+# expanded its variable name once too often during evaluation.  This was only
+# relevant for variable names containing a '$' sign in their actual name, not
+# the usual VAR.${param}.
+.MAKEFLAGS: -dv
+param=         twice
+VARNAME=       VAR.$${param}   # Indirect variable name because of the '$',
+                               # to avoid difficult escaping rules.
+
+${VARNAME}=    initial-value   # Sets 'VAR.${param}' to 'expanded'.
+.if defined(VAR.twice)         # At this point, the '$$' is not expanded.
+.  error
+.endif
+.if ${${VARNAME}::=assigned-value} # Here the variable name gets expanded once
+.  error                       # too often.
+.endif
+.if !defined(VAR.twice)
+.  error                       # FIXME: This is the unwanted current behavior.
+.else
+.  info                FIXME: don't expand the variable name twice here, $\
+               for symmetry with the usual assignment operators.
+.endif
+.if ${${VARNAME}} != "initial-value"
+.  error
+.endif
+.MAKEFLAGS: -d0



Home | Main Index | Thread Index | Old Index