Sun Jul 26 11:10:29 2020 UTC ()
make(1): add test for appending and exporting a variable
(rillig)
diff -r1.64 -r1.65 src/usr.bin/make/unit-tests/Makefile
diff -r1.9 -r1.10 src/usr.bin/make/unit-tests/varmisc.exp
diff -r1.13 -r1.14 src/usr.bin/make/unit-tests/varmisc.mk
--- src/usr.bin/make/unit-tests/Makefile 2020/07/25 21:19:29 1.64
+++ src/usr.bin/make/unit-tests/Makefile 2020/07/26 11:10:29 1.65
@@ -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 @@
# 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
--- src/usr.bin/make/unit-tests/varmisc.exp 2020/07/26 10:48:21 1.9
+++ src/usr.bin/make/unit-tests/varmisc.exp 2020/07/26 11:10:29 1.10
@@ -40,4 +40,7 @@
save-dollars: OFF = $
save-dollars: on = $$
save-dollars: off = $
+export-appended: env
+export-appended: env
+export-appended: env mk
exit status 0
--- src/usr.bin/make/unit-tests/varmisc.mk 2020/07/26 10:59:56 1.13
+++ src/usr.bin/make/unit-tests/varmisc.mk 2020/07/26 11:10:29 1.14
@@ -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 @@
.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"