1 # $Id: Makefile,v 1.10 2004/01/19 00:32:26 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 17 UNIT_TESTS:= ${.PARSEDIR} 18 19 all: mod-ts varcmd modword ternary 20 21 LIST= one two three 22 LIST+= four five six 23 24 FU_mod-ts = a / b / cool 25 26 AAA= a a a 27 B.aaa= Baaa 28 29 mod-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 53 varcmd modword: 54 @${.MAKE} -k -f ${UNIT_TESTS}/$@ 55 56 .PHONY: ternary 57 ternary: 58 @${.MAKE} -k -f ${UNIT_TESTS}/$@ 59 @${.MAKE} -k -f ${UNIT_TESTS}/$@ A= 60 @${.MAKE} -k -f ${UNIT_TESTS}/$@ A=42 61 62 clean: 63 rm -f *.out *.fail *.core 64 65 .include <bsd.obj.mk> 66 67 TEST_MAKE?= ${MAKE} 68 69 # here is the driver 70 test: 71 @echo "${TEST_MAKE} -f ${MAKEFILE} > ${.TARGET}.out 2>&1" 72 @cd ${.OBJDIR} && ${TEST_MAKE} -f ${MAKEFILE} 2>&1 | \ 73 sed 's,^${TEST_MAKE:T}:,make:,' > ${.TARGET}.out || { \ 74 tail ${.TARGET}.out; mv ${.TARGET}.out ${.TARGET}.fail; exit 1; } 75 diff -u ${UNIT_TESTS}/${.TARGET}.exp ${.TARGET}.out 76 77 accept: 78 mv test.out ${.CURDIR}/test.exp 79 80