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.
33TESTS+=		comment
34TESTS+=		cond-late
35TESTS+=		cond-short
36TESTS+=		cond1
37TESTS+=		cond2
38TESTS+=		dollar
39TESTS+=		doterror
40TESTS+=		dotwait
41TESTS+=		error
42TESTS+=		# escape	# broken by referting POSIX changes
43TESTS+=		export
44TESTS+=		export-all
45TESTS+=		export-env
46TESTS+=		forloop
47TESTS+=		forsubst
48TESTS+=		hash
49TESTS+=		# impsrc	# broken by referting POSIX changes
50TESTS+=		include-main
51TESTS+=		misc
52TESTS+=		moderrs
53TESTS+=		modmatch
54TESTS+=		modmisc
55TESTS+=		modorder
56TESTS+=		modts
57TESTS+=		modword
58TESTS+=		order
59TESTS+=		# phony-end	# broken by referting POSIX changes
60TESTS+=		posix
61TESTS+=		# posix1	# broken by referting POSIX changes
62TESTS+=		qequals
63TESTS+=		# suffixes	# broken by referting POSIX changes
64TESTS+=		sunshcmd
65TESTS+=		sysv
66TESTS+=		ternary
67TESTS+=		unexport
68TESTS+=		unexport-env
69TESTS+=		varcmd
70TESTS+=		varmisc
71TESTS+=		varmod-edge
72TESTS+=		varquote
73TESTS+=		varshell
74
75# Override make flags for certain tests; default is -k.
76FLAGS.doterror=		# none
77FLAGS.order=		-j1
78
79# Some tests need extra post-processing.
80SED_CMDS.modmisc+=	-e 's,\(substitution error:\).*,\1 (details omitted),'
81SED_CMDS.varshell+=	-e 's,^[a-z]*sh: ,,'
82SED_CMDS.varshell+=	-e '/command/s,No such.*,not found,'
83
84# End of the configuration section.
85
86.MAIN: all
87
88UNIT_TESTS:=	${.PARSEDIR}
89.PATH: ${UNIT_TESTS}
90
91OUTFILES=	${TESTS:=.out}
92
93all: ${OUTFILES}
94
95CLEANFILES+=		*.rawout *.out *.status *.tmp *.core *.tmp
96CLEANFILES+=		obj*.[och] lib*.a	# posix1.mk
97CLEANFILES+=		issue* .[ab]*		# suffixes.mk
98CLEANRECURSIVE+=	dir dummy		# posix1.mk
99
100clean:
101	rm -f ${CLEANFILES}
102.if !empty(CLEANRECURSIVE)
103	rm -rf ${CLEANRECURSIVE}
104.endif
105
106TEST_MAKE?=	${.MAKE}
107TOOL_SED?=	sed
108
109# ensure consistent results from sort(1)
110LC_ALL=		C
111LANG=		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
142test:	${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
154accept:
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