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

cvs diff -r1.64 -r1.65 src/usr.bin/make/unit-tests/Makefile (expand / switch to unified diff)

--- 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,14 +1,14 @@ @@ -1,14 +1,14 @@
1# $NetBSD: Makefile,v 1.64 2020/07/25 21:19:29 rillig Exp $ 1# $NetBSD: Makefile,v 1.65 2020/07/26 11:10:29 rillig Exp $
2# 2#
3# Unit tests for make(1) 3# Unit tests for make(1)
4# 4#
5# The main targets are: 5# The main targets are:
6# 6#
7# all: 7# all:
8# run all the tests 8# run all the tests
9# test: 9# test:
10# run 'all', and compare to expected results 10# run 'all', and compare to expected results
11# accept: 11# accept:
12# move generated output to expected results 12# move generated output to expected results
13# 13#
14# Settable variables 14# Settable variables
@@ -67,26 +67,29 @@ TESTS+= sysv @@ -67,26 +67,29 @@ TESTS+= sysv
67TESTS+= ternary 67TESTS+= ternary
68TESTS+= unexport 68TESTS+= unexport
69TESTS+= unexport-env 69TESTS+= unexport-env
70TESTS+= varcmd 70TESTS+= varcmd
71TESTS+= vardebug 71TESTS+= vardebug
72TESTS+= varfind 72TESTS+= varfind
73TESTS+= varmisc 73TESTS+= varmisc
74TESTS+= varmod-edge 74TESTS+= varmod-edge
75TESTS+= varquote 75TESTS+= varquote
76TESTS+= varshell 76TESTS+= varshell
77 77
78# Override environment variables for some of the tests. 78# Override environment variables for some of the tests.
79ENV.envfirst= FROM_ENV=value-from-env 79ENV.envfirst= FROM_ENV=value-from-env
 80ENV.varmisc= FROM_ENV=env
 81ENV.varmisc+= FROM_ENV_BEFORE=env
 82ENV.varmisc+= FROM_ENV_AFTER=env
80 83
81# Override make flags for some of the tests; default is -k. 84# Override make flags for some of the tests; default is -k.
82FLAGS.doterror= # none 85FLAGS.doterror= # none
83FLAGS.order= -j1 86FLAGS.order= -j1
84FLAGS.envfirst= -e 87FLAGS.envfirst= -e
85FLAGS.vardebug= -k -dv FROM_CMDLINE= 88FLAGS.vardebug= -k -dv FROM_CMDLINE=
86 89
87# Some tests need extra post-processing. 90# Some tests need extra post-processing.
88SED_CMDS.modmisc+= -e 's,\(substitution error:\).*,\1 (details omitted),' 91SED_CMDS.modmisc+= -e 's,\(substitution error:\).*,\1 (details omitted),'
89SED_CMDS.varshell+= -e 's,^[a-z]*sh: ,,' 92SED_CMDS.varshell+= -e 's,^[a-z]*sh: ,,'
90SED_CMDS.varshell+= -e '/command/s,No such.*,not found,' 93SED_CMDS.varshell+= -e '/command/s,No such.*,not found,'
91 94
92# Some tests need an additional round of postprocessing. 95# Some tests need an additional round of postprocessing.

cvs diff -r1.9 -r1.10 src/usr.bin/make/unit-tests/varmisc.exp (expand / switch to unified diff)

--- 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
@@ -30,14 +30,17 @@ save-dollars: False = $ @@ -30,14 +30,17 @@ save-dollars: False = $
30save-dollars: True = $$ 30save-dollars: True = $$
31save-dollars: false = $ 31save-dollars: false = $
32save-dollars: true = $$ 32save-dollars: true = $$
33save-dollars: Yes = $$ 33save-dollars: Yes = $$
34save-dollars: No = $ 34save-dollars: No = $
35save-dollars: yes = $$ 35save-dollars: yes = $$
36save-dollars: no = $ 36save-dollars: no = $
37save-dollars: On = $$ 37save-dollars: On = $$
38save-dollars: Off = $ 38save-dollars: Off = $
39save-dollars: ON = $$ 39save-dollars: ON = $$
40save-dollars: OFF = $ 40save-dollars: OFF = $
41save-dollars: on = $$ 41save-dollars: on = $$
42save-dollars: off = $ 42save-dollars: off = $
 43export-appended: env
 44export-appended: env
 45export-appended: env mk
43exit status 0 46exit status 0

cvs diff -r1.13 -r1.14 src/usr.bin/make/unit-tests/varmisc.mk (expand / switch to unified diff)

--- 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,20 +1,21 @@ @@ -1,20 +1,21 @@
1# $Id: varmisc.mk,v 1.13 2020/07/26 10:59:56 rillig Exp $ 1# $Id: varmisc.mk,v 1.14 2020/07/26 11:10:29 rillig Exp $
2# 2#
3# Miscellaneous variable tests. 3# Miscellaneous variable tests.
4 4
5all: unmatched_var_paren D_true U_true D_false U_false Q_lhs Q_rhs NQ_none \ 5all: unmatched_var_paren D_true U_true D_false U_false Q_lhs Q_rhs NQ_none \
6 strftime cmpv manok 6 strftime cmpv manok
7all: save-dollars 7all: save-dollars
 8all: export-appended
8 9
9unmatched_var_paren: 10unmatched_var_paren:
10 @echo ${foo::=foo-text} 11 @echo ${foo::=foo-text}
11 12
12True = ${echo true >&2:L:sh}TRUE 13True = ${echo true >&2:L:sh}TRUE
13False= ${echo false >&2:L:sh}FALSE 14False= ${echo false >&2:L:sh}FALSE
14 15
15VSET= is set 16VSET= is set
16.undef UNDEF 17.undef UNDEF
17 18
18U_false: 19U_false:
19 @echo :U skipped when var set 20 @echo :U skipped when var set
20 @echo ${VSET:U${False}} 21 @echo ${VSET:U${False}}
@@ -129,13 +130,29 @@ VAR.${PARAM}+= 2 @@ -129,13 +130,29 @@ VAR.${PARAM}+= 2
129# and the assignment operator. 130# and the assignment operator.
130PARAM= + 131PARAM= +
131VAR.${PARAM}= 1 132VAR.${PARAM}= 1
132VAR.${PARAM}+= 2 133VAR.${PARAM}+= 2
133.if ${VAR.+} != "1 2" 134.if ${VAR.+} != "1 2"
134.error "${VAR.+}" 135.error "${VAR.+}"
135.endif 136.endif
136.for param in + ! ? 137.for param in + ! ?
137VAR.${param}= ${param} 138VAR.${param}= ${param}
138.endfor 139.endfor
139.if ${VAR.+} != "+" || ${VAR.!} != "!" || ${VAR.?} != "?" 140.if ${VAR.+} != "+" || ${VAR.!} != "!" || ${VAR.?} != "?"
140.error "${VAR.+}" "${VAR.!}" "${VAR.?}" 141.error "${VAR.+}" "${VAR.!}" "${VAR.?}"
141.endif 142.endif
 143
 144# Appending to a variable from the environment creates a copy of that variable
 145# in the global context.
 146# The appended value is not exported automatically.
 147# When a variable is exported, the exported value is taken at the time of the
 148# .export directive. Later changes to the variable have no effect.
 149.export FROM_ENV_BEFORE
 150FROM_ENV+= mk
 151FROM_ENV_BEFORE+= mk
 152FROM_ENV_AFTER+= mk
 153.export FROM_ENV_AFTER
 154
 155export-appended:
 156 @echo $@: "$$FROM_ENV"
 157 @echo $@: "$$FROM_ENV_BEFORE"
 158 @echo $@: "$$FROM_ENV_AFTER"