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