Home | History | Annotate | Line # | Download | only in unit-tests
Makefile revision 1.52
      1  1.52     sjg # $NetBSD: Makefile,v 1.52 2015/05/05 21:51:09 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.42     apb # test:	run 'all', 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.42     apb # named makefile (*.mk), with its own set of expected results (*.exp),
     13  1.42     apb # and it should be added to the TESTNAMES list.
     14   1.1     sjg # 
     15   1.1     sjg 
     16   1.1     sjg .MAIN: all
     17   1.1     sjg 
     18   1.7     sjg UNIT_TESTS:= ${.PARSEDIR}
     19  1.44     apb .PATH: ${UNIT_TESTS}
     20   1.7     sjg 
     21  1.42     apb # Each test is in a sub-makefile.
     22  1.42     apb # Keep the list sorted.
     23  1.42     apb TESTNAMES= \
     24  1.16  rpaulo 	comment \
     25  1.12     sjg 	cond1 \
     26  1.52     sjg 	cond2 \
     27  1.26     sjg 	error \
     28  1.21     sjg 	export \
     29  1.21     sjg 	export-all \
     30  1.36     sjg 	export-env \
     31  1.26     sjg 	doterror \
     32  1.19     apb 	dotwait \
     33  1.34     sjg 	forloop \
     34  1.24     sjg 	forsubst \
     35  1.32   joerg 	hash \
     36  1.31     sjg 	misc \
     37  1.20     sjg 	moderrs \
     38  1.11     sjg 	modmatch \
     39  1.18     sjg 	modmisc \
     40  1.15     sjg 	modorder \
     41  1.11     sjg 	modts \
     42  1.11     sjg 	modword \
     43  1.35     sjg 	order \
     44  1.13     sjg 	posix \
     45  1.22     sjg 	qequals \
     46  1.38     sjg 	sunshcmd \
     47  1.31     sjg 	sysv \
     48  1.11     sjg 	ternary \
     49  1.25     sjg 	unexport \
     50  1.25     sjg 	unexport-env \
     51  1.39     apb 	varcmd \
     52  1.43     apb 	varmisc \
     53  1.39     apb 	varshell
     54  1.11     sjg 
     55  1.51     sjg # these tests were broken by referting POSIX chanegs
     56  1.51     sjg STRICT_POSIX_TESTS = \
     57  1.51     sjg 	escape \
     58  1.51     sjg 	impsrc \
     59  1.51     sjg 	phony-end \
     60  1.51     sjg 	posix1 \
     61  1.51     sjg 	suffixes
     62  1.51     sjg 
     63  1.42     apb # Override make flags for certain tests
     64  1.26     sjg flags.doterror=
     65  1.35     sjg flags.order=-j1
     66  1.26     sjg 
     67  1.42     apb OUTFILES= ${TESTNAMES:S/$/.out/}
     68  1.42     apb 
     69  1.42     apb all: ${OUTFILES}
     70   1.9     sjg 
     71  1.48     apb CLEANFILES += *.rawout *.out *.status *.tmp *.core *.tmp
     72  1.48     apb CLEANFILES += obj*.[och] lib*.a		# posix1.mk
     73  1.49     sjg CLEANFILES += issue* .[ab]*		# suffixes.mk
     74  1.48     apb CLEANRECURSIVE += dir dummy		# posix1.mk
     75  1.48     apb 
     76   1.1     sjg clean:
     77  1.48     apb 	rm -f ${CLEANFILES}
     78  1.48     apb .if !empty(CLEANRECURSIVE)
     79  1.48     apb 	rm -rf ${CLEANRECURSIVE}
     80  1.48     apb .endif
     81   1.1     sjg 
     82  1.15     sjg TEST_MAKE?= ${.MAKE}
     83  1.27     sjg TOOL_SED?= sed
     84   1.1     sjg 
     85  1.28     sjg # ensure consistent results from sort(1)
     86  1.30     sjg LC_ALL= C
     87  1.28     sjg LANG= C
     88  1.29     sjg .export LANG LC_ALL
     89  1.28     sjg 
     90  1.42     apb # the tests are actually done with sub-makes.
     91  1.42     apb .SUFFIXES: .mk .rawout .out
     92  1.42     apb .mk.rawout:
     93  1.42     apb 	@echo ${TEST_MAKE} ${flags.${.TARGET:R}:U-k} -f ${.IMPSRC}
     94  1.42     apb 	-@cd ${.OBJDIR} && \
     95  1.42     apb 	{ ${TEST_MAKE} ${flags.${.TARGET:R}:U-k} -f ${.IMPSRC} \
     96  1.42     apb 	  2>&1 ; echo $$? >${.TARGET:R}.status ; } > ${.TARGET}.tmp
     97  1.42     apb 	@mv ${.TARGET}.tmp ${.TARGET}
     98  1.42     apb 
     99  1.12     sjg # We always pretend .MAKE was called 'make' 
    100  1.12     sjg # and strip ${.CURDIR}/ from the output
    101  1.13     sjg # and replace anything after 'stopped in' with unit-tests
    102  1.12     sjg # so the results can be compared.
    103  1.42     apb .rawout.out:
    104  1.42     apb 	@echo postprocess ${.TARGET}
    105  1.42     apb 	@${TOOL_SED} -e 's,^${TEST_MAKE:T:C/\./\\\./g}[][0-9]*:,make:,' \
    106  1.42     apb 	  -e 's,${TEST_MAKE:C/\./\\\./g},make,' \
    107  1.42     apb 	  -e '/stopped/s, /.*, unit-tests,' \
    108  1.42     apb 	  -e 's,${.CURDIR:C/\./\\\./g}/,,g' \
    109  1.42     apb 	  -e 's,${UNIT_TESTS:C/\./\\\./g}/,,g' \
    110  1.42     apb 	  < ${.IMPSRC} > ${.TARGET}.tmp
    111  1.42     apb 	@echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp
    112  1.42     apb 	@mv ${.TARGET}.tmp ${.TARGET}
    113  1.42     apb 
    114  1.42     apb # Compare all output files
    115  1.42     apb test:	${OUTFILES} .PHONY
    116  1.42     apb 	@failed= ; \
    117  1.42     apb 	for test in ${TESTNAMES}; do \
    118  1.42     apb 	  diff -u ${UNIT_TESTS}/$${test}.exp $${test}.out \
    119  1.42     apb 	  || failed="$${failed}$${failed:+ }$${test}" ; \
    120  1.42     apb 	done ; \
    121  1.42     apb 	if [ -n "$${failed}" ]; then \
    122  1.42     apb 	  echo "Failed tests: $${failed}" ; false ; \
    123  1.42     apb 	else \
    124  1.42     apb 	  echo "All tests passed" ; \
    125  1.42     apb 	fi
    126   1.1     sjg 
    127   1.1     sjg accept:
    128  1.42     apb 	@for test in ${TESTNAMES}; do \
    129  1.42     apb 	  cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \
    130  1.42     apb 	  || { echo "Replacing $${test}.exp" ; \
    131  1.42     apb 	       cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \
    132  1.42     apb 	done
    133   1.1     sjg 
    134  1.50     sjg .if exists(${TEST_MAKE})
    135  1.50     sjg ${TESTNAMES:S/$/.rawout/}: ${TEST_MAKE}
    136  1.50     sjg .endif
    137  1.50     sjg 
    138  1.42     apb .-include <bsd.obj.mk>
    139