Makefile revision 1.35
1# $NetBSD: Makefile,v 1.35 2012/11/09 19:08:28 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	doterror \
28	dotwait \
29	forloop \
30	forsubst \
31	hash \
32	misc \
33	moderrs \
34	modmatch \
35	modmisc \
36	modorder \
37	modts \
38	modword \
39	order \
40	phony-end \
41	posix \
42	qequals \
43	sysv \
44	ternary \
45	unexport \
46	unexport-env \
47	varcmd
48
49all: ${SUBFILES}
50
51flags.doterror=
52flags.order=-j1
53
54# the tests are actually done with sub-makes.
55.PHONY: ${SUBFILES}
56.PRECIOUS: ${SUBFILES}
57${SUBFILES}:
58	-@${.MAKE} ${flags.$@:U-k} -f ${UNIT_TESTS}/$@
59
60clean:
61	rm -f *.out *.fail *.core
62
63.-include <bsd.obj.mk>
64
65TEST_MAKE?= ${.MAKE}
66TOOL_SED?= sed
67
68# ensure consistent results from sort(1)
69LC_ALL= C
70LANG= C
71.export LANG LC_ALL
72
73# The driver.
74# We always pretend .MAKE was called 'make' 
75# and strip ${.CURDIR}/ from the output
76# and replace anything after 'stopped in' with unit-tests
77# so the results can be compared.
78test:
79	@echo "${TEST_MAKE} -f ${MAKEFILE} > ${.TARGET}.out 2>&1"
80	@cd ${.OBJDIR} && ${TEST_MAKE} -f ${MAKEFILE} 2>&1 | \
81	${TOOL_SED} -e 's,^${TEST_MAKE:T:C/\./\\\./g}:,make:,' \
82	-e '/stopped/s, /.*, unit-tests,' \
83	-e 's,${.CURDIR:C/\./\\\./g}/,,g' \
84	-e 's,${UNIT_TESTS:C/\./\\\./g}/,,g' > ${.TARGET}.out || { \
85	tail ${.TARGET}.out; mv ${.TARGET}.out ${.TARGET}.fail; exit 1; }
86	diff -u ${UNIT_TESTS}/${.TARGET}.exp ${.TARGET}.out
87
88accept:
89	mv test.out ${.CURDIR}/test.exp
90
91