Module Name: src
Committed By: rillig
Date: Sun Jul 26 11:10:29 UTC 2020
Modified Files:
src/usr.bin/make/unit-tests: Makefile varmisc.exp varmisc.mk
Log Message:
make(1): add test for appending and exporting a variable
To generate a diff of this commit:
cvs rdiff -u -r1.64 -r1.65 src/usr.bin/make/unit-tests/Makefile
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/make/unit-tests/varmisc.exp
cvs rdiff -u -r1.13 -r1.14 src/usr.bin/make/unit-tests/varmisc.mk
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/make/unit-tests/Makefile
diff -u src/usr.bin/make/unit-tests/Makefile:1.64 src/usr.bin/make/unit-tests/Makefile:1.65
--- src/usr.bin/make/unit-tests/Makefile:1.64 Sat Jul 25 21:19:29 2020
+++ src/usr.bin/make/unit-tests/Makefile Sun Jul 26 11:10:29 2020
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.64 2020/07/25 21:19:29 rillig Exp $
+# $NetBSD: Makefile,v 1.65 2020/07/26 11:10:29 rillig Exp $
#
# Unit tests for make(1)
#
@@ -77,6 +77,9 @@ TESTS+= varshell
# Override environment variables for some of the tests.
ENV.envfirst= FROM_ENV=value-from-env
+ENV.varmisc= FROM_ENV=env
+ENV.varmisc+= FROM_ENV_BEFORE=env
+ENV.varmisc+= FROM_ENV_AFTER=env
# Override make flags for some of the tests; default is -k.
FLAGS.doterror= # none
Index: src/usr.bin/make/unit-tests/varmisc.exp
diff -u src/usr.bin/make/unit-tests/varmisc.exp:1.9 src/usr.bin/make/unit-tests/varmisc.exp:1.10
--- src/usr.bin/make/unit-tests/varmisc.exp:1.9 Sun Jul 26 10:48:21 2020
+++ src/usr.bin/make/unit-tests/varmisc.exp Sun Jul 26 11:10:29 2020
@@ -40,4 +40,7 @@ save-dollars: ON = $$
save-dollars: OFF = $
save-dollars: on = $$
save-dollars: off = $
+export-appended: env
+export-appended: env
+export-appended: env mk
exit status 0
Index: src/usr.bin/make/unit-tests/varmisc.mk
diff -u src/usr.bin/make/unit-tests/varmisc.mk:1.13 src/usr.bin/make/unit-tests/varmisc.mk:1.14
--- src/usr.bin/make/unit-tests/varmisc.mk:1.13 Sun Jul 26 10:59:56 2020
+++ src/usr.bin/make/unit-tests/varmisc.mk Sun Jul 26 11:10:29 2020
@@ -1,10 +1,11 @@
-# $Id: varmisc.mk,v 1.13 2020/07/26 10:59:56 rillig Exp $
+# $Id: varmisc.mk,v 1.14 2020/07/26 11:10:29 rillig Exp $
#
# Miscellaneous variable tests.
all: unmatched_var_paren D_true U_true D_false U_false Q_lhs Q_rhs NQ_none \
strftime cmpv manok
all: save-dollars
+all: export-appended
unmatched_var_paren:
@echo ${foo::=foo-text}
@@ -139,3 +140,19 @@ VAR.${param}= ${param}
.if ${VAR.+} != "+" || ${VAR.!} != "!" || ${VAR.?} != "?"
.error "${VAR.+}" "${VAR.!}" "${VAR.?}"
.endif
+
+# Appending to a variable from the environment creates a copy of that variable
+# in the global context.
+# The appended value is not exported automatically.
+# When a variable is exported, the exported value is taken at the time of the
+# .export directive. Later changes to the variable have no effect.
+.export FROM_ENV_BEFORE
+FROM_ENV+= mk
+FROM_ENV_BEFORE+= mk
+FROM_ENV_AFTER+= mk
+.export FROM_ENV_AFTER
+
+export-appended:
+ @echo $@: "$$FROM_ENV"
+ @echo $@: "$$FROM_ENV_BEFORE"
+ @echo $@: "$$FROM_ENV_AFTER"