xref: /freebsd/share/mk/plain.test.mk (revision 8aaffd78c0f517985c12fd1e3cbceeb6c6b98ef5)
1#
2# You must include bsd.test.mk instead of this file from your Makefile.
3#
4# Logic to build and install plain test programs.  A plain test programs it not
5# supposed to use any specific testing framework: all it does is run some code
6# and report the test's pass or fail status via a 0 or 1 exit code.
7
8.if !target(__<bsd.test.mk>__)
9.error plain.test.mk cannot be included directly.
10.endif
11
12# List of C, C++ and shell test programs to build.
13#
14# Programs listed here are built according to the semantics of bsd.prog.mk for
15# PROGS, PROGS_CXX and SCRIPTS, respectively.
16#
17# Test programs registered in this manner are set to be installed into TESTSDIR
18# (which should be overridden by the Makefile) and are not required to provide a
19# manpage.
20PLAIN_TESTS_C?=
21PLAIN_TESTS_CXX?=
22PLAIN_TESTS_SH?=
23
24.if !empty(PLAIN_TESTS_C)
25PROGS+= ${PLAIN_TESTS_C}
26_TESTS+= ${PLAIN_TESTS_C}
27.for _T in ${PLAIN_TESTS_C}
28BINDIR.${_T}= ${TESTSDIR}
29MAN.${_T}?= # empty
30SRCS.${_T}?= ${_T}.c
31TEST_INTERFACE.${_T}= plain
32.endfor
33.endif
34
35.if !empty(PLAIN_TESTS_CXX)
36PROGS_CXX+= ${PLAIN_TESTS_CXX}
37_TESTS+= ${PLAIN_TESTS_CXX}
38.for _T in ${PLAIN_TESTS_CXX}
39BINDIR.${_T}= ${TESTSDIR}
40MAN.${_T}?= # empty
41SRCS.${_T}?= ${_T}.cc
42TEST_INTERFACE.${_T}= plain
43.endfor
44.endif
45
46.if !empty(PLAIN_TESTS_SH)
47SCRIPTS+= ${PLAIN_TESTS_SH}
48_TESTS+= ${PLAIN_TESTS_SH}
49.for _T in ${PLAIN_TESTS_SH}
50SCRIPTSDIR_${_T}= ${TESTSDIR}
51TEST_INTERFACE.${_T}= plain
52CLEANFILES+= ${_T} ${_T}.tmp
53# TODO(jmmv): It seems to me that this SED and SRC functionality should
54# exist in bsd.prog.mk along the support for SCRIPTS.  Move it there if
55# this proves to be useful within the tests.
56PLAIN_TESTS_SH_SED_${_T}?= # empty
57PLAIN_TESTS_SH_SRC_${_T}?= ${_T}.sh
58${_T}: ${PLAIN_TESTS_SH_SRC_${_T}}
59.if empty(PLAIN_TESTS_SH_SED_${_T})
60	cat ${.ALLSRC:N*Makefile*} >${.TARGET}.tmp
61.else
62	cat ${.ALLSRC:N*Makefile*} \
63	    | sed ${PLAIN_TESTS_SH_SED_${_T}} >${.TARGET}.tmp
64.endif
65	chmod +x ${.TARGET}.tmp
66	mv ${.TARGET}.tmp ${.TARGET}
67.endfor
68.endif
69