TestsRules revision 8c54af56
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
36rule UnitTest
37{
38	# UnitTest <target> : <sources> : <libraries> : <resources> ;
39	#
40	local target = $(1) ;
41	local sources = $(2) ;
42	local libraries = $(3) ;
43	local resources = $(4) ;
44
45	# define TEST_R5/TEST_HAIKU depending on the platform we build for
46	if $(TARGET_PLATFORM) = libbe_test {
47		ObjectDefines $(2) : TEST_HAIKU TEST_OBOS ;
48
49		# make the target depend on the installed libbe libraries
50		Depends $(target) :
51			 <tests!unittests>libbe_test.so ;
52	} else {
53		ObjectDefines $(2) : TEST_HAIKU TEST_OBOS ;
54	}
55
56	UseCppUnitObjectHeaders $(sources) ;
57
58	MakeLocate $(target) : $(TARGET_UNIT_TEST_DIR) ;
59	SimpleTest $(target) : $(sources) : $(libraries) libcppunit.so
60		: $(resources) ;
61
62	Depends unittests : $(lib) ;
63}
64
65rule TestObjects
66{
67	# TestObjects <sources> ;
68	#
69	local sources = $(1) ;
70
71	# define TEST_R5/TEST_HAIKU depending on the platform we build for
72	if $(TARGET_PLATFORM) = libbe_test {
73		ObjectDefines $(2) : TEST_HAIKU TEST_OBOS ;
74	} else {
75		ObjectDefines $(2) : TEST_HAIKU TEST_OBOS ;
76	}
77
78	UseCppUnitObjectHeaders $(sources) ;
79
80	Objects $(sources) ;
81}
82
83rule SimpleTest
84{
85	# SimpleTest <target> : <sources> : [ <libraries> ] : [ <resources> ] ;
86
87	# if TEST_DEBUG is defined, we turn on debugging
88	if $(TEST_DEBUG) {
89		DEBUG on $(1) [ FGristFiles $(2:S=$(SUFOBJ)) ] ?= 1 ;
90	}
91
92	Executable $(1) : $(2) : $(3) : $(4) ;
93}
94
95rule BuildPlatformTest
96{
97	# Usage BuildPlatformTest <target> : <sources> ;
98	local target = $(1) ;
99	local sources = $(2) ;
100
101	local relPath ;
102	if [ FIsPrefix src tests : $(SUBDIR_TOKENS) ] {
103		relPath = $(SUBDIR_TOKENS[3-]) ;
104	} else {
105		relPath = $(SUBDIR_TOKENS[2-]) ;
106	}
107	MakeLocate $(target) : [ FDirName $(HAIKU_TEST_DIR) $(relPath) ] ;
108
109	BuildPlatformMain $(target) : $(sources) ;
110}
111