Home | History | Annotate | Line # | Download | only in unit-tests
Makefile revision 1.64
      1 # $NetBSD: Makefile,v 1.64 2020/07/25 21:19:29 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+=		envfirst
     42 TESTS+=		error
     43 TESTS+=		# escape	# broken by reverting POSIX changes
     44 TESTS+=		export
     45 TESTS+=		export-all
     46 TESTS+=		export-env
     47 TESTS+=		forloop
     48 TESTS+=		forsubst
     49 TESTS+=		hash
     50 TESTS+=		# impsrc	# broken by reverting POSIX changes
     51 TESTS+=		include-main
     52 TESTS+=		misc
     53 TESTS+=		moderrs
     54 TESTS+=		modmatch
     55 TESTS+=		modmisc
     56 TESTS+=		modorder
     57 TESTS+=		modts
     58 TESTS+=		modword
     59 TESTS+=		order
     60 TESTS+=		# phony-end	# broken by reverting POSIX changes
     61 TESTS+=		posix
     62 TESTS+=		# posix1	# broken by reverting POSIX changes
     63 TESTS+=		qequals
     64 TESTS+=		# suffixes	# broken by reverting POSIX changes
     65 TESTS+=		sunshcmd
     66 TESTS+=		sysv
     67 TESTS+=		ternary
     68 TESTS+=		unexport
     69 TESTS+=		unexport-env
     70 TESTS+=		varcmd
     71 TESTS+=		vardebug
     72 TESTS+=		varfind
     73 TESTS+=		varmisc
     74 TESTS+=		varmod-edge
     75 TESTS+=		varquote
     76 TESTS+=		varshell
     77 
     78 # Override environment variables for some of the tests.
     79 ENV.envfirst=		FROM_ENV=value-from-env
     80 
     81 # Override make flags for some of the tests; default is -k.
     82 FLAGS.doterror=		# none
     83 FLAGS.order=		-j1
     84 FLAGS.envfirst=		-e
     85 FLAGS.vardebug=		-k -dv FROM_CMDLINE=
     86 
     87 # Some tests need extra post-processing.
     88 SED_CMDS.modmisc+=	-e 's,\(substitution error:\).*,\1 (details omitted),'
     89 SED_CMDS.varshell+=	-e 's,^[a-z]*sh: ,,'
     90 SED_CMDS.varshell+=	-e '/command/s,No such.*,not found,'
     91 
     92 # Some tests need an additional round of postprocessing.
     93 POSTPROC.vardebug=	${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p'
     94 
     95 # End of the configuration section.
     96 
     97 .MAIN: all
     98 
     99 UNIT_TESTS:=	${.PARSEDIR}
    100 .PATH: ${UNIT_TESTS}
    101 
    102 OUTFILES=	${TESTS:=.out}
    103 
    104 all: ${OUTFILES}
    105 
    106 CLEANFILES+=		*.rawout *.out *.status *.tmp *.core *.tmp
    107 CLEANFILES+=		obj*.[och] lib*.a	# posix1.mk
    108 CLEANFILES+=		issue* .[ab]*		# suffixes.mk
    109 CLEANRECURSIVE+=	dir dummy		# posix1.mk
    110 
    111 clean:
    112 	rm -f ${CLEANFILES}
    113 .if !empty(CLEANRECURSIVE)
    114 	rm -rf ${CLEANRECURSIVE}
    115 .endif
    116 
    117 TEST_MAKE?=	${.MAKE}
    118 TOOL_SED?=	sed
    119 
    120 # ensure consistent results from sort(1)
    121 LC_ALL=		C
    122 LANG=		C
    123 .export LANG LC_ALL
    124 
    125 # the tests are actually done with sub-makes.
    126 .SUFFIXES: .mk .rawout .out
    127 .mk.rawout:
    128 	@echo testing ${.IMPSRC}
    129 	@set -eu; \
    130 	cd ${.OBJDIR}; \
    131 	${ENV.${.TARGET:R}} ${TEST_MAKE} \
    132 	  ${FLAGS.${.TARGET:R}:U-k} -f ${.IMPSRC} \
    133 	  > ${.TARGET}.tmp 2>&1 \
    134 	&& status=$$? || status=$$?; \
    135 	echo $$status > ${.TARGET:R}.status
    136 	@mv ${.TARGET}.tmp ${.TARGET}
    137 
    138 # Post-process the test output so that the results can be compared.
    139 #
    140 # always pretend .MAKE was called 'make'
    141 _SED_CMDS+=	-e 's,^${TEST_MAKE:T:S,.,\\.,g}[][0-9]*:,make:,'
    142 _SED_CMDS+=	-e 's,${TEST_MAKE:S,.,\\.,g},make,'
    143 # replace anything after 'stopped in' with unit-tests
    144 _SED_CMDS+=	-e '/stopped/s, /.*, unit-tests,'
    145 # strip ${.CURDIR}/ from the output
    146 _SED_CMDS+=	-e 's,${.CURDIR:S,.,\\.,g}/,,g'
    147 _SED_CMDS+=	-e 's,${UNIT_TESTS:S,.,\\.,g}/,,g'
    148 
    149 .rawout.out:
    150 	@echo postprocess ${.TARGET}
    151 	@${TOOL_SED} ${_SED_CMDS} ${SED_CMDS.${.TARGET:R}} \
    152 	  < ${.IMPSRC} > ${.TARGET}.tmp1
    153 	@${POSTPROC.${.TARGET:R}:U${TOOL_SED}} < ${.TARGET}.tmp1 > ${.TARGET}.tmp2
    154 	@rm ${.TARGET}.tmp1
    155 	@echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp2
    156 	@mv ${.TARGET}.tmp2 ${.TARGET}
    157 
    158 # Compare all output files
    159 test:	${OUTFILES} .PHONY
    160 	@failed= ; \
    161 	for test in ${TESTS}; do \
    162 	  diff -u ${UNIT_TESTS}/$${test}.exp $${test}.out \
    163 	  || failed="$${failed}$${failed:+ }$${test}" ; \
    164 	done ; \
    165 	if [ -n "$${failed}" ]; then \
    166 	  echo "Failed tests: $${failed}" ; false ; \
    167 	else \
    168 	  echo "All tests passed" ; \
    169 	fi
    170 
    171 accept:
    172 	@for test in ${TESTS}; do \
    173 	  cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \
    174 	  || { echo "Replacing $${test}.exp" ; \
    175 	       cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \
    176 	done
    177 
    178 .if exists(${TEST_MAKE})
    179 ${TESTS:=.rawout}: ${TEST_MAKE}
    180 .endif
    181 
    182 .-include <bsd.obj.mk>
    183