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