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