xref: /freebsd/share/mk/tap.test.mk (revision f81cdf24ba5436367377f7c8e8f51f6df2a75ca7)
1#
2# You must include bsd.test.mk instead of this file from your Makefile.
3#
4# Logic to build and install TAP-compliant test programs.
5#
6# This is provided to support existing tests in the FreeBSD source tree
7# (particularly those coming from tools/regression/) that comply with the
8# Test Anything Protocol.  It should not be used for new tests.
9
10.if !target(__<bsd.test.mk>__)
11.error tap.test.mk cannot be included directly.
12.endif
13
14# List of C, C++ and shell test programs to build.
15#
16# Programs listed here are built according to the semantics of bsd.prog.mk for
17# PROGS, PROGS_CXX and SCRIPTS, respectively.
18#
19# Test programs registered in this manner are set to be installed into TESTSDIR
20# (which should be overridden by the Makefile) and are not required to provide a
21# manpage.
22TAP_TESTS_C?=
23TAP_TESTS_CXX?=
24TAP_TESTS_PERL?=
25TAP_TESTS_SH?=
26
27# Perl interpreter to use for test programs written in this language.
28TAP_PERL_INTERPRETER?=	${LOCALBASE}/bin/perl
29
30.if !empty(TAP_TESTS_C)
31PROGS+= ${TAP_TESTS_C}
32_TESTS+= ${TAP_TESTS_C}
33.for _T in ${TAP_TESTS_C}
34BINDIR.${_T}= ${TESTSDIR}
35MAN.${_T}?= # empty
36SRCS.${_T}?= ${_T}.c
37TEST_INTERFACE.${_T}= tap
38.endfor
39.endif
40
41.if !empty(TAP_TESTS_CXX)
42PROGS_CXX+= ${TAP_TESTS_CXX}
43_TESTS+= ${TAP_TESTS_CXX}
44.for _T in ${TAP_TESTS_CXX}
45BINDIR.${_T}= ${TESTSDIR}
46MAN.${_T}?= # empty
47SRCS.${_T}?= ${_T}.cc
48TEST_INTERFACE.${_T}= tap
49.endfor
50.endif
51
52.if !empty(TAP_TESTS_PERL)
53SCRIPTS+= ${TAP_TESTS_PERL}
54_TESTS+= ${TAP_TESTS_PERL}
55.for _T in ${TAP_TESTS_PERL}
56SCRIPTSDIR_${_T}= ${TESTSDIR}
57TEST_INTERFACE.${_T}= tap
58TEST_METADATA.${_T}+= required_programs="${TAP_PERL_INTERPRETER}"
59CLEANFILES+= ${_T} ${_T}.tmp
60# TODO(jmmv): It seems to me that this SED and SRC functionality should
61# exist in bsd.prog.mk along the support for SCRIPTS.  Move it there if
62# this proves to be useful within the tests.
63TAP_TESTS_PERL_SED_${_T}?= # empty
64TAP_TESTS_PERL_SRC_${_T}?= ${_T}.pl
65${_T}: ${TAP_TESTS_PERL_SRC_${_T}}
66	{ \
67	    echo '#! ${TAP_PERL_INTERPRETER}'; \
68	    cat ${.ALLSRC:N*Makefile*} | sed ${TAP_TESTS_PERL_SED_${_T}}; \
69	} >${.TARGET}.tmp
70	chmod +x ${.TARGET}.tmp
71	mv ${.TARGET}.tmp ${.TARGET}
72.endfor
73.endif
74
75.if !empty(TAP_TESTS_SH)
76SCRIPTS+= ${TAP_TESTS_SH}
77_TESTS+= ${TAP_TESTS_SH}
78.for _T in ${TAP_TESTS_SH}
79SCRIPTSDIR_${_T}= ${TESTSDIR}
80TEST_INTERFACE.${_T}= tap
81CLEANFILES+= ${_T} ${_T}.tmp
82# TODO(jmmv): It seems to me that this SED and SRC functionality should
83# exist in bsd.prog.mk along the support for SCRIPTS.  Move it there if
84# this proves to be useful within the tests.
85TAP_TESTS_SH_SED_${_T}?= # empty
86TAP_TESTS_SH_SRC_${_T}?= ${_T}.sh
87${_T}: ${TAP_TESTS_SH_SRC_${_T}}
88.if empty(TAP_TESTS_SH_SED_${_T})
89	cat ${.ALLSRC} >${.TARGET}.tmp
90.else
91	cat ${.ALLSRC} | sed ${TAP_TESTS_SH_SED_${_T}} >${.TARGET}.tmp
92.endif
93	chmod +x ${.TARGET}.tmp
94	mv ${.TARGET}.tmp ${.TARGET}
95.endfor
96.endif
97