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