1 # $Id: Makefile,v 1.8 2003/09/27 21:29:37 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 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 clean: 57 rm -f *.out *.fail *.core 58 59 .include <bsd.obj.mk> 60 61 TEST_MAKE?= ${MAKE} 62 63 # here is the driver 64 test: 65 @echo "${TEST_MAKE} -f ${MAKEFILE} > ${.TARGET}.out 2>&1" 66 @cd ${.OBJDIR} && ${TEST_MAKE} -f ${MAKEFILE} 2>&1 | \ 67 sed 's,^${TEST_MAKE:T}:,make:,' > ${.TARGET}.out || { \ 68 tail ${.TARGET}.out; mv ${.TARGET}.out ${.TARGET}.fail; exit 1; } 69 diff -u ${UNIT_TESTS}/${.TARGET}.exp ${.TARGET}.out 70 71 accept: 72 mv test.out ${.CURDIR}/test.exp 73 74