Makefile revision 1.45
1# $NetBSD: Makefile,v 1.45 2014/08/23 15:02:04 christos Exp $
2#
3# Unit tests for make(1)
4# The main targets are:
5# 
6# all:	run all the tests
7# test:	run 'all', 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 (*.mk), with its own set of expected results (*.exp),
13# and it should be added to the TESTNAMES list.
14# 
15
16.MAIN: all
17
18UNIT_TESTS:= ${.PARSEDIR}
19.PATH: ${UNIT_TESTS}
20
21# Each test is in a sub-makefile.
22# Keep the list sorted.
23TESTNAMES= \
24	comment \
25	cond1 \
26	error \
27	export \
28	export-all \
29	export-env \
30	doterror \
31	dotwait \
32	forloop \
33	forsubst \
34	hash \
35	impsrc \
36	misc \
37	moderrs \
38	modmatch \
39	modmisc \
40	modorder \
41	modts \
42	modword \
43	order \
44	phony-end \
45	posix \
46	qequals \
47	suffixes \
48	sunshcmd \
49	sysv \
50	ternary \
51	unexport \
52	unexport-env \
53	varcmd \
54	varmisc \
55	varshell
56
57# Override make flags for certain tests
58flags.doterror=
59flags.order=-j1
60
61OUTFILES= ${TESTNAMES:S/$/.out/}
62
63all: ${OUTFILES}
64
65clean:
66	rm -f *.rawout *.out *.status *.tmp *.core *.tmp
67
68TEST_MAKE?= ${.MAKE}
69TOOL_SED?= sed
70
71# ensure consistent results from sort(1)
72LC_ALL= C
73LANG= C
74.export LANG LC_ALL
75
76# the tests are actually done with sub-makes.
77.SUFFIXES: .mk .rawout .out
78.mk.rawout:
79	@echo ${TEST_MAKE} ${flags.${.TARGET:R}:U-k} -f ${.IMPSRC}
80	-@cd ${.OBJDIR} && \
81	{ ${TEST_MAKE} ${flags.${.TARGET:R}:U-k} -f ${.IMPSRC} \
82	  2>&1 ; echo $$? >${.TARGET:R}.status ; } > ${.TARGET}.tmp
83	@mv ${.TARGET}.tmp ${.TARGET}
84
85# We always pretend .MAKE was called 'make' 
86# and strip ${.CURDIR}/ from the output
87# and replace anything after 'stopped in' with unit-tests
88# so the results can be compared.
89.rawout.out:
90	@echo postprocess ${.TARGET}
91	@${TOOL_SED} -e 's,^${TEST_MAKE:T:C/\./\\\./g}[][0-9]*:,make:,' \
92	  -e 's,${TEST_MAKE:C/\./\\\./g},make,' \
93	  -e '/stopped/s, /.*, unit-tests,' \
94	  -e 's,${.CURDIR:C/\./\\\./g}/,,g' \
95	  -e 's,${UNIT_TESTS:C/\./\\\./g}/,,g' \
96	  < ${.IMPSRC} > ${.TARGET}.tmp
97	@echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp
98	@mv ${.TARGET}.tmp ${.TARGET}
99
100# Compare all output files
101test:	${OUTFILES} .PHONY
102	@failed= ; \
103	for test in ${TESTNAMES}; do \
104	  diff -u ${UNIT_TESTS}/$${test}.exp $${test}.out \
105	  || failed="$${failed}$${failed:+ }$${test}" ; \
106	done ; \
107	if [ -n "$${failed}" ]; then \
108	  echo "Failed tests: $${failed}" ; false ; \
109	else \
110	  echo "All tests passed" ; \
111	fi
112
113accept:
114	@for test in ${TESTNAMES}; do \
115	  cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \
116	  || { echo "Replacing $${test}.exp" ; \
117	       cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \
118	done
119
120.-include <bsd.obj.mk>
121