1 # $Id: Makefile,v 1.7 2003/08/08 06:42:38 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 20 21 LIST= one two three 22 LIST+= four five six 23 24 FU_mod-ts = a / b / cool 25 26 mod-ts: 27 @echo 'LIST="${LIST}"' 28 @echo 'LIST:ts,="${LIST:ts,}"' 29 @echo 'LIST:ts/:tu="${LIST:ts/:tu}"' 30 @echo 'LIST:tu:ts/="${LIST:tu:ts/}"' 31 @echo 'LIST:ts:="${LIST:ts:}"' 32 @echo 'LIST:ts="${LIST:ts}"' 33 @echo 'LIST:ts:S/two/2/="${LIST:ts:S/two/2/}"' 34 @echo 'LIST:S/two/2/:ts="${LIST:S/two/2/:ts}"' 35 @echo 'LIST:ts/:S/two/2/="${LIST:ts/:S/two/2/}"' 36 @echo "Pretend the '/' in '/n' etc. below are back-slashes." 37 @echo 'LIST:ts/n="${LIST:ts\n}"' 38 @echo 'LIST:ts/t="${LIST:ts\t}"' 39 @echo 'LIST:ts/012:tu="${LIST:ts\012:tu}"' 40 @echo 'LIST:tx="${LIST:tx}"' 41 @echo 'LIST:ts/x:tu="${LIST:ts\x:tu}"' 42 @echo 'FU_$@="${FU_${@:ts}:ts}"' 43 @echo 'FU_$@:ts:T="${FU_${@:ts}:ts:T}" == cool?' 44 45 .PHONY: varcmd 46 varcmd: 47 @${.MAKE} -f ${UNIT_TESTS}/varcmd 48 49 clean: 50 rm -f *.out *.fail *.core 51 52 .include <bsd.obj.mk> 53 54 TEST_MAKE?= ${MAKE} 55 56 # here is the driver 57 test: 58 @echo "${TEST_MAKE} -f ${MAKEFILE} > ${.TARGET}.out 2>&1" 59 @cd ${.OBJDIR} && ${TEST_MAKE} -f ${MAKEFILE} 2>&1 | \ 60 sed 's,^${TEST_MAKE:T}:,make:,' > ${.TARGET}.out || { \ 61 tail ${.TARGET}.out; mv ${.TARGET}.out ${.TARGET}.fail; exit 1; } 62 diff -u ${UNIT_TESTS}/${.TARGET}.exp ${.TARGET}.out 63 64 accept: 65 mv test.out ${.CURDIR}/test.exp 66 67