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