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