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 (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,187 +1,188 @@ @@ -1,187 +1,188 @@
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
15# 15#
16# TEST_MAKE 16# TEST_MAKE
17# The make program to be tested. 17# The make program to be tested.
18# 18#
19# 19#
20# Adding a test case 20# Adding a test case
21# 21#
22# Each feature should get its own set of tests in its own suitably 22# Each feature should get its own set of tests in its own suitably
23# named makefile (*.mk), with its own set of expected results (*.exp), 23# named makefile (*.mk), with its own set of expected results (*.exp),
24# and it should be added to the TESTS list. 24# and it should be added to the TESTS list.
25# 25#
26# Any added files must also be added to src/distrib/sets/lists/tests/mi. 26# Any added files must also be added to src/distrib/sets/lists/tests/mi.
27# Makefiles that are not added to TESTS must be ignored in 27# Makefiles that are not added to TESTS must be ignored in
28# src/tests/usr.bin/make/t_make.sh (example: include-sub). 28# src/tests/usr.bin/make/t_make.sh (example: include-sub).
29# 29#
30 30
31# Each test is in a sub-makefile. 31# Each test is in a sub-makefile.
32# Keep the list sorted. 32# Keep the list sorted.
33TESTS+= archive 33TESTS+= archive
34TESTS+= comment 34TESTS+= comment
35TESTS+= cond-late 35TESTS+= cond-late
36TESTS+= cond-short 36TESTS+= cond-short
37TESTS+= cond1 37TESTS+= cond1
38TESTS+= cond2 38TESTS+= cond2
39TESTS+= dollar 39TESTS+= dollar
40TESTS+= doterror 40TESTS+= doterror
41TESTS+= dotwait 41TESTS+= dotwait
42TESTS+= envfirst 42TESTS+= envfirst
43TESTS+= error 43TESTS+= error
44TESTS+= # escape # broken by reverting POSIX changes 44TESTS+= # escape # broken by reverting POSIX changes
45TESTS+= export 45TESTS+= export
46TESTS+= export-all 46TESTS+= export-all
47TESTS+= export-env 47TESTS+= export-env
48TESTS+= forloop 48TESTS+= forloop
49TESTS+= forsubst 49TESTS+= forsubst
50TESTS+= hash 50TESTS+= hash
51TESTS+= # impsrc # broken by reverting POSIX changes 51TESTS+= # impsrc # broken by reverting POSIX changes
52TESTS+= include-main 52TESTS+= include-main
53TESTS+= misc 53TESTS+= misc
54TESTS+= moderrs 54TESTS+= moderrs
55TESTS+= modmatch 55TESTS+= modmatch
56TESTS+= modmisc 56TESTS+= modmisc
57TESTS+= modorder 57TESTS+= modorder
58TESTS+= modts 58TESTS+= modts
59TESTS+= modword 59TESTS+= modword
60TESTS+= order 60TESTS+= order
61TESTS+= # phony-end # broken by reverting POSIX changes 61TESTS+= # phony-end # broken by reverting POSIX changes
62TESTS+= posix 62TESTS+= posix
63TESTS+= # posix1 # broken by reverting POSIX changes 63TESTS+= # posix1 # broken by reverting POSIX changes
64TESTS+= qequals 64TESTS+= qequals
65TESTS+= # suffixes # broken by reverting POSIX changes 65TESTS+= # suffixes # broken by reverting POSIX changes
66TESTS+= sunshcmd 66TESTS+= sunshcmd
67TESTS+= sysv 67TESTS+= sysv
68TESTS+= ternary 68TESTS+= 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: ,,'
95SED_CMDS.varshell+= -e '/command/s,No such.*,not found,' 96SED_CMDS.varshell+= -e '/command/s,No such.*,not found,'
96 97
97# Some tests need an additional round of postprocessing. 98# Some tests need an additional round of postprocessing.
98POSTPROC.vardebug= ${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p' 99POSTPROC.vardebug= ${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p'
99 100
100# End of the configuration section. 101# End of the configuration section.
101 102
102.MAIN: all 103.MAIN: all
103 104
104UNIT_TESTS:= ${.PARSEDIR} 105UNIT_TESTS:= ${.PARSEDIR}
105.PATH: ${UNIT_TESTS} 106.PATH: ${UNIT_TESTS}
106 107
107OUTFILES= ${TESTS:=.out} 108OUTFILES= ${TESTS:=.out}
108 109
109all: ${OUTFILES} 110all: ${OUTFILES}
110 111
111CLEANFILES+= *.rawout *.out *.status *.tmp *.core *.tmp 112CLEANFILES+= *.rawout *.out *.status *.tmp *.core *.tmp
112CLEANFILES+= obj*.[och] lib*.a # posix1.mk 113CLEANFILES+= obj*.[och] lib*.a # posix1.mk
113CLEANFILES+= issue* .[ab]* # suffixes.mk 114CLEANFILES+= issue* .[ab]* # suffixes.mk
114CLEANRECURSIVE+= dir dummy # posix1.mk 115CLEANRECURSIVE+= dir dummy # posix1.mk
115 116
116clean: 117clean:
117 rm -f ${CLEANFILES} 118 rm -f ${CLEANFILES}
118.if !empty(CLEANRECURSIVE) 119.if !empty(CLEANRECURSIVE)
119 rm -rf ${CLEANRECURSIVE} 120 rm -rf ${CLEANRECURSIVE}
120.endif 121.endif
121 122
122TEST_MAKE?= ${.MAKE} 123TEST_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,'
150# strip ${.CURDIR}/ from the output 151# strip ${.CURDIR}/ from the output
151_SED_CMDS+= -e 's,${.CURDIR:S,.,\\.,g}/,,g' 152_SED_CMDS+= -e 's,${.CURDIR:S,.,\\.,g}/,,g'
152_SED_CMDS+= -e 's,${UNIT_TESTS:S,.,\\.,g}/,,g' 153_SED_CMDS+= -e 's,${UNIT_TESTS:S,.,\\.,g}/,,g'
153 154
154.rawout.out: 155.rawout.out:
155 @echo postprocess ${.TARGET} 156 @echo postprocess ${.TARGET}
156 @${TOOL_SED} ${_SED_CMDS} ${SED_CMDS.${.TARGET:R}} \ 157 @${TOOL_SED} ${_SED_CMDS} ${SED_CMDS.${.TARGET:R}} \
157 < ${.IMPSRC} > ${.TARGET}.tmp1 158 < ${.IMPSRC} > ${.TARGET}.tmp1
158 @${POSTPROC.${.TARGET:R}:U${TOOL_SED}} < ${.TARGET}.tmp1 > ${.TARGET}.tmp2 159 @${POSTPROC.${.TARGET:R}:U${TOOL_SED}} < ${.TARGET}.tmp1 > ${.TARGET}.tmp2
159 @rm ${.TARGET}.tmp1 160 @rm ${.TARGET}.tmp1
160 @echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp2 161 @echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp2
161 @mv ${.TARGET}.tmp2 ${.TARGET} 162 @mv ${.TARGET}.tmp2 ${.TARGET}
162 163
163# Compare all output files 164# Compare all output files
164test: ${OUTFILES} .PHONY 165test: ${OUTFILES} .PHONY
165 @failed= ; \ 166 @failed= ; \
166 for test in ${TESTS}; do \ 167 for test in ${TESTS}; do \
167 diff -u ${UNIT_TESTS}/$${test}.exp $${test}.out \ 168 diff -u ${UNIT_TESTS}/$${test}.exp $${test}.out \
168 || failed="$${failed}$${failed:+ }$${test}" ; \ 169 || failed="$${failed}$${failed:+ }$${test}" ; \
169 done ; \ 170 done ; \
170 if [ -n "$${failed}" ]; then \ 171 if [ -n "$${failed}" ]; then \
171 echo "Failed tests: $${failed}" ; false ; \ 172 echo "Failed tests: $${failed}" ; false ; \
172 else \ 173 else \
173 echo "All tests passed" ; \ 174 echo "All tests passed" ; \
174 fi 175 fi
175 176
176accept: 177accept:
177 @for test in ${TESTS}; do \ 178 @for test in ${TESTS}; do \
178 cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \ 179 cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \
179 || { echo "Replacing $${test}.exp" ; \ 180 || { echo "Replacing $${test}.exp" ; \
180 cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \ 181 cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \
181 done 182 done
182 183
183.if exists(${TEST_MAKE}) 184.if exists(${TEST_MAKE})
184${TESTS:=.rawout}: ${TEST_MAKE} 185${TESTS:=.rawout}: ${TEST_MAKE}
185.endif 186.endif
186 187
187.-include <bsd.obj.mk> 188.-include <bsd.obj.mk>

cvs diff -r1.2 -r1.3 src/usr.bin/make/unit-tests/export-all.mk (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 (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 (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 (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 (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