Makefile revision 1.83 1 # $NetBSD: Makefile,v 1.83 2020/08/03 15:43:32 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+= forloop
56 TESTS+= forsubst
57 TESTS+= hash
58 TESTS+= # impsrc # broken by reverting POSIX changes
59 TESTS+= include-main
60 TESTS+= lint
61 TESTS+= misc
62 TESTS+= moderrs
63 TESTS+= modmatch
64 TESTS+= modmisc
65 TESTS+= modorder
66 TESTS+= modts
67 TESTS+= modword
68 TESTS+= order
69 TESTS+= # phony-end # broken by reverting POSIX changes
70 TESTS+= posix
71 TESTS+= # posix1 # broken by reverting POSIX changes
72 TESTS+= qequals
73 TESTS+= # suffixes # broken by reverting POSIX changes
74 TESTS+= sunshcmd
75 TESTS+= sysv
76 TESTS+= ternary
77 TESTS+= unexport
78 TESTS+= unexport-env
79 TESTS+= varcmd
80 TESTS+= vardebug
81 TESTS+= varfind
82 TESTS+= varmisc
83 TESTS+= varmod-edge
84 TESTS+= varparse-dynamic
85 TESTS+= varquote
86 TESTS+= varshell
87
88 # Override environment variables for some of the tests.
89 ENV.counter= -i
90 ENV.envfirst= FROM_ENV=value-from-env
91 ENV.export= -i PATH=${PATH:Q}
92 ENV.lint= -i
93 ENV.varmisc= FROM_ENV=env
94 ENV.varmisc+= FROM_ENV_BEFORE=env
95 ENV.varmisc+= FROM_ENV_AFTER=env
96
97 # Override make flags for some of the tests; default is -k.
98 FLAGS.counter= -r -dv
99 FLAGS.doterror= # none
100 FLAGS.envfirst= -e
101 FLAGS.export= -r
102 FLAGS.lint= -dL -k
103 FLAGS.order= -j1
104 FLAGS.vardebug= -k -dv FROM_CMDLINE=
105
106 # Some tests need extra post-processing.
107 SED_CMDS.moderrs+= -e 's,\(Regex compilation error:\).*,\1 (details omitted),'
108 SED_CMDS.modmisc+= -e 's,\(Regex compilation error:\).*,\1 (details omitted),'
109 SED_CMDS.varmod-edge+= -e 's, line [0-9]*:, line omitted:,'
110 SED_CMDS.varshell+= -e 's,^[a-z]*sh: ,,'
111 SED_CMDS.varshell+= -e '/command/s,No such.*,not found,'
112
113 # Some tests need an additional round of postprocessing.
114 POSTPROC.counter= ${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p'
115 POSTPROC.vardebug= ${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p'
116
117 # End of the configuration section.
118
119 .MAIN: all
120
121 UNIT_TESTS:= ${.PARSEDIR}
122 .PATH: ${UNIT_TESTS}
123
124 OUTFILES= ${TESTS:=.out}
125
126 all: ${OUTFILES}
127
128 CLEANFILES+= *.rawout *.out *.status *.tmp *.core *.tmp
129 CLEANFILES+= obj*.[och] lib*.a # posix1.mk
130 CLEANFILES+= issue* .[ab]* # suffixes.mk
131 CLEANRECURSIVE+= dir dummy # posix1.mk
132
133 clean:
134 rm -f ${CLEANFILES}
135 .if !empty(CLEANRECURSIVE)
136 rm -rf ${CLEANRECURSIVE}
137 .endif
138
139 TEST_MAKE?= ${.MAKE}
140 TOOL_SED?= sed
141
142 # ensure consistent results from sort(1)
143 LC_ALL= C
144 LANG= C
145 .export LANG LC_ALL
146
147 # the tests are actually done with sub-makes.
148 .SUFFIXES: .mk .rawout .out
149 .mk.rawout:
150 @echo testing ${.IMPSRC}
151 @set -eu; \
152 cd ${.OBJDIR}; \
153 env ${ENV.${.TARGET:R}} ${TEST_MAKE} -C ${.CURDIR} \
154 ${FLAGS.${.TARGET:R}:U-k} -f ${.IMPSRC} \
155 > ${.TARGET}.tmp 2>&1 \
156 && status=$$? || status=$$?; \
157 echo $$status > ${.TARGET:R}.status
158 @mv ${.TARGET}.tmp ${.TARGET}
159
160 # Post-process the test output so that the results can be compared.
161 #
162 # always pretend .MAKE was called 'make'
163 _SED_CMDS+= -e 's,^${TEST_MAKE:T:S,.,\\.,g}[][0-9]*:,make:,'
164 _SED_CMDS+= -e 's,${TEST_MAKE:S,.,\\.,g},make,'
165 # replace anything after 'stopped in' with unit-tests
166 _SED_CMDS+= -e '/stopped/s, /.*, unit-tests,'
167 # strip ${.CURDIR}/ from the output
168 _SED_CMDS+= -e 's,${.CURDIR:S,.,\\.,g}/,,g'
169 _SED_CMDS+= -e 's,${UNIT_TESTS:S,.,\\.,g}/,,g'
170
171 .rawout.out:
172 @echo postprocess ${.TARGET}
173 @${TOOL_SED} ${_SED_CMDS} ${SED_CMDS.${.TARGET:R}} \
174 < ${.IMPSRC} > ${.TARGET}.tmp1
175 @${POSTPROC.${.TARGET:R}:Ucat} < ${.TARGET}.tmp1 > ${.TARGET}.tmp2
176 @rm ${.TARGET}.tmp1
177 @echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp2
178 @mv ${.TARGET}.tmp2 ${.TARGET}
179
180 # Compare all output files
181 test: ${OUTFILES} .PHONY
182 @failed= ; \
183 for test in ${TESTS}; do \
184 diff -u ${UNIT_TESTS}/$${test}.exp $${test}.out \
185 || failed="$${failed}$${failed:+ }$${test}" ; \
186 done ; \
187 if [ -n "$${failed}" ]; then \
188 echo "Failed tests: $${failed}" ; false ; \
189 else \
190 echo "All tests passed" ; \
191 fi
192
193 accept:
194 @for test in ${TESTS}; do \
195 cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \
196 || { echo "Replacing $${test}.exp" ; \
197 cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \
198 done
199
200 SYNC_MI_AWK= \
201 BEGIN { \
202 testsdir = "usr.bin/make/unit-tests"; \
203 linestart = "./usr/tests/" testsdir; \
204 fmt = linestart "/%s\ttests-usr.bin-tests\tcompattestfile,atf\\n"; \
205 cmd = "cd " testsdir " && ls *.exp *.mk | xargs printf '" fmt "'" \
206 } \
207 function startswith(s, prefix) { \
208 return substr(s, 1, length(prefix)) == prefix; \
209 } \
210 startswith($$1, linestart) && $$1 ~ /\.(exp|mk)$$/ { next } \
211 { print $$0 } \
212 $$1 == linestart "/Makefile" { system(cmd) }
213
214 sync-mi:
215 @set -eu; \
216 cd "${MAKEFILE:tA:H}/../../.."; \
217 mi="distrib/sets/lists/tests/mi"; \
218 awk ${SYNC_MI_AWK:Q} < "$$mi" > "$$mi.$@"; \
219 mv -f "$$mi.$@" "$$mi"; \
220 cvs diff "$$mi" || true
221
222 .if exists(${TEST_MAKE})
223 ${TESTS:=.rawout}: ${TEST_MAKE}
224 .endif
225
226 .-include <bsd.obj.mk>
227