make(1): prepare test for .export to show all exported variables Currently the unit tests don't cover exporting of local variables like .TARGET or @. To see the effects, all exported variables must be listed by the tests.diff -r1.68 -r1.69 src/usr.bin/make/unit-tests/Makefile
(rillig)
--- src/usr.bin/make/unit-tests/Makefile 2020/07/27 19:23:12 1.68
+++ src/usr.bin/make/unit-tests/Makefile 2020/07/27 19:45:56 1.69
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | # $NetBSD: Makefile,v 1.68 2020/07/27 19:23:12 rillig Exp $ | 1 | # $NetBSD: Makefile,v 1.69 2020/07/27 19:45:56 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 | |
@@ -69,26 +69,27 @@ TESTS+= ternary | @@ -69,26 +69,27 @@ TESTS+= ternary | |||
69 | TESTS+= unexport | 69 | TESTS+= unexport | |
70 | TESTS+= unexport-env | 70 | TESTS+= unexport-env | |
71 | TESTS+= varcmd | 71 | TESTS+= varcmd | |
72 | TESTS+= vardebug | 72 | TESTS+= vardebug | |
73 | TESTS+= varfind | 73 | TESTS+= varfind | |
74 | TESTS+= varmisc | 74 | TESTS+= varmisc | |
75 | TESTS+= varmod-edge | 75 | TESTS+= varmod-edge | |
76 | TESTS+= varparse-dynamic | 76 | TESTS+= varparse-dynamic | |
77 | TESTS+= varquote | 77 | TESTS+= varquote | |
78 | TESTS+= varshell | 78 | TESTS+= varshell | |
79 | 79 | |||
80 | # Override environment variables for some of the tests. | 80 | # Override environment variables for some of the tests. | |
81 | ENV.envfirst= FROM_ENV=value-from-env | 81 | ENV.envfirst= FROM_ENV=value-from-env | |
82 | ENV.export= -i PATH=${PATH:Q} | |||
82 | ENV.varmisc= FROM_ENV=env | 83 | ENV.varmisc= FROM_ENV=env | |
83 | ENV.varmisc+= FROM_ENV_BEFORE=env | 84 | ENV.varmisc+= FROM_ENV_BEFORE=env | |
84 | ENV.varmisc+= FROM_ENV_AFTER=env | 85 | ENV.varmisc+= FROM_ENV_AFTER=env | |
85 | 86 | |||
86 | # Override make flags for some of the tests; default is -k. | 87 | # Override make flags for some of the tests; default is -k. | |
87 | FLAGS.doterror= # none | 88 | FLAGS.doterror= # none | |
88 | FLAGS.envfirst= -e | 89 | FLAGS.envfirst= -e | |
89 | FLAGS.order= -j1 | 90 | FLAGS.order= -j1 | |
90 | FLAGS.vardebug= -k -dv FROM_CMDLINE= | 91 | FLAGS.vardebug= -k -dv FROM_CMDLINE= | |
91 | 92 | |||
92 | # Some tests need extra post-processing. | 93 | # Some tests need extra post-processing. | |
93 | SED_CMDS.modmisc+= -e 's,\(substitution error:\).*,\1 (details omitted),' | 94 | SED_CMDS.modmisc+= -e 's,\(substitution error:\).*,\1 (details omitted),' | |
94 | SED_CMDS.varshell+= -e 's,^[a-z]*sh: ,,' | 95 | SED_CMDS.varshell+= -e 's,^[a-z]*sh: ,,' | |
@@ -123,27 +124,27 @@ TEST_MAKE?= ${.MAKE} | @@ -123,27 +124,27 @@ TEST_MAKE?= ${.MAKE} | |||
123 | TOOL_SED?= sed | 124 | TOOL_SED?= sed | |
124 | 125 | |||
125 | # ensure consistent results from sort(1) | 126 | # ensure consistent results from sort(1) | |
126 | LC_ALL= C | 127 | LC_ALL= C | |
127 | LANG= C | 128 | LANG= C | |
128 | .export LANG LC_ALL | 129 | .export LANG LC_ALL | |
129 | 130 | |||
130 | # the tests are actually done with sub-makes. | 131 | # the tests are actually done with sub-makes. | |
131 | .SUFFIXES: .mk .rawout .out | 132 | .SUFFIXES: .mk .rawout .out | |
132 | .mk.rawout: | 133 | .mk.rawout: | |
133 | @echo testing ${.IMPSRC} | 134 | @echo testing ${.IMPSRC} | |
134 | @set -eu; \ | 135 | @set -eu; \ | |
135 | cd ${.OBJDIR}; \ | 136 | cd ${.OBJDIR}; \ | |
136 | ${ENV.${.TARGET:R}} ${TEST_MAKE} \ | 137 | env ${ENV.${.TARGET:R}} ${TEST_MAKE} \ | |
137 | ${FLAGS.${.TARGET:R}:U-k} -f ${.IMPSRC} \ | 138 | ${FLAGS.${.TARGET:R}:U-k} -f ${.IMPSRC} \ | |
138 | > ${.TARGET}.tmp 2>&1 \ | 139 | > ${.TARGET}.tmp 2>&1 \ | |
139 | && status=$$? || status=$$?; \ | 140 | && status=$$? || status=$$?; \ | |
140 | echo $$status > ${.TARGET:R}.status | 141 | echo $$status > ${.TARGET:R}.status | |
141 | @mv ${.TARGET}.tmp ${.TARGET} | 142 | @mv ${.TARGET}.tmp ${.TARGET} | |
142 | 143 | |||
143 | # Post-process the test output so that the results can be compared. | 144 | # Post-process the test output so that the results can be compared. | |
144 | # | 145 | # | |
145 | # always pretend .MAKE was called 'make' | 146 | # always pretend .MAKE was called 'make' | |
146 | _SED_CMDS+= -e 's,^${TEST_MAKE:T:S,.,\\.,g}[][0-9]*:,make:,' | 147 | _SED_CMDS+= -e 's,^${TEST_MAKE:T:S,.,\\.,g}[][0-9]*:,make:,' | |
147 | _SED_CMDS+= -e 's,${TEST_MAKE:S,.,\\.,g},make,' | 148 | _SED_CMDS+= -e 's,${TEST_MAKE:S,.,\\.,g},make,' | |
148 | # replace anything after 'stopped in' with unit-tests | 149 | # replace anything after 'stopped in' with unit-tests | |
149 | _SED_CMDS+= -e '/stopped/s, /.*, unit-tests,' | 150 | _SED_CMDS+= -e '/stopped/s, /.*, unit-tests,' |
--- src/usr.bin/make/unit-tests/export-all.mk 2015/04/10 20:41:59 1.2
+++ src/usr.bin/make/unit-tests/export-all.mk 2020/07/27 19:45:56 1.3
@@ -1,23 +1,24 @@ | @@ -1,23 +1,24 @@ | |||
1 | # $Id: export-all.mk,v 1.2 2015/04/10 20:41:59 sjg Exp $ | 1 | # $Id: export-all.mk,v 1.3 2020/07/27 19:45:56 rillig Exp $ | |
2 | 2 | |||
3 | UT_OK=good | 3 | UT_OK=good | |
4 | UT_F=fine | 4 | UT_F=fine | |
5 | 5 | |||
6 | # the old way to do :tA | 6 | # the old way to do :tA | |
7 | M_tAbad = C,.*,cd & \&\& 'pwd',:sh | 7 | M_tAbad = C,.*,cd & \&\& 'pwd',:sh | |
8 | # the new | 8 | # the new | |
9 | M_tA = tA | 9 | M_tA = tA | |
10 | 10 | |||
11 | here := ${.PARSEDIR} | 11 | here := ${.PARSEDIR} | |
12 | 12 | |||
13 | # this will cause trouble (recursing if we let it) | 13 | # this will cause trouble (recursing if we let it) | |
14 | UT_BADDIR = ${${here}/../${here:T}:L:${M_tAbad}:T} | 14 | UT_BADDIR = ${${here}/../${here:T}:L:${M_tAbad}:T} | |
15 | # this will be ok | 15 | # this will be ok | |
16 | UT_OKDIR = ${${here}/../${here:T}:L:${M_tA}:T} | 16 | UT_OKDIR = ${${here}/../${here:T}:L:${M_tA}:T} | |
17 | 17 | |||
18 | .export | 18 | .export | |
19 | 19 | |||
20 | FILTER_CMD= grep ^UT_ | |||
20 | .include "export.mk" | 21 | .include "export.mk" | |
21 | 22 | |||
22 | UT_TEST=export-all | 23 | UT_TEST=export-all | |
23 | UT_ALL=even this gets exported | 24 | UT_ALL=even this gets exported |
--- src/usr.bin/make/unit-tests/export.exp 2014/08/21 13:44:51 1.1
+++ src/usr.bin/make/unit-tests/export.exp 2020/07/27 19:45:56 1.2
@@ -1,6 +1,8 @@ | @@ -1,6 +1,8 @@ | |||
1 | .MAKE.LEVEL.ENV=MAKELEVEL | |||
2 | MAKELEVEL=1 | |||
1 | UT_DOLLAR=This is $UT_FU | 3 | UT_DOLLAR=This is $UT_FU | |
2 | UT_FOO=foobar is fubar | 4 | UT_FOO=foobar is fubar | |
3 | UT_FU=fubar | 5 | UT_FU=fubar | |
4 | UT_TEST=export | 6 | UT_TEST=export | |
5 | UT_ZOO=hoopie | 7 | UT_ZOO=hoopie | |
6 | exit status 0 | 8 | exit status 0 |
--- src/usr.bin/make/unit-tests/export.mk 2014/08/21 13:44:51 1.1
+++ src/usr.bin/make/unit-tests/export.mk 2020/07/27 19:45:56 1.2
@@ -1,22 +1,23 @@ | @@ -1,22 +1,23 @@ | |||
1 | # $Id: export.mk,v 1.1 2014/08/21 13:44:51 apb Exp $ | 1 | # $Id: export.mk,v 1.2 2020/07/27 19:45:56 rillig Exp $ | |
2 | 2 | |||
3 | UT_TEST=export | 3 | UT_TEST=export | |
4 | UT_FOO=foo${BAR} | 4 | UT_FOO=foo${BAR} | |
5 | UT_FU=fubar | 5 | UT_FU=fubar | |
6 | UT_ZOO=hoopie | 6 | UT_ZOO=hoopie | |
7 | UT_NO=all | 7 | UT_NO=all | |
8 | # belive it or not, we expect this one to come out with $UT_FU unexpanded. | 8 | # belive it or not, we expect this one to come out with $UT_FU unexpanded. | |
9 | UT_DOLLAR= This is $$UT_FU | 9 | UT_DOLLAR= This is $$UT_FU | |
10 | 10 | |||
11 | .export UT_FU UT_FOO | 11 | .export UT_FU UT_FOO | |
12 | .export UT_DOLLAR | 12 | .export UT_DOLLAR | |
13 | # this one will be ignored | 13 | # this one will be ignored | |
14 | .export .MAKE.PID | 14 | .export .MAKE.PID | |
15 | 15 | |||
16 | BAR=bar is ${UT_FU} | 16 | BAR=bar is ${UT_FU} | |
17 | 17 | |||
18 | .MAKE.EXPORTED+= UT_ZOO UT_TEST | 18 | .MAKE.EXPORTED+= UT_ZOO UT_TEST | |
19 | 19 | |||
20 | all: | 20 | FILTER_CMD?= grep -v -E '^(MAKEFLAGS|PATH|PWD)=' | |
21 | @env | grep '^UT_' | sort | |||
22 | 21 | |||
22 | all: | |||
23 | @env | ${FILTER_CMD} | sort |
--- src/usr.bin/make/unit-tests/unexport-env.mk 2014/08/21 13:44:52 1.1
+++ src/usr.bin/make/unit-tests/unexport-env.mk 2020/07/27 19:45:56 1.2
@@ -1,14 +1,15 @@ | @@ -1,14 +1,15 @@ | |||
1 | # $Id: unexport-env.mk,v 1.1 2014/08/21 13:44:52 apb Exp $ | 1 | # $Id: unexport-env.mk,v 1.2 2020/07/27 19:45:56 rillig Exp $ | |
2 | 2 | |||
3 | # pick up a bunch of exported vars | 3 | # pick up a bunch of exported vars | |
4 | FILTER_CMD= grep ^UT_ | |||
4 | .include "export.mk" | 5 | .include "export.mk" | |
5 | 6 | |||
6 | # an example of setting up a minimal environment. | 7 | # an example of setting up a minimal environment. | |
7 | PATH = /bin:/usr/bin:/sbin:/usr/sbin | 8 | PATH = /bin:/usr/bin:/sbin:/usr/sbin | |
8 | 9 | |||
9 | # now clobber the environment to just PATH and UT_TEST | 10 | # now clobber the environment to just PATH and UT_TEST | |
10 | UT_TEST = unexport-env | 11 | UT_TEST = unexport-env | |
11 | 12 | |||
12 | # this removes everything | 13 | # this removes everything | |
13 | .unexport-env | 14 | .unexport-env | |
14 | .export PATH UT_TEST | 15 | .export PATH UT_TEST |
--- src/usr.bin/make/unit-tests/unexport.mk 2014/08/21 13:44:52 1.1
+++ src/usr.bin/make/unit-tests/unexport.mk 2020/07/27 19:45:56 1.2
@@ -1,8 +1,9 @@ | @@ -1,8 +1,9 @@ | |||
1 | # $Id: unexport.mk,v 1.1 2014/08/21 13:44:52 apb Exp $ | 1 | # $Id: unexport.mk,v 1.2 2020/07/27 19:45:56 rillig Exp $ | |
2 | 2 | |||
3 | # pick up a bunch of exported vars | 3 | # pick up a bunch of exported vars | |
4 | FILTER_CMD= grep ^UT_ | |||
4 | .include "export.mk" | 5 | .include "export.mk" | |
5 | 6 | |||
6 | .unexport UT_ZOO UT_FOO | 7 | .unexport UT_ZOO UT_FOO | |
7 | 8 | |||
8 | UT_TEST = unexport | 9 | UT_TEST = unexport |