1 1.9 sjg # $Id: Makefile,v 1.9 2004/01/09 00:56:44 sjg Exp $ 2 1.1 sjg # 3 1.1 sjg # Unit tests for make(1) 4 1.1 sjg # The main targets are: 5 1.1 sjg # 6 1.1 sjg # all: run all the tests 7 1.1 sjg # test: run 'all', capture output and compare to expected results 8 1.1 sjg # accept: move generated output to expected results 9 1.1 sjg # 10 1.1 sjg # Adding a test case. 11 1.1 sjg # Each feature should get its own set of tests which should be hooked 12 1.1 sjg # into the 'all' target. 13 1.1 sjg # 14 1.1 sjg 15 1.1 sjg .MAIN: all 16 1.1 sjg 17 1.7 sjg UNIT_TESTS:= ${.PARSEDIR} 18 1.7 sjg 19 1.9 sjg all: mod-ts varcmd modword ternary 20 1.1 sjg 21 1.1 sjg LIST= one two three 22 1.1 sjg LIST+= four five six 23 1.1 sjg 24 1.1 sjg FU_mod-ts = a / b / cool 25 1.1 sjg 26 1.8 sjg AAA= a a a 27 1.8 sjg B.aaa= Baaa 28 1.8 sjg 29 1.1 sjg mod-ts: 30 1.3 sjg @echo 'LIST="${LIST}"' 31 1.3 sjg @echo 'LIST:ts,="${LIST:ts,}"' 32 1.3 sjg @echo 'LIST:ts/:tu="${LIST:ts/:tu}"' 33 1.8 sjg @echo 'LIST:ts::tu="${LIST:ts::tu}"' 34 1.8 sjg @echo 'LIST:ts:tu="${LIST:ts:tu}"' 35 1.3 sjg @echo 'LIST:tu:ts/="${LIST:tu:ts/}"' 36 1.3 sjg @echo 'LIST:ts:="${LIST:ts:}"' 37 1.3 sjg @echo 'LIST:ts="${LIST:ts}"' 38 1.3 sjg @echo 'LIST:ts:S/two/2/="${LIST:ts:S/two/2/}"' 39 1.3 sjg @echo 'LIST:S/two/2/:ts="${LIST:S/two/2/:ts}"' 40 1.3 sjg @echo 'LIST:ts/:S/two/2/="${LIST:ts/:S/two/2/}"' 41 1.4 sjg @echo "Pretend the '/' in '/n' etc. below are back-slashes." 42 1.4 sjg @echo 'LIST:ts/n="${LIST:ts\n}"' 43 1.4 sjg @echo 'LIST:ts/t="${LIST:ts\t}"' 44 1.4 sjg @echo 'LIST:ts/012:tu="${LIST:ts\012:tu}"' 45 1.3 sjg @echo 'LIST:tx="${LIST:tx}"' 46 1.6 sjg @echo 'LIST:ts/x:tu="${LIST:ts\x:tu}"' 47 1.3 sjg @echo 'FU_$@="${FU_${@:ts}:ts}"' 48 1.3 sjg @echo 'FU_$@:ts:T="${FU_${@:ts}:ts:T}" == cool?' 49 1.8 sjg @echo 'B.$${AAA:ts}="${B.${AAA:ts}}" == Baaa?' 50 1.1 sjg 51 1.8 sjg # Some tests are best handled via a sub-make 52 1.8 sjg .PHONY: varcmd modword 53 1.8 sjg varcmd modword: 54 1.8 sjg @${.MAKE} -k -f ${UNIT_TESTS}/$@ 55 1.5 sjg 56 1.9 sjg ternary: 57 1.9 sjg @${.MAKE} -k -f ${UNIT_TESTS}/$@ 58 1.9 sjg @${.MAKE} -k -f ${UNIT_TESTS}/$@ A= 59 1.9 sjg @${.MAKE} -k -f ${UNIT_TESTS}/$@ A=42 60 1.9 sjg 61 1.1 sjg clean: 62 1.1 sjg rm -f *.out *.fail *.core 63 1.1 sjg 64 1.1 sjg .include <bsd.obj.mk> 65 1.1 sjg 66 1.1 sjg TEST_MAKE?= ${MAKE} 67 1.1 sjg 68 1.1 sjg # here is the driver 69 1.1 sjg test: 70 1.1 sjg @echo "${TEST_MAKE} -f ${MAKEFILE} > ${.TARGET}.out 2>&1" 71 1.6 sjg @cd ${.OBJDIR} && ${TEST_MAKE} -f ${MAKEFILE} 2>&1 | \ 72 1.2 sjg sed 's,^${TEST_MAKE:T}:,make:,' > ${.TARGET}.out || { \ 73 1.1 sjg tail ${.TARGET}.out; mv ${.TARGET}.out ${.TARGET}.fail; exit 1; } 74 1.7 sjg diff -u ${UNIT_TESTS}/${.TARGET}.exp ${.TARGET}.out 75 1.1 sjg 76 1.1 sjg accept: 77 1.1 sjg mv test.out ${.CURDIR}/test.exp 78 1.1 sjg 79