Mon Jul 27 19:45:56 2020 UTC ()
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.


(rillig)
diff -r1.68 -r1.69 src/usr.bin/make/unit-tests/Makefile
diff -r1.2 -r1.3 src/usr.bin/make/unit-tests/export-all.mk
diff -r1.1 -r1.2 src/usr.bin/make/unit-tests/export.exp
diff -r1.1 -r1.2 src/usr.bin/make/unit-tests/export.mk
diff -r1.1 -r1.2 src/usr.bin/make/unit-tests/unexport-env.mk
diff -r1.1 -r1.2 src/usr.bin/make/unit-tests/unexport.mk

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

--- 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
69TESTS+= unexport 69TESTS+= unexport
70TESTS+= unexport-env 70TESTS+= unexport-env
71TESTS+= varcmd 71TESTS+= varcmd
72TESTS+= vardebug 72TESTS+= vardebug
73TESTS+= varfind 73TESTS+= varfind
74TESTS+= varmisc 74TESTS+= varmisc
75TESTS+= varmod-edge 75TESTS+= varmod-edge
76TESTS+= varparse-dynamic 76TESTS+= varparse-dynamic
77TESTS+= varquote 77TESTS+= varquote
78TESTS+= varshell 78TESTS+= varshell
79 79
80# Override environment variables for some of the tests. 80# Override environment variables for some of the tests.
81ENV.envfirst= FROM_ENV=value-from-env 81ENV.envfirst= FROM_ENV=value-from-env
 82ENV.export= -i PATH=${PATH:Q}
82ENV.varmisc= FROM_ENV=env 83ENV.varmisc= FROM_ENV=env
83ENV.varmisc+= FROM_ENV_BEFORE=env 84ENV.varmisc+= FROM_ENV_BEFORE=env
84ENV.varmisc+= FROM_ENV_AFTER=env 85ENV.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.
87FLAGS.doterror= # none 88FLAGS.doterror= # none
88FLAGS.envfirst= -e 89FLAGS.envfirst= -e
89FLAGS.order= -j1 90FLAGS.order= -j1
90FLAGS.vardebug= -k -dv FROM_CMDLINE= 91FLAGS.vardebug= -k -dv FROM_CMDLINE=
91 92
92# Some tests need extra post-processing. 93# Some tests need extra post-processing.
93SED_CMDS.modmisc+= -e 's,\(substitution error:\).*,\1 (details omitted),' 94SED_CMDS.modmisc+= -e 's,\(substitution error:\).*,\1 (details omitted),'
94SED_CMDS.varshell+= -e 's,^[a-z]*sh: ,,' 95SED_CMDS.varshell+= -e 's,^[a-z]*sh: ,,'
@@ -123,27 +124,27 @@ TEST_MAKE?= ${.MAKE} @@ -123,27 +124,27 @@ TEST_MAKE?= ${.MAKE}
123TOOL_SED?= sed 124TOOL_SED?= sed
124 125
125# ensure consistent results from sort(1) 126# ensure consistent results from sort(1)
126LC_ALL= C 127LC_ALL= C
127LANG= C 128LANG= 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,'

cvs diff -r1.2 -r1.3 src/usr.bin/make/unit-tests/export-all.mk (expand / switch to unified diff)

--- 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
3UT_OK=good 3UT_OK=good
4UT_F=fine 4UT_F=fine
5 5
6# the old way to do :tA 6# the old way to do :tA
7M_tAbad = C,.*,cd & \&\& 'pwd',:sh 7M_tAbad = C,.*,cd & \&\& 'pwd',:sh
8# the new 8# the new
9M_tA = tA 9M_tA = tA
10 10
11here := ${.PARSEDIR} 11here := ${.PARSEDIR}
12 12
13# this will cause trouble (recursing if we let it) 13# this will cause trouble (recursing if we let it)
14UT_BADDIR = ${${here}/../${here:T}:L:${M_tAbad}:T} 14UT_BADDIR = ${${here}/../${here:T}:L:${M_tAbad}:T}
15# this will be ok 15# this will be ok
16UT_OKDIR = ${${here}/../${here:T}:L:${M_tA}:T} 16UT_OKDIR = ${${here}/../${here:T}:L:${M_tA}:T}
17 17
18.export 18.export
19 19
 20FILTER_CMD= grep ^UT_
20.include "export.mk" 21.include "export.mk"
21 22
22UT_TEST=export-all 23UT_TEST=export-all
23UT_ALL=even this gets exported 24UT_ALL=even this gets exported

cvs diff -r1.1 -r1.2 src/usr.bin/make/unit-tests/export.exp (expand / switch to unified diff)

--- 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
 2MAKELEVEL=1
1UT_DOLLAR=This is $UT_FU 3UT_DOLLAR=This is $UT_FU
2UT_FOO=foobar is fubar 4UT_FOO=foobar is fubar
3UT_FU=fubar 5UT_FU=fubar
4UT_TEST=export 6UT_TEST=export
5UT_ZOO=hoopie 7UT_ZOO=hoopie
6exit status 0 8exit status 0

cvs diff -r1.1 -r1.2 src/usr.bin/make/unit-tests/export.mk (expand / switch to unified diff)

--- 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
3UT_TEST=export 3UT_TEST=export
4UT_FOO=foo${BAR} 4UT_FOO=foo${BAR}
5UT_FU=fubar 5UT_FU=fubar
6UT_ZOO=hoopie 6UT_ZOO=hoopie
7UT_NO=all 7UT_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.
9UT_DOLLAR= This is $$UT_FU 9UT_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
16BAR=bar is ${UT_FU} 16BAR=bar is ${UT_FU}
17 17
18.MAKE.EXPORTED+= UT_ZOO UT_TEST 18.MAKE.EXPORTED+= UT_ZOO UT_TEST
19 19
20all: 20FILTER_CMD?= grep -v -E '^(MAKEFLAGS|PATH|PWD)='
21 @env | grep '^UT_' | sort 
22 21
 22all:
 23 @env | ${FILTER_CMD} | sort

cvs diff -r1.1 -r1.2 src/usr.bin/make/unit-tests/unexport-env.mk (expand / switch to unified diff)

--- 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
 4FILTER_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.
7PATH = /bin:/usr/bin:/sbin:/usr/sbin 8PATH = /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
10UT_TEST = unexport-env 11UT_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

cvs diff -r1.1 -r1.2 src/usr.bin/make/unit-tests/unexport.mk (expand / switch to unified diff)

--- 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
 4FILTER_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
8UT_TEST = unexport 9UT_TEST = unexport