make(1): add test for appending and exporting a variablediff -r1.64 -r1.65 src/usr.bin/make/unit-tests/Makefile
(rillig)
--- 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 | |||
67 | TESTS+= ternary | 67 | TESTS+= ternary | |
68 | TESTS+= unexport | 68 | TESTS+= unexport | |
69 | TESTS+= unexport-env | 69 | TESTS+= unexport-env | |
70 | TESTS+= varcmd | 70 | TESTS+= varcmd | |
71 | TESTS+= vardebug | 71 | TESTS+= vardebug | |
72 | TESTS+= varfind | 72 | TESTS+= varfind | |
73 | TESTS+= varmisc | 73 | TESTS+= varmisc | |
74 | TESTS+= varmod-edge | 74 | TESTS+= varmod-edge | |
75 | TESTS+= varquote | 75 | TESTS+= varquote | |
76 | TESTS+= varshell | 76 | TESTS+= varshell | |
77 | 77 | |||
78 | # Override environment variables for some of the tests. | 78 | # Override environment variables for some of the tests. | |
79 | ENV.envfirst= FROM_ENV=value-from-env | 79 | ENV.envfirst= FROM_ENV=value-from-env | |
80 | ENV.varmisc= FROM_ENV=env | |||
81 | ENV.varmisc+= FROM_ENV_BEFORE=env | |||
82 | ENV.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. | |
82 | FLAGS.doterror= # none | 85 | FLAGS.doterror= # none | |
83 | FLAGS.order= -j1 | 86 | FLAGS.order= -j1 | |
84 | FLAGS.envfirst= -e | 87 | FLAGS.envfirst= -e | |
85 | FLAGS.vardebug= -k -dv FROM_CMDLINE= | 88 | FLAGS.vardebug= -k -dv FROM_CMDLINE= | |
86 | 89 | |||
87 | # Some tests need extra post-processing. | 90 | # Some tests need extra post-processing. | |
88 | SED_CMDS.modmisc+= -e 's,\(substitution error:\).*,\1 (details omitted),' | 91 | SED_CMDS.modmisc+= -e 's,\(substitution error:\).*,\1 (details omitted),' | |
89 | SED_CMDS.varshell+= -e 's,^[a-z]*sh: ,,' | 92 | SED_CMDS.varshell+= -e 's,^[a-z]*sh: ,,' | |
90 | SED_CMDS.varshell+= -e '/command/s,No such.*,not found,' | 93 | SED_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. |
--- 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 = $ | |||
30 | save-dollars: True = $$ | 30 | save-dollars: True = $$ | |
31 | save-dollars: false = $ | 31 | save-dollars: false = $ | |
32 | save-dollars: true = $$ | 32 | save-dollars: true = $$ | |
33 | save-dollars: Yes = $$ | 33 | save-dollars: Yes = $$ | |
34 | save-dollars: No = $ | 34 | save-dollars: No = $ | |
35 | save-dollars: yes = $$ | 35 | save-dollars: yes = $$ | |
36 | save-dollars: no = $ | 36 | save-dollars: no = $ | |
37 | save-dollars: On = $$ | 37 | save-dollars: On = $$ | |
38 | save-dollars: Off = $ | 38 | save-dollars: Off = $ | |
39 | save-dollars: ON = $$ | 39 | save-dollars: ON = $$ | |
40 | save-dollars: OFF = $ | 40 | save-dollars: OFF = $ | |
41 | save-dollars: on = $$ | 41 | save-dollars: on = $$ | |
42 | save-dollars: off = $ | 42 | save-dollars: off = $ | |
43 | export-appended: env | |||
44 | export-appended: env | |||
45 | export-appended: env mk | |||
43 | exit status 0 | 46 | 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,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 | |||
5 | all: unmatched_var_paren D_true U_true D_false U_false Q_lhs Q_rhs NQ_none \ | 5 | all: 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 | |
7 | all: save-dollars | 7 | all: save-dollars | |
8 | all: export-appended | |||
8 | 9 | |||
9 | unmatched_var_paren: | 10 | unmatched_var_paren: | |
10 | @echo ${foo::=foo-text} | 11 | @echo ${foo::=foo-text} | |
11 | 12 | |||
12 | True = ${echo true >&2:L:sh}TRUE | 13 | True = ${echo true >&2:L:sh}TRUE | |
13 | False= ${echo false >&2:L:sh}FALSE | 14 | False= ${echo false >&2:L:sh}FALSE | |
14 | 15 | |||
15 | VSET= is set | 16 | VSET= is set | |
16 | .undef UNDEF | 17 | .undef UNDEF | |
17 | 18 | |||
18 | U_false: | 19 | U_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. | |
130 | PARAM= + | 131 | PARAM= + | |
131 | VAR.${PARAM}= 1 | 132 | VAR.${PARAM}= 1 | |
132 | VAR.${PARAM}+= 2 | 133 | VAR.${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 + ! ? | |
137 | VAR.${param}= ${param} | 138 | VAR.${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 | |||
150 | FROM_ENV+= mk | |||
151 | FROM_ENV_BEFORE+= mk | |||
152 | FROM_ENV_AFTER+= mk | |||
153 | .export FROM_ENV_AFTER | |||
154 | ||||
155 | export-appended: | |||
156 | @echo $@: "$$FROM_ENV" | |||
157 | @echo $@: "$$FROM_ENV_BEFORE" | |||
158 | @echo $@: "$$FROM_ENV_AFTER" |