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