Home | History | Annotate | Line # | Download | only in unit-tests
Makefile revision 1.62
      1 # $NetBSD: Makefile,v 1.62 2020/07/04 22:17:09 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.modmisc+=	-e 's,\(substitution error:\).*,\1 (details omitted),'
     81 SED_CMDS.varshell+=	-e 's,^[a-z]*sh: ,,'
     82 SED_CMDS.varshell+=	-e '/command/s,No such.*,not found,'
     83 
     84 # End of the configuration section.
     85 
     86 .MAIN: all
     87 
     88 UNIT_TESTS:=	${.PARSEDIR}
     89 .PATH: ${UNIT_TESTS}
     90 
     91 OUTFILES=	${TESTS:=.out}
     92 
     93 all: ${OUTFILES}
     94 
     95 CLEANFILES+=		*.rawout *.out *.status *.tmp *.core *.tmp
     96 CLEANFILES+=		obj*.[och] lib*.a	# posix1.mk
     97 CLEANFILES+=		issue* .[ab]*		# suffixes.mk
     98 CLEANRECURSIVE+=	dir dummy		# posix1.mk
     99 
    100 clean:
    101 	rm -f ${CLEANFILES}
    102 .if !empty(CLEANRECURSIVE)
    103 	rm -rf ${CLEANRECURSIVE}
    104 .endif
    105 
    106 TEST_MAKE?=	${.MAKE}
    107 TOOL_SED?=	sed
    108 
    109 # ensure consistent results from sort(1)
    110 LC_ALL=		C
    111 LANG=		C
    112 .export LANG LC_ALL
    113 
    114 # the tests are actually done with sub-makes.
    115 .SUFFIXES: .mk .rawout .out
    116 .mk.rawout:
    117 	@echo ${TEST_MAKE} ${FLAGS.${.TARGET:R}:U-k} -f ${.IMPSRC}
    118 	-@cd ${.OBJDIR} && \
    119 	{ ${TEST_MAKE} ${FLAGS.${.TARGET:R}:U-k} -f ${.IMPSRC} \
    120 	  2>&1 ; echo $$? >${.TARGET:R}.status ; } > ${.TARGET}.tmp
    121 	@mv ${.TARGET}.tmp ${.TARGET}
    122 
    123 # Post-process the test output so that the results can be compared.
    124 #
    125 # always pretend .MAKE was called 'make'
    126 _SED_CMDS+=	-e 's,^${TEST_MAKE:T:S,.,\\.,g}[][0-9]*:,make:,'
    127 _SED_CMDS+=	-e 's,${TEST_MAKE:S,.,\\.,g},make,'
    128 # replace anything after 'stopped in' with unit-tests
    129 _SED_CMDS+=	-e '/stopped/s, /.*, unit-tests,'
    130 # strip ${.CURDIR}/ from the output
    131 _SED_CMDS+=	-e 's,${.CURDIR:S,.,\\.,g}/,,g'
    132 _SED_CMDS+=	-e 's,${UNIT_TESTS:S,.,\\.,g}/,,g'
    133 
    134 .rawout.out:
    135 	@echo postprocess ${.TARGET}
    136 	@${TOOL_SED} ${_SED_CMDS} ${SED_CMDS.${.TARGET:R}} \
    137 	  < ${.IMPSRC} > ${.TARGET}.tmp
    138 	@echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp
    139 	@mv ${.TARGET}.tmp ${.TARGET}
    140 
    141 # Compare all output files
    142 test:	${OUTFILES} .PHONY
    143 	@failed= ; \
    144 	for test in ${TESTS}; do \
    145 	  diff -u ${UNIT_TESTS}/$${test}.exp $${test}.out \
    146 	  || failed="$${failed}$${failed:+ }$${test}" ; \
    147 	done ; \
    148 	if [ -n "$${failed}" ]; then \
    149 	  echo "Failed tests: $${failed}" ; false ; \
    150 	else \
    151 	  echo "All tests passed" ; \
    152 	fi
    153 
    154 accept:
    155 	@for test in ${TESTS}; do \
    156 	  cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \
    157 	  || { echo "Replacing $${test}.exp" ; \
    158 	       cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \
    159 	done
    160 
    161 .if exists(${TEST_MAKE})
    162 ${TESTS:=.rawout}: ${TEST_MAKE}
    163 .endif
    164 
    165 .-include <bsd.obj.mk>
    166