Makefile revision 1.9
1# $Id: Makefile,v 1.9 2004/01/09 00:56:44 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 which should be hooked
12# into the 'all' target.
13# 
14
15.MAIN: all
16
17UNIT_TESTS:= ${.PARSEDIR}
18
19all: mod-ts varcmd modword ternary
20
21LIST= one two three
22LIST+= four five six
23
24FU_mod-ts = a / b / cool
25
26AAA= a a a
27B.aaa= Baaa
28
29mod-ts:
30	@echo 'LIST="${LIST}"'
31	@echo 'LIST:ts,="${LIST:ts,}"'
32	@echo 'LIST:ts/:tu="${LIST:ts/:tu}"'
33	@echo 'LIST:ts::tu="${LIST:ts::tu}"'
34	@echo 'LIST:ts:tu="${LIST:ts:tu}"'
35	@echo 'LIST:tu:ts/="${LIST:tu:ts/}"'
36	@echo 'LIST:ts:="${LIST:ts:}"'
37	@echo 'LIST:ts="${LIST:ts}"'
38	@echo 'LIST:ts:S/two/2/="${LIST:ts:S/two/2/}"'
39	@echo 'LIST:S/two/2/:ts="${LIST:S/two/2/:ts}"'
40	@echo 'LIST:ts/:S/two/2/="${LIST:ts/:S/two/2/}"'
41	@echo "Pretend the '/' in '/n' etc. below are back-slashes."
42	@echo 'LIST:ts/n="${LIST:ts\n}"'
43	@echo 'LIST:ts/t="${LIST:ts\t}"'
44	@echo 'LIST:ts/012:tu="${LIST:ts\012:tu}"'
45	@echo 'LIST:tx="${LIST:tx}"'
46	@echo 'LIST:ts/x:tu="${LIST:ts\x:tu}"'
47	@echo 'FU_$@="${FU_${@:ts}:ts}"'
48	@echo 'FU_$@:ts:T="${FU_${@:ts}:ts:T}" == cool?'
49	@echo 'B.$${AAA:ts}="${B.${AAA:ts}}" == Baaa?'
50
51# Some tests are best handled via a sub-make
52.PHONY: varcmd modword
53varcmd modword:
54	@${.MAKE} -k -f ${UNIT_TESTS}/$@
55
56ternary:
57	@${.MAKE} -k -f ${UNIT_TESTS}/$@
58	@${.MAKE} -k -f ${UNIT_TESTS}/$@ A=
59	@${.MAKE} -k -f ${UNIT_TESTS}/$@ A=42
60
61clean:
62	rm -f *.out *.fail *.core
63
64.include <bsd.obj.mk>
65
66TEST_MAKE?= ${MAKE}
67
68# here is the driver
69test:
70	@echo "${TEST_MAKE} -f ${MAKEFILE} > ${.TARGET}.out 2>&1"
71	@cd ${.OBJDIR} && ${TEST_MAKE} -f ${MAKEFILE} 2>&1 | \
72	sed 's,^${TEST_MAKE:T}:,make:,' > ${.TARGET}.out || { \
73	tail ${.TARGET}.out; mv ${.TARGET}.out ${.TARGET}.fail; exit 1; }
74	diff -u ${UNIT_TESTS}/${.TARGET}.exp ${.TARGET}.out
75
76accept:
77	mv test.out ${.CURDIR}/test.exp
78
79