Makefile revision 1.8
11.8Ssjg# $Id: Makefile,v 1.8 2003/09/27 21:29:37 sjg Exp $ 21.1Ssjg# 31.1Ssjg# Unit tests for make(1) 41.1Ssjg# The main targets are: 51.1Ssjg# 61.1Ssjg# all: run all the tests 71.1Ssjg# test: run 'all', capture output and compare to expected results 81.1Ssjg# accept: move generated output to expected results 91.1Ssjg# 101.1Ssjg# Adding a test case. 111.1Ssjg# Each feature should get its own set of tests which should be hooked 121.1Ssjg# into the 'all' target. 131.1Ssjg# 141.1Ssjg 151.1Ssjg.MAIN: all 161.1Ssjg 171.7SsjgUNIT_TESTS:= ${.PARSEDIR} 181.7Ssjg 191.8Ssjgall: mod-ts varcmd modword 201.1Ssjg 211.1SsjgLIST= one two three 221.1SsjgLIST+= four five six 231.1Ssjg 241.1SsjgFU_mod-ts = a / b / cool 251.1Ssjg 261.8SsjgAAA= a a a 271.8SsjgB.aaa= Baaa 281.8Ssjg 291.1Ssjgmod-ts: 301.3Ssjg @echo 'LIST="${LIST}"' 311.3Ssjg @echo 'LIST:ts,="${LIST:ts,}"' 321.3Ssjg @echo 'LIST:ts/:tu="${LIST:ts/:tu}"' 331.8Ssjg @echo 'LIST:ts::tu="${LIST:ts::tu}"' 341.8Ssjg @echo 'LIST:ts:tu="${LIST:ts:tu}"' 351.3Ssjg @echo 'LIST:tu:ts/="${LIST:tu:ts/}"' 361.3Ssjg @echo 'LIST:ts:="${LIST:ts:}"' 371.3Ssjg @echo 'LIST:ts="${LIST:ts}"' 381.3Ssjg @echo 'LIST:ts:S/two/2/="${LIST:ts:S/two/2/}"' 391.3Ssjg @echo 'LIST:S/two/2/:ts="${LIST:S/two/2/:ts}"' 401.3Ssjg @echo 'LIST:ts/:S/two/2/="${LIST:ts/:S/two/2/}"' 411.4Ssjg @echo "Pretend the '/' in '/n' etc. below are back-slashes." 421.4Ssjg @echo 'LIST:ts/n="${LIST:ts\n}"' 431.4Ssjg @echo 'LIST:ts/t="${LIST:ts\t}"' 441.4Ssjg @echo 'LIST:ts/012:tu="${LIST:ts\012:tu}"' 451.3Ssjg @echo 'LIST:tx="${LIST:tx}"' 461.6Ssjg @echo 'LIST:ts/x:tu="${LIST:ts\x:tu}"' 471.3Ssjg @echo 'FU_$@="${FU_${@:ts}:ts}"' 481.3Ssjg @echo 'FU_$@:ts:T="${FU_${@:ts}:ts:T}" == cool?' 491.8Ssjg @echo 'B.$${AAA:ts}="${B.${AAA:ts}}" == Baaa?' 501.1Ssjg 511.8Ssjg# Some tests are best handled via a sub-make 521.8Ssjg.PHONY: varcmd modword 531.8Ssjgvarcmd modword: 541.8Ssjg @${.MAKE} -k -f ${UNIT_TESTS}/$@ 551.5Ssjg 561.1Ssjgclean: 571.1Ssjg rm -f *.out *.fail *.core 581.1Ssjg 591.1Ssjg.include <bsd.obj.mk> 601.1Ssjg 611.1SsjgTEST_MAKE?= ${MAKE} 621.1Ssjg 631.1Ssjg# here is the driver 641.1Ssjgtest: 651.1Ssjg @echo "${TEST_MAKE} -f ${MAKEFILE} > ${.TARGET}.out 2>&1" 661.6Ssjg @cd ${.OBJDIR} && ${TEST_MAKE} -f ${MAKEFILE} 2>&1 | \ 671.2Ssjg sed 's,^${TEST_MAKE:T}:,make:,' > ${.TARGET}.out || { \ 681.1Ssjg tail ${.TARGET}.out; mv ${.TARGET}.out ${.TARGET}.fail; exit 1; } 691.7Ssjg diff -u ${UNIT_TESTS}/${.TARGET}.exp ${.TARGET}.out 701.1Ssjg 711.1Ssjgaccept: 721.1Ssjg mv test.out ${.CURDIR}/test.exp 731.1Ssjg 74