Mon Jul 27 18:51:56 2020 UTC ()
make(1): add very basic test for archive handling

The whole code in arch.c had been uncovered by tests before.

The code coverage shows that neither the archive name nor the member
contain any $, even though archive.mk looks like it.  It could be
necessary to place the variable assignments below the dependency line,
to force late evaluation.


(rillig)
diff -r1.66 -r1.67 src/usr.bin/make/unit-tests/Makefile

cvs diff -r1.66 -r1.67 src/usr.bin/make/unit-tests/Makefile (switch to unified diff)

--- src/usr.bin/make/unit-tests/Makefile 2020/07/26 22:15:36 1.66
+++ src/usr.bin/make/unit-tests/Makefile 2020/07/27 18:51:56 1.67
@@ -1,186 +1,187 @@ @@ -1,186 +1,187 @@
1# $NetBSD: Makefile,v 1.66 2020/07/26 22:15:36 rillig Exp $ 1# $NetBSD: Makefile,v 1.67 2020/07/27 18:51: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+= comment 34TESTS+= comment
34TESTS+= cond-late 35TESTS+= cond-late
35TESTS+= cond-short 36TESTS+= cond-short
36TESTS+= cond1 37TESTS+= cond1
37TESTS+= cond2 38TESTS+= cond2
38TESTS+= dollar 39TESTS+= dollar
39TESTS+= doterror 40TESTS+= doterror
40TESTS+= dotwait 41TESTS+= dotwait
41TESTS+= envfirst 42TESTS+= envfirst
42TESTS+= error 43TESTS+= error
43TESTS+= # escape # broken by reverting POSIX changes 44TESTS+= # escape # broken by reverting POSIX changes
44TESTS+= export 45TESTS+= export
45TESTS+= export-all 46TESTS+= export-all
46TESTS+= export-env 47TESTS+= export-env
47TESTS+= forloop 48TESTS+= forloop
48TESTS+= forsubst 49TESTS+= forsubst
49TESTS+= hash 50TESTS+= hash
50TESTS+= # impsrc # broken by reverting POSIX changes 51TESTS+= # impsrc # broken by reverting POSIX changes
51TESTS+= include-main 52TESTS+= include-main
52TESTS+= misc 53TESTS+= misc
53TESTS+= moderrs 54TESTS+= moderrs
54TESTS+= modmatch 55TESTS+= modmatch
55TESTS+= modmisc 56TESTS+= modmisc
56TESTS+= modorder 57TESTS+= modorder
57TESTS+= modts 58TESTS+= modts
58TESTS+= modword 59TESTS+= modword
59TESTS+= order 60TESTS+= order
60TESTS+= # phony-end # broken by reverting POSIX changes 61TESTS+= # phony-end # broken by reverting POSIX changes
61TESTS+= posix 62TESTS+= posix
62TESTS+= # posix1 # broken by reverting POSIX changes 63TESTS+= # posix1 # broken by reverting POSIX changes
63TESTS+= qequals 64TESTS+= qequals
64TESTS+= # suffixes # broken by reverting POSIX changes 65TESTS+= # suffixes # broken by reverting POSIX changes
65TESTS+= sunshcmd 66TESTS+= sunshcmd
66TESTS+= sysv 67TESTS+= sysv
67TESTS+= ternary 68TESTS+= ternary
68TESTS+= unexport 69TESTS+= unexport
69TESTS+= unexport-env 70TESTS+= unexport-env
70TESTS+= varcmd 71TESTS+= varcmd
71TESTS+= vardebug 72TESTS+= vardebug
72TESTS+= varfind 73TESTS+= varfind
73TESTS+= varmisc 74TESTS+= varmisc
74TESTS+= varmod-edge 75TESTS+= varmod-edge
75TESTS+= varparse-dynamic 76TESTS+= varparse-dynamic
76TESTS+= varquote 77TESTS+= varquote
77TESTS+= varshell 78TESTS+= varshell
78 79
79# Override environment variables for some of the tests. 80# Override environment variables for some of the tests.
80ENV.envfirst= FROM_ENV=value-from-env 81ENV.envfirst= FROM_ENV=value-from-env
81ENV.varmisc= FROM_ENV=env 82ENV.varmisc= FROM_ENV=env
82ENV.varmisc+= FROM_ENV_BEFORE=env 83ENV.varmisc+= FROM_ENV_BEFORE=env
83ENV.varmisc+= FROM_ENV_AFTER=env 84ENV.varmisc+= FROM_ENV_AFTER=env
84 85
85# Override make flags for some of the tests; default is -k. 86# Override make flags for some of the tests; default is -k.
86FLAGS.doterror= # none 87FLAGS.doterror= # none
87FLAGS.order= -j1 88FLAGS.order= -j1
88FLAGS.envfirst= -e 89FLAGS.envfirst= -e
89FLAGS.vardebug= -k -dv FROM_CMDLINE= 90FLAGS.vardebug= -k -dv FROM_CMDLINE=
90 91
91# Some tests need extra post-processing. 92# Some tests need extra post-processing.
92SED_CMDS.modmisc+= -e 's,\(substitution error:\).*,\1 (details omitted),' 93SED_CMDS.modmisc+= -e 's,\(substitution error:\).*,\1 (details omitted),'
93SED_CMDS.varshell+= -e 's,^[a-z]*sh: ,,' 94SED_CMDS.varshell+= -e 's,^[a-z]*sh: ,,'
94SED_CMDS.varshell+= -e '/command/s,No such.*,not found,' 95SED_CMDS.varshell+= -e '/command/s,No such.*,not found,'
95 96
96# Some tests need an additional round of postprocessing. 97# Some tests need an additional round of postprocessing.
97POSTPROC.vardebug= ${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p' 98POSTPROC.vardebug= ${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p'
98 99
99# End of the configuration section. 100# End of the configuration section.
100 101
101.MAIN: all 102.MAIN: all
102 103
103UNIT_TESTS:= ${.PARSEDIR} 104UNIT_TESTS:= ${.PARSEDIR}
104.PATH: ${UNIT_TESTS} 105.PATH: ${UNIT_TESTS}
105 106
106OUTFILES= ${TESTS:=.out} 107OUTFILES= ${TESTS:=.out}
107 108
108all: ${OUTFILES} 109all: ${OUTFILES}
109 110
110CLEANFILES+= *.rawout *.out *.status *.tmp *.core *.tmp 111CLEANFILES+= *.rawout *.out *.status *.tmp *.core *.tmp
111CLEANFILES+= obj*.[och] lib*.a # posix1.mk 112CLEANFILES+= obj*.[och] lib*.a # posix1.mk
112CLEANFILES+= issue* .[ab]* # suffixes.mk 113CLEANFILES+= issue* .[ab]* # suffixes.mk
113CLEANRECURSIVE+= dir dummy # posix1.mk 114CLEANRECURSIVE+= dir dummy # posix1.mk
114 115
115clean: 116clean:
116 rm -f ${CLEANFILES} 117 rm -f ${CLEANFILES}
117.if !empty(CLEANRECURSIVE) 118.if !empty(CLEANRECURSIVE)
118 rm -rf ${CLEANRECURSIVE} 119 rm -rf ${CLEANRECURSIVE}
119.endif 120.endif
120 121
121TEST_MAKE?= ${.MAKE} 122TEST_MAKE?= ${.MAKE}
122TOOL_SED?= sed 123TOOL_SED?= sed
123 124
124# ensure consistent results from sort(1) 125# ensure consistent results from sort(1)
125LC_ALL= C 126LC_ALL= C
126LANG= C 127LANG= C
127.export LANG LC_ALL 128.export LANG LC_ALL
128 129
129# the tests are actually done with sub-makes. 130# the tests are actually done with sub-makes.
130.SUFFIXES: .mk .rawout .out 131.SUFFIXES: .mk .rawout .out
131.mk.rawout: 132.mk.rawout:
132 @echo testing ${.IMPSRC} 133 @echo testing ${.IMPSRC}
133 @set -eu; \ 134 @set -eu; \
134 cd ${.OBJDIR}; \ 135 cd ${.OBJDIR}; \
135 ${ENV.${.TARGET:R}} ${TEST_MAKE} \ 136 ${ENV.${.TARGET:R}} ${TEST_MAKE} \
136 ${FLAGS.${.TARGET:R}:U-k} -f ${.IMPSRC} \ 137 ${FLAGS.${.TARGET:R}:U-k} -f ${.IMPSRC} \
137 > ${.TARGET}.tmp 2>&1 \ 138 > ${.TARGET}.tmp 2>&1 \
138 && status=$$? || status=$$?; \ 139 && status=$$? || status=$$?; \
139 echo $$status > ${.TARGET:R}.status 140 echo $$status > ${.TARGET:R}.status
140 @mv ${.TARGET}.tmp ${.TARGET} 141 @mv ${.TARGET}.tmp ${.TARGET}
141 142
142# Post-process the test output so that the results can be compared. 143# Post-process the test output so that the results can be compared.
143# 144#
144# always pretend .MAKE was called 'make' 145# always pretend .MAKE was called 'make'
145_SED_CMDS+= -e 's,^${TEST_MAKE:T:S,.,\\.,g}[][0-9]*:,make:,' 146_SED_CMDS+= -e 's,^${TEST_MAKE:T:S,.,\\.,g}[][0-9]*:,make:,'
146_SED_CMDS+= -e 's,${TEST_MAKE:S,.,\\.,g},make,' 147_SED_CMDS+= -e 's,${TEST_MAKE:S,.,\\.,g},make,'
147# replace anything after 'stopped in' with unit-tests 148# replace anything after 'stopped in' with unit-tests
148_SED_CMDS+= -e '/stopped/s, /.*, unit-tests,' 149_SED_CMDS+= -e '/stopped/s, /.*, unit-tests,'
149# strip ${.CURDIR}/ from the output 150# strip ${.CURDIR}/ from the output
150_SED_CMDS+= -e 's,${.CURDIR:S,.,\\.,g}/,,g' 151_SED_CMDS+= -e 's,${.CURDIR:S,.,\\.,g}/,,g'
151_SED_CMDS+= -e 's,${UNIT_TESTS:S,.,\\.,g}/,,g' 152_SED_CMDS+= -e 's,${UNIT_TESTS:S,.,\\.,g}/,,g'
152 153
153.rawout.out: 154.rawout.out:
154 @echo postprocess ${.TARGET} 155 @echo postprocess ${.TARGET}
155 @${TOOL_SED} ${_SED_CMDS} ${SED_CMDS.${.TARGET:R}} \ 156 @${TOOL_SED} ${_SED_CMDS} ${SED_CMDS.${.TARGET:R}} \
156 < ${.IMPSRC} > ${.TARGET}.tmp1 157 < ${.IMPSRC} > ${.TARGET}.tmp1
157 @${POSTPROC.${.TARGET:R}:U${TOOL_SED}} < ${.TARGET}.tmp1 > ${.TARGET}.tmp2 158 @${POSTPROC.${.TARGET:R}:U${TOOL_SED}} < ${.TARGET}.tmp1 > ${.TARGET}.tmp2
158 @rm ${.TARGET}.tmp1 159 @rm ${.TARGET}.tmp1
159 @echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp2 160 @echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp2
160 @mv ${.TARGET}.tmp2 ${.TARGET} 161 @mv ${.TARGET}.tmp2 ${.TARGET}
161 162
162# Compare all output files 163# Compare all output files
163test: ${OUTFILES} .PHONY 164test: ${OUTFILES} .PHONY
164 @failed= ; \ 165 @failed= ; \
165 for test in ${TESTS}; do \ 166 for test in ${TESTS}; do \
166 diff -u ${UNIT_TESTS}/$${test}.exp $${test}.out \ 167 diff -u ${UNIT_TESTS}/$${test}.exp $${test}.out \
167 || failed="$${failed}$${failed:+ }$${test}" ; \ 168 || failed="$${failed}$${failed:+ }$${test}" ; \
168 done ; \ 169 done ; \
169 if [ -n "$${failed}" ]; then \ 170 if [ -n "$${failed}" ]; then \
170 echo "Failed tests: $${failed}" ; false ; \ 171 echo "Failed tests: $${failed}" ; false ; \
171 else \ 172 else \
172 echo "All tests passed" ; \ 173 echo "All tests passed" ; \
173 fi 174 fi
174 175
175accept: 176accept:
176 @for test in ${TESTS}; do \ 177 @for test in ${TESTS}; do \
177 cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \ 178 cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \
178 || { echo "Replacing $${test}.exp" ; \ 179 || { echo "Replacing $${test}.exp" ; \
179 cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \ 180 cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \
180 done 181 done
181 182
182.if exists(${TEST_MAKE}) 183.if exists(${TEST_MAKE})
183${TESTS:=.rawout}: ${TEST_MAKE} 184${TESTS:=.rawout}: ${TEST_MAKE}
184.endif 185.endif
185 186
186.-include <bsd.obj.mk> 187.-include <bsd.obj.mk>