xref: /haiku/build/jam/TestsRules (revision ca8ed5ea660fb6275799a3b7f138b201c41a667b)
1# unit test pseudo target
2NotFile unittests ;
3
4rule UnitTestLib
5{
6	# UnitTestLib <lib> : <sources> : <libraries> ;
7	#
8	local lib = $(1) ;
9	local sources = $(2) ;
10	local libraries = $(3) ;
11
12	# if TEST_DEBUG is defined, we turn on debugging
13	if $(TEST_DEBUG) {
14		DEBUG on $(lib) [ FGristFiles $(sources:S=$(SUFOBJ)) ] ?= 1 ;
15	}
16
17	# define TEST_R5/TEST_HAIKU depending on the platform we build for
18	if $(TARGET_PLATFORM) = libbe_test {
19		ObjectDefines $(2) : TEST_HAIKU TEST_OBOS ;
20
21		# make the target depend on the installed libbe libraries
22		Depends $(lib) :
23			<tests!unittests>libbe_test.so ;
24	} else {
25		ObjectDefines $(2) : TEST_HAIKU TEST_OBOS ;
26	}
27
28	UseCppUnitObjectHeaders $(sources) ;
29
30	MakeLocate $(lib) : $(TARGET_UNIT_TEST_LIB_DIR) ;
31	SharedLibrary $(lib) : $(sources) : $(libraries) libcppunit.so ;
32
33	Depends unittests : $(lib) ;
34}
35
36
37rule UnitTest
38{
39	# UnitTest <target> : <sources> : <libraries> : <resources> ;
40	#
41	local target = $(1) ;
42	local sources = $(2) ;
43	local libraries = $(3) ;
44	local resources = $(4) ;
45
46	# define TEST_R5/TEST_HAIKU depending on the platform we build for
47	if $(TARGET_PLATFORM) = libbe_test {
48		ObjectDefines $(2) : TEST_HAIKU TEST_OBOS ;
49
50		# make the target depend on the installed libbe libraries
51		Depends $(target) :
52			<tests!unittests>libbe_test.so ;
53	} else {
54		ObjectDefines $(2) : TEST_HAIKU TEST_OBOS ;
55	}
56
57	UseCppUnitObjectHeaders $(sources) ;
58
59	MakeLocate $(target) : $(TARGET_UNIT_TEST_DIR) ;
60	SimpleTest $(target) : $(sources) : $(libraries) libcppunit.so
61		: $(resources) ;
62
63	Depends unittests : $(target) ;
64}
65
66
67rule TestObjects
68{
69	# TestObjects <sources> ;
70	#
71	local sources = $(1) ;
72
73	# define TEST_R5/TEST_HAIKU depending on the platform we build for
74	if $(TARGET_PLATFORM) = libbe_test {
75		ObjectDefines $(2) : TEST_HAIKU TEST_OBOS ;
76	} else {
77		ObjectDefines $(2) : TEST_HAIKU TEST_OBOS ;
78	}
79
80	UseCppUnitObjectHeaders $(sources) ;
81
82	Objects $(sources) ;
83}
84
85
86rule SimpleTest
87{
88	# SimpleTest <target> : <sources> : [ <libraries> ] : [ <resources> ] ;
89
90	# if TEST_DEBUG is defined, we turn on debugging
91	if $(TEST_DEBUG) {
92		DEBUG on $(1) [ FGristFiles $(2:S=$(SUFOBJ)) ] ?= 1 ;
93	}
94
95	Executable $(1) : $(2) : $(3) : $(4) ;
96}
97
98
99rule BuildPlatformTest
100{
101	# Usage BuildPlatformTest <target> : <sources> ;
102	local target = $(1) ;
103	local sources = $(2) ;
104
105	local relPath ;
106	if [ FIsPrefix src tests : $(SUBDIR_TOKENS) ] {
107		relPath = $(SUBDIR_TOKENS[3-]) ;
108	} else {
109		relPath = $(SUBDIR_TOKENS[2-]) ;
110	}
111	MakeLocate $(target) : [ FDirName $(HAIKU_TEST_DIR) $(relPath) ] ;
112
113	BuildPlatformMain $(target) : $(sources) ;
114}
115