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 edge case in r...



details:   https://anonhg.NetBSD.org/src/rev/0a9224a98840
branches:  trunk
changeset: 942466:0a9224a98840
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Nov 08 13:46:15 2020 +0000

description:
make(1): add test for edge case in resolving undefined variables

diffstat:

 usr.bin/make/unit-tests/var-op-expand.exp |   9 +++++++++
 usr.bin/make/unit-tests/var-op-expand.mk  |  20 +++++++++++++++++++-
 2 files changed, 28 insertions(+), 1 deletions(-)

diffs (46 lines):

diff -r 45770e7d603f -r 0a9224a98840 usr.bin/make/unit-tests/var-op-expand.exp
--- a/usr.bin/make/unit-tests/var-op-expand.exp Sun Nov 08 13:10:30 2020 +0000
+++ b/usr.bin/make/unit-tests/var-op-expand.exp Sun Nov 08 13:46:15 2020 +0000
@@ -1,1 +1,10 @@
+Var_Parse: ${UNDEF} with VARE_WANTRES
+Global:VAR_ASSIGN_ = undef value
+Var_Parse: ${UNDEF} with VARE_WANTRES
+Var_Parse: ${UNDEF} with VARE_WANTRES
+Global:VAR_SUBST_${UNDEF} = 
+Var_Parse: ${UNDEF} with VARE_WANTRES
+Global:VAR_SUBST_ = undef value
+Global:.MAKEFLAGS =  -r -k -d v -d
+Global:.MAKEFLAGS =  -r -k -d v -d 0
 exit status 0
diff -r 45770e7d603f -r 0a9224a98840 usr.bin/make/unit-tests/var-op-expand.mk
--- a/usr.bin/make/unit-tests/var-op-expand.mk  Sun Nov 08 13:10:30 2020 +0000
+++ b/usr.bin/make/unit-tests/var-op-expand.mk  Sun Nov 08 13:46:15 2020 +0000
@@ -1,9 +1,27 @@
-# $NetBSD: var-op-expand.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: var-op-expand.mk,v 1.3 2020/11/08 13:46:15 rillig Exp $
 #
 # Tests for the := variable assignment operator, which expands its
 # right-hand side.
 
 # TODO: Implementation
 
+# 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 at least 1993-03-21.
+#
+# The '=' operator expands the undefined variable to an empty string, thus
+# assigning to VAR_ASSIGN_.  In the name of variables to be set, it should
+# really be forbidden to refer to undefined variables.
+#
+# The ':=' operator expands the variable name twice.  In one of these
+# expansions, the undefined variable expression is preserved (controlled by
+# preserveUndefined in VarAssign_EvalSubst), in the other expansion it expands
+# to an empty string.  This way, 2 variables are created using a single
+# variable assignment.  It's magic. :-/
+.MAKEFLAGS: -dv
+VAR_ASSIGN_${UNDEF}=   undef value
+VAR_SUBST_${UNDEF}:=   undef value
+.MAKEFLAGS: -d0
+
 all:
        @:;



Home | Main Index | Thread Index | Old Index