Makefile revision 1.90 1 # $NetBSD: Makefile,v 1.90 2020/08/09 12:59:16 rillig Exp $
2 #
3 # Unit tests for make(1)
4 #
5 # The main targets are:
6 #
7 # all:
8 # run all the tests
9 # test:
10 # run 'all', and compare to expected results
11 # accept:
12 # move generated output to expected results
13 #
14 # Settable variables
15 #
16 # TEST_MAKE
17 # The make program to be tested.
18 #
19 #
20 # Adding a test case
21 #
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),
24 # and it should be added to the TESTS list.
25 #
26 # Any added files must also be added to src/distrib/sets/lists/tests/mi.
27 # To do that, just run "make sync-mi" in this directory.
28 #
29 # A few *.mk files are helper files for other tests (such as include-sub.mk)
30 # and are thus not added to TESTS. Such files must be ignored in
31 # src/tests/usr.bin/make/t_make.sh.
32 #
33
34 # Each test is in a sub-makefile.
35 # Keep the list sorted.
36 TESTS+= # archive # broken on FreeBSD
37 TESTS+= cmdline
38 TESTS+= comment
39 TESTS+= cond-late
40 TESTS+= cond-short
41 TESTS+= cond1
42 TESTS+= cond2
43 TESTS+= counter
44 TESTS+= dir
45 TESTS+= directives
46 TESTS+= dollar
47 TESTS+= doterror
48 TESTS+= dotwait
49 TESTS+= envfirst
50 TESTS+= error
51 TESTS+= # escape # broken by reverting POSIX changes
52 TESTS+= export
53 TESTS+= export-all
54 TESTS+= export-env
55 TESTS+= export-variants
56 TESTS+= forloop
57 TESTS+= forsubst
58 TESTS+= hash
59 TESTS+= impsrc
60 TESTS+= include-main
61 TESTS+= lint
62 TESTS+= make-exported
63 TESTS+= misc
64 TESTS+= moderrs
65 TESTS+= modmatch
66 TESTS+= modmisc
67 TESTS+= modorder
68 TESTS+= modts
69 TESTS+= modword
70 TESTS+= order
71 TESTS+= phony-end
72 TESTS+= posix
73 TESTS+= # posix1 # broken by reverting POSIX changes
74 TESTS+= qequals
75 TESTS+= recursive
76 TESTS+= # suffixes # runs into an endless loop (try -dA)
77 TESTS+= sunshcmd
78 TESTS+= sysv
79 TESTS+= ternary
80 TESTS+= unexport
81 TESTS+= unexport-env
82 TESTS+= varcmd
83 TESTS+= vardebug
84 TESTS+= varfind
85 TESTS+= varmisc
86 TESTS+= varmod-edge
87 TESTS+= varparse-dynamic
88 TESTS+= varquote
89 TESTS+= varshell
90
91 # Override environment variables for some of the tests.
92 ENV.counter= -i
93 ENV.envfirst= FROM_ENV=value-from-env
94 ENV.export= -i PATH=${PATH:Q}
95 ENV.export-variants= -i PATH=${PATH:Q}
96 ENV.lint= -i
97 ENV.make-exported= -i PATH=${PATH:Q}
98 ENV.recursive= -i
99 ENV.varmisc= FROM_ENV=env
100 ENV.varmisc+= FROM_ENV_BEFORE=env
101 ENV.varmisc+= FROM_ENV_AFTER=env
102
103 # Override make flags for some of the tests; default is -k.
104 FLAGS.counter= -r -dv
105 FLAGS.doterror= # none
106 FLAGS.envfirst= -e
107 FLAGS.export= -r
108 FLAGS.lint= -dL -k
109 FLAGS.order= -j1
110 FLAGS.recursive= -dL -r
111 FLAGS.vardebug= -k -dv FROM_CMDLINE=
112
113 # Some tests need extra post-processing.
114 SED_CMDS.moderrs+= -e 's,\(Regex compilation error:\).*,\1 (details omitted),'
115 SED_CMDS.modmisc+= -e 's,\(Regex compilation error:\).*,\1 (details omitted),'
116 SED_CMDS.varmod-edge+= -e 's, line [0-9]*:, line omitted:,'
117 SED_CMDS.varshell+= -e 's,^[a-z]*sh: ,,'
118 SED_CMDS.varshell+= -e '/command/s,No such.*,not found,'
119
120 # Some tests need an additional round of postprocessing.
121 POSTPROC.counter= ${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p'
122 POSTPROC.vardebug= ${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p'
123
124 export-all.rawout: export.mk
125 unexport.rawout: export.mk
126 unexport-env.rawout: export.mk
127
128 # End of the configuration section.
129
130 .MAIN: all
131
132 UNIT_TESTS:= ${.PARSEDIR}
133 .PATH: ${UNIT_TESTS}
134
135 OUTFILES= ${TESTS:=.out}
136
137 all: ${OUTFILES}
138
139 CLEANFILES+= *.rawout *.out *.status *.tmp *.core *.tmp
140 CLEANFILES+= obj*.[och] lib*.a # posix1.mk
141 CLEANFILES+= issue* .[ab]* # suffixes.mk
142 CLEANRECURSIVE+= dir dummy # posix1.mk
143
144 clean:
145 rm -f ${CLEANFILES}
146 .if !empty(CLEANRECURSIVE)
147 rm -rf ${CLEANRECURSIVE}
148 .endif
149
150 TEST_MAKE?= ${.MAKE}
151 TOOL_SED?= sed
152
153 # ensure consistent results from sort(1)
154 LC_ALL= C
155 LANG= C
156 .export LANG LC_ALL
157
158 # the tests are actually done with sub-makes.
159 .SUFFIXES: .mk .rawout .out
160 .mk.rawout:
161 @echo testing ${.IMPSRC}
162 @set -eu; \
163 cd ${.OBJDIR}; \
164 env ${ENV.${.TARGET:R}} ${TEST_MAKE} -C ${.CURDIR} \
165 ${FLAGS.${.TARGET:R}:U-k} -f ${.IMPSRC} \
166 > ${.TARGET}.tmp 2>&1 \
167 && status=$$? || status=$$?; \
168 echo $$status > ${.TARGET:R}.status
169 @mv ${.TARGET}.tmp ${.TARGET}
170
171 # Post-process the test output so that the results can be compared.
172 #
173 # always pretend .MAKE was called 'make'
174 _SED_CMDS+= -e 's,^${TEST_MAKE:T:S,.,\\.,g}[][0-9]*:,make:,'
175 _SED_CMDS+= -e 's,${TEST_MAKE:S,.,\\.,g},make,'
176 # replace anything after 'stopped in' with unit-tests
177 _SED_CMDS+= -e '/stopped/s, /.*, unit-tests,'
178 # strip ${.CURDIR}/ from the output
179 _SED_CMDS+= -e 's,${.CURDIR:S,.,\\.,g}/,,g'
180 _SED_CMDS+= -e 's,${UNIT_TESTS:S,.,\\.,g}/,,g'
181
182 .rawout.out:
183 @echo postprocess ${.TARGET}
184 @${TOOL_SED} ${_SED_CMDS} ${SED_CMDS.${.TARGET:R}} \
185 < ${.IMPSRC} > ${.TARGET}.tmp1
186 @${POSTPROC.${.TARGET:R}:Ucat} < ${.TARGET}.tmp1 > ${.TARGET}.tmp2
187 @rm ${.TARGET}.tmp1
188 @echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp2
189 @mv ${.TARGET}.tmp2 ${.TARGET}
190
191 # Compare all output files
192 test: ${OUTFILES} .PHONY
193 @failed= ; \
194 for test in ${TESTS}; do \
195 diff -u ${UNIT_TESTS}/$${test}.exp $${test}.out \
196 || failed="$${failed}$${failed:+ }$${test}" ; \
197 done ; \
198 if [ -n "$${failed}" ]; then \
199 echo "Failed tests: $${failed}" ; false ; \
200 else \
201 echo "All tests passed" ; \
202 fi
203
204 accept:
205 @for test in ${TESTS}; do \
206 cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \
207 || { echo "Replacing $${test}.exp" ; \
208 cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \
209 done
210
211 SYNC_MI_AWK= \
212 BEGIN { \
213 testsdir = "usr.bin/make/unit-tests"; \
214 linestart = "./usr/tests/" testsdir; \
215 fmt = linestart "/%s\ttests-usr.bin-tests\tcompattestfile,atf\\n"; \
216 cmd = "cd " testsdir " && ls *.exp *.mk | xargs printf '" fmt "'" \
217 } \
218 function startswith(s, prefix) { \
219 return substr(s, 1, length(prefix)) == prefix; \
220 } \
221 startswith($$1, linestart) && $$1 ~ /\.(exp|mk)$$/ { next } \
222 { print $$0 } \
223 $$1 == linestart "/Makefile" { system(cmd) }
224
225 sync-mi:
226 @set -eu; \
227 cd "${MAKEFILE:tA:H}/../../.."; \
228 mi="distrib/sets/lists/tests/mi"; \
229 awk ${SYNC_MI_AWK:Q} < "$$mi" > "$$mi.$@"; \
230 mv -f "$$mi.$@" "$$mi"; \
231 cvs diff "$$mi" || true
232
233 .if exists(${TEST_MAKE})
234 ${TESTS:=.rawout}: ${TEST_MAKE}
235 .endif
236
237 .-include <bsd.obj.mk>
238