summaryrefslogtreecommitdiff
path: root/usr.bin/make/unit-tests/Makefile
blob: c8bb2c1bfac6f127f5a7f6d16f25ecb6bcfaa778 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# $Id: Makefile,v 1.9 2004/01/09 00:56:44 sjg Exp $
#
# Unit tests for make(1)
# The main targets are:
# 
# all:	run all the tests
# test:	run 'all', capture output and compare to expected results
# accept: move generated output to expected results
#
# Adding a test case.  
# Each feature should get its own set of tests which should be hooked
# into the 'all' target.
# 

.MAIN: all

UNIT_TESTS:= ${.PARSEDIR}

all: mod-ts varcmd modword ternary

LIST= one two three
LIST+= four five six

FU_mod-ts = a / b / cool

AAA= a a a
B.aaa= Baaa

mod-ts:
	@echo 'LIST="${LIST}"'
	@echo 'LIST:ts,="${LIST:ts,}"'
	@echo 'LIST:ts/:tu="${LIST:ts/:tu}"'
	@echo 'LIST:ts::tu="${LIST:ts::tu}"'
	@echo 'LIST:ts:tu="${LIST:ts:tu}"'
	@echo 'LIST:tu:ts/="${LIST:tu:ts/}"'
	@echo 'LIST:ts:="${LIST:ts:}"'
	@echo 'LIST:ts="${LIST:ts}"'
	@echo 'LIST:ts:S/two/2/="${LIST:ts:S/two/2/}"'
	@echo 'LIST:S/two/2/:ts="${LIST:S/two/2/:ts}"'
	@echo 'LIST:ts/:S/two/2/="${LIST:ts/:S/two/2/}"'
	@echo "Pretend the '/' in '/n' etc. below are back-slashes."
	@echo 'LIST:ts/n="${LIST:ts\n}"'
	@echo 'LIST:ts/t="${LIST:ts\t}"'
	@echo 'LIST:ts/012:tu="${LIST:ts\012:tu}"'
	@echo 'LIST:tx="${LIST:tx}"'
	@echo 'LIST:ts/x:tu="${LIST:ts\x:tu}"'
	@echo 'FU_$@="${FU_${@:ts}:ts}"'
	@echo 'FU_$@:ts:T="${FU_${@:ts}:ts:T}" == cool?'
	@echo 'B.$${AAA:ts}="${B.${AAA:ts}}" == Baaa?'

# Some tests are best handled via a sub-make
.PHONY: varcmd modword
varcmd modword:
	@${.MAKE} -k -f ${UNIT_TESTS}/$@

ternary:
	@${.MAKE} -k -f ${UNIT_TESTS}/$@
	@${.MAKE} -k -f ${UNIT_TESTS}/$@ A=
	@${.MAKE} -k -f ${UNIT_TESTS}/$@ A=42

clean:
	rm -f *.out *.fail *.core

.include <bsd.obj.mk>

TEST_MAKE?= ${MAKE}

# here is the driver
test:
	@echo "${TEST_MAKE} -f ${MAKEFILE} > ${.TARGET}.out 2>&1"
	@cd ${.OBJDIR} && ${TEST_MAKE} -f ${MAKEFILE} 2>&1 | \
	sed 's,^${TEST_MAKE:T}:,make:,' > ${.TARGET}.out || { \
	tail ${.TARGET}.out; mv ${.TARGET}.out ${.TARGET}.fail; exit 1; }
	diff -u ${UNIT_TESTS}/${.TARGET}.exp ${.TARGET}.out

accept:
	mv test.out ${.CURDIR}/test.exp