xref: /netbsd-src/usr.bin/make/unit-tests/Makefile (revision af56d1fe9956bd7c616e18c1b7f025f464618471)
1# $NetBSD: Makefile,v 1.36 2013/03/22 16:36:46 sjg Exp $
2#
3# Unit tests for make(1)
4# The main targets are:
5#
6# all:	run all the tests
7# test:	run 'all', capture output and compare to expected results
8# accept: move generated output to expected results
9#
10# Adding a test case.
11# Each feature should get its own set of tests in its own suitably
12# named makefile which should be added to SUBFILES to hook it in.
13#
14
15.MAIN: all
16
17UNIT_TESTS:= ${.PARSEDIR}
18
19# Simple sub-makefiles - we run them as a black box
20# keep the list sorted.
21SUBFILES= \
22	comment \
23	cond1 \
24	error \
25	export \
26	export-all \
27	export-env \
28	doterror \
29	dotwait \
30	forloop \
31	forsubst \
32	hash \
33	misc \
34	moderrs \
35	modmatch \
36	modmisc \
37	modorder \
38	modts \
39	modword \
40	order \
41	phony-end \
42	posix \
43	qequals \
44	sysv \
45	ternary \
46	unexport \
47	unexport-env \
48	varcmd
49
50all: ${SUBFILES}
51
52flags.doterror=
53flags.order=-j1
54
55# the tests are actually done with sub-makes.
56.PHONY: ${SUBFILES}
57.PRECIOUS: ${SUBFILES}
58${SUBFILES}:
59	-@${.MAKE} ${flags.$@:U-k} -f ${UNIT_TESTS}/$@
60
61clean:
62	rm -f *.out *.fail *.core
63
64.-include <bsd.obj.mk>
65
66TEST_MAKE?= ${.MAKE}
67TOOL_SED?= sed
68
69# ensure consistent results from sort(1)
70LC_ALL= C
71LANG= C
72.export LANG LC_ALL
73
74# The driver.
75# We always pretend .MAKE was called 'make'
76# and strip ${.CURDIR}/ from the output
77# and replace anything after 'stopped in' with unit-tests
78# so the results can be compared.
79test:
80	@echo "${TEST_MAKE} -f ${MAKEFILE} > ${.TARGET}.out 2>&1"
81	@cd ${.OBJDIR} && ${TEST_MAKE} -f ${MAKEFILE} 2>&1 | \
82	${TOOL_SED} -e 's,^${TEST_MAKE:T:C/\./\\\./g}:,make:,' \
83	-e '/stopped/s, /.*, unit-tests,' \
84	-e 's,${.CURDIR:C/\./\\\./g}/,,g' \
85	-e 's,${UNIT_TESTS:C/\./\\\./g}/,,g' > ${.TARGET}.out || { \
86	tail ${.TARGET}.out; mv ${.TARGET}.out ${.TARGET}.fail; exit 1; }
87	diff -u ${UNIT_TESTS}/${.TARGET}.exp ${.TARGET}.out
88
89accept:
90	mv test.out ${.CURDIR}/test.exp
91
92