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