Home | History | Annotate | Line # | Download | only in unit-tests
Makefile revision 1.39
      1  1.39     apb # $NetBSD: Makefile,v 1.39 2014/08/20 08:39:14 apb 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.11     sjg # Each feature should get its own set of tests in its own suitably
     12  1.11     sjg # named makefile which should be added to SUBFILES to hook it in.
     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.11     sjg # Simple sub-makefiles - we run them as a black box
     20  1.11     sjg # keep the list sorted.
     21  1.11     sjg SUBFILES= \
     22  1.16  rpaulo 	comment \
     23  1.12     sjg 	cond1 \
     24  1.26     sjg 	error \
     25  1.21     sjg 	export \
     26  1.21     sjg 	export-all \
     27  1.36     sjg 	export-env \
     28  1.26     sjg 	doterror \
     29  1.19     apb 	dotwait \
     30  1.34     sjg 	forloop \
     31  1.24     sjg 	forsubst \
     32  1.32   joerg 	hash \
     33  1.31     sjg 	misc \
     34  1.20     sjg 	moderrs \
     35  1.11     sjg 	modmatch \
     36  1.18     sjg 	modmisc \
     37  1.15     sjg 	modorder \
     38  1.11     sjg 	modts \
     39  1.11     sjg 	modword \
     40  1.35     sjg 	order \
     41  1.33     sjg 	phony-end \
     42  1.13     sjg 	posix \
     43  1.22     sjg 	qequals \
     44  1.38     sjg 	sunshcmd \
     45  1.31     sjg 	sysv \
     46  1.11     sjg 	ternary \
     47  1.25     sjg 	unexport \
     48  1.25     sjg 	unexport-env \
     49  1.39     apb 	varcmd \
     50  1.39     apb 	varshell
     51  1.11     sjg 
     52  1.11     sjg all: ${SUBFILES}
     53  1.11     sjg 
     54  1.26     sjg flags.doterror=
     55  1.35     sjg flags.order=-j1
     56  1.26     sjg 
     57  1.11     sjg # the tests are actually done with sub-makes.
     58  1.11     sjg .PHONY: ${SUBFILES}
     59  1.19     apb .PRECIOUS: ${SUBFILES}
     60  1.11     sjg ${SUBFILES}:
     61  1.26     sjg 	-@${.MAKE} ${flags.$@:U-k} -f ${UNIT_TESTS}/$@
     62   1.9     sjg 
     63   1.1     sjg clean:
     64   1.1     sjg 	rm -f *.out *.fail *.core
     65   1.1     sjg 
     66  1.27     sjg .-include <bsd.obj.mk>
     67   1.1     sjg 
     68  1.15     sjg TEST_MAKE?= ${.MAKE}
     69  1.27     sjg TOOL_SED?= sed
     70   1.1     sjg 
     71  1.28     sjg # ensure consistent results from sort(1)
     72  1.30     sjg LC_ALL= C
     73  1.28     sjg LANG= C
     74  1.29     sjg .export LANG LC_ALL
     75  1.28     sjg 
     76  1.11     sjg # The driver.
     77  1.12     sjg # We always pretend .MAKE was called 'make' 
     78  1.12     sjg # and strip ${.CURDIR}/ from the output
     79  1.13     sjg # and replace anything after 'stopped in' with unit-tests
     80  1.12     sjg # so the results can be compared.
     81   1.1     sjg test:
     82   1.1     sjg 	@echo "${TEST_MAKE} -f ${MAKEFILE} > ${.TARGET}.out 2>&1"
     83   1.6     sjg 	@cd ${.OBJDIR} && ${TEST_MAKE} -f ${MAKEFILE} 2>&1 | \
     84  1.37     sjg 	${TOOL_SED} -e 's,^${TEST_MAKE:T:C/\./\\\./g}[^:]*:,make:,' \
     85  1.13     sjg 	-e '/stopped/s, /.*, unit-tests,' \
     86  1.17     apb 	-e 's,${.CURDIR:C/\./\\\./g}/,,g' \
     87  1.17     apb 	-e 's,${UNIT_TESTS:C/\./\\\./g}/,,g' > ${.TARGET}.out || { \
     88   1.1     sjg 	tail ${.TARGET}.out; mv ${.TARGET}.out ${.TARGET}.fail; exit 1; }
     89   1.7     sjg 	diff -u ${UNIT_TESTS}/${.TARGET}.exp ${.TARGET}.out
     90   1.1     sjg 
     91   1.1     sjg accept:
     92   1.1     sjg 	mv test.out ${.CURDIR}/test.exp
     93   1.1     sjg 
     94