Makefile revision 1.60
1# $NetBSD: Makefile,v 1.60 2020/07/04 21:04:25 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#
15# Adding a test case
16#
17# Each feature should get its own set of tests in its own suitably
18# named makefile (*.mk), with its own set of expected results (*.exp),
19# and it should be added to the TESTNAMES list.
20#
21# Any added files must also be added to src/distrib/sets/lists/tests/mi.
22# Makefiles that are not added to TESTNAMES must be ignored in
23# src/tests/usr.bin/make/t_make.sh (example: include-sub).
24#
25
26.MAIN: all
27
28UNIT_TESTS:= ${.PARSEDIR}
29.PATH: ${UNIT_TESTS}
30
31# Each test is in a sub-makefile.
32# Keep the list sorted.
33TESTNAMES= \
34	comment \
35	cond-late \
36	cond-short \
37	cond1 \
38	cond2 \
39	dollar \
40	doterror \
41	dotwait \
42	error \
43	export \
44	export-all \
45	export-env \
46	forloop \
47	forsubst \
48	hash \
49	include-main \
50	misc \
51	moderrs \
52	modmatch \
53	modmisc \
54	modorder \
55	modts \
56	modword \
57	order \
58	posix \
59	qequals \
60	sunshcmd \
61	sysv \
62	ternary \
63	unexport \
64	unexport-env \
65	varcmd \
66	varmisc \
67	varmod-edge \
68	varquote \
69	varshell
70
71# these tests were broken by referting POSIX chanegs
72STRICT_POSIX_TESTS = \
73	escape \
74	impsrc \
75	phony-end \
76	posix1 \
77	suffixes
78
79# Override make flags for certain tests
80flags.doterror=
81flags.order=-j1
82
83OUTFILES= ${TESTNAMES:S/$/.out/}
84
85all: ${OUTFILES}
86
87CLEANFILES += *.rawout *.out *.status *.tmp *.core *.tmp
88CLEANFILES += obj*.[och] lib*.a		# posix1.mk
89CLEANFILES += issue* .[ab]*		# suffixes.mk
90CLEANRECURSIVE += dir dummy		# posix1.mk
91
92clean:
93	rm -f ${CLEANFILES}
94.if !empty(CLEANRECURSIVE)
95	rm -rf ${CLEANRECURSIVE}
96.endif
97
98TEST_MAKE?= ${.MAKE}
99TOOL_SED?= sed
100
101# ensure consistent results from sort(1)
102LC_ALL= C
103LANG= C
104.export LANG LC_ALL
105
106# the tests are actually done with sub-makes.
107.SUFFIXES: .mk .rawout .out
108.mk.rawout:
109	@echo ${TEST_MAKE} ${flags.${.TARGET:R}:U-k} -f ${.IMPSRC}
110	-@cd ${.OBJDIR} && \
111	{ ${TEST_MAKE} ${flags.${.TARGET:R}:U-k} -f ${.IMPSRC} \
112	  2>&1 ; echo $$? >${.TARGET:R}.status ; } > ${.TARGET}.tmp
113	@mv ${.TARGET}.tmp ${.TARGET}
114
115# We always pretend .MAKE was called 'make' 
116# and strip ${.CURDIR}/ from the output
117# and replace anything after 'stopped in' with unit-tests
118# so the results can be compared.
119.rawout.out:
120	@echo postprocess ${.TARGET}
121	@${TOOL_SED} -e 's,^${TEST_MAKE:T:C/\./\\\./g}[][0-9]*:,make:,' \
122	  -e 's,${TEST_MAKE:C/\./\\\./g},make,' \
123	  -e '/stopped/s, /.*, unit-tests,' \
124	  -e 's,${.CURDIR:C/\./\\\./g}/,,g' \
125	  -e 's,${UNIT_TESTS:C/\./\\\./g}/,,g' \
126	  < ${.IMPSRC} > ${.TARGET}.tmp
127	@echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp
128	@mv ${.TARGET}.tmp ${.TARGET}
129
130# Compare all output files
131test:	${OUTFILES} .PHONY
132	@failed= ; \
133	for test in ${TESTNAMES}; do \
134	  diff -u ${UNIT_TESTS}/$${test}.exp $${test}.out \
135	  || failed="$${failed}$${failed:+ }$${test}" ; \
136	done ; \
137	if [ -n "$${failed}" ]; then \
138	  echo "Failed tests: $${failed}" ; false ; \
139	else \
140	  echo "All tests passed" ; \
141	fi
142
143accept:
144	@for test in ${TESTNAMES}; do \
145	  cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \
146	  || { echo "Replacing $${test}.exp" ; \
147	       cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \
148	done
149
150.if exists(${TEST_MAKE})
151${TESTNAMES:S/$/.rawout/}: ${TEST_MAKE}
152.endif
153
154.-include <bsd.obj.mk>
155