Debian Codegraph @

tests/CMakeLists.txt

raw
1 set(CGREEN_TEST_INCLUDE_DIRS
2 ${CGREEN_PUBLIC_INCLUDE_DIRS}
3 ${CMAKE_CURRENT_BINARY_DIR}
4 )
5
6 check_include_file("sys/resource.h" HAVE_SYS_RESOURCE_H)
7 if (HAVE_SYS_RESOURCE_H)
8 add_definitions(-DHAVE_SYS_RESOURCE_H)
9 endif(HAVE_SYS_RESOURCE_H)
10
11 if (MSVC)
12 LIST(APPEND CGREEN_TEST_INCLUDE_DIRS
13 ${PROJECT_SOURCE_DIR}/include/cgreen/internal/windows_headers
14 )
15 endif(MSVC)
16
17
18 include_directories(${CGREEN_TEST_INCLUDE_DIRS})
19
20 # Dependency on our own library
21 if (CGREEN_WITH_STATIC_LIBRARY)
22 set(CGREEN_LIBRARY ${CGREEN_STATIC_LIBRARY})
23 else ()
24 set(CGREEN_LIBRARY ${CGREEN_SHARED_LIBRARY})
25 endif()
26
27
28 # C tests, library to use with runner, and a main program
29 # NOTE that some of these are "pure" unit tests which only
30 # need to work in C, since Cgreen's internal is C.
31 # Some others are actually testing user level functionality
32 # which must work both for C and C++ compiles.
33 # TODO: separate out those into separate dirs? Or just
34 # two lists of files, one which should go into C++ compilation
35 # too.
36 set(c_tests_library_SRCS
37 assertion_tests.c
38 breadcrumb_tests.c
39 cdash_reporter_tests.c
40 cgreen_value_tests.c
41 constraint_tests.c
42 cute_reporter_tests.c
43 double_tests.c
44 environment_variables_tests.c
45 message_formatting_tests.c
46 messaging_tests.c
47 mocks_tests.c
48 mocks_struct_tests.c
49 multiple_suite_tests.c
50 parameters_tests.c
51 reflective_runner_no_teardown_tests.c
52 reflective_tests.c
53 text_reporter_tests.c
54 unit_tests.c
55 vector_tests.c
56 )
57 if (CGREEN_WITH_XML)
58 LIST(APPEND c_tests_library_SRCS xml_reporter_tests.c)
59 endif (CGREEN_WITH_XML)
60 if (CGREEN_WITH_LIBXML2)
61 LIST(APPEND c_tests_library_SRCS libxml_reporter_tests.c)
62 endif (CGREEN_WITH_LIBXML2)
63 SET_SOURCE_FILES_PROPERTIES(${c_tests_library_SRCS} PROPERTIES LANGUAGE C)
64
65 set(CGREEN_C_TESTS_LIBRARY
66 cgreen_c_tests
67 CACHE INTERNAL "cgreen shared library with tests for C"
68 )
69
70 add_library(${CGREEN_C_TESTS_LIBRARY} SHARED ${c_tests_library_SRCS})
71 target_link_libraries(${CGREEN_C_TESTS_LIBRARY} ${CGREEN_LIBRARY}
72 $<$<BOOL:${CGREEN_WITH_LIBXML2}>:${LIBXML2_LIBRARIES}>)
73 include_directories($<$<BOOL:${CGREEN_WITH_LIBXML2}>:${LIBXML2_INCLUDE_DIRS}>)
74 macro_add_valgrind_test(${CGREEN_C_TESTS_LIBRARY})
75
76
77 set(c_tests_SRCS
78 all_c_tests.c
79 ${c_tests_library_SRCS}
80 )
81 SET_SOURCE_FILES_PROPERTIES(${c_tests_SRCS} PROPERTIES LANGUAGE C)
82
83 set(TEST_TARGET_LIBRARIES ${CGREEN_LIBRARY}
84 $<$<BOOL:${CGREEN_WITH_LIBXML2}>:${LIBXML2_LIBRARIES}>)
85
86 # unit test with main program runner
87 macro_add_unit_test(test_cgreen_c "${c_tests_SRCS}" "${TEST_TARGET_LIBRARIES}")
88 macro_add_test(NAME test_cgreen_c_run_named_test COMMAND test_cgreen_c integer_one_should_assert_true)
89
90 set(cgreen_runner_args)
91 if (CGREEN_WITH_XML)
92 set(cgreen_runner_args -x TEST)
93 endif (CGREEN_WITH_XML)
94
95 # run them with cgreen-runner also
96 macro_add_test(NAME runner_test_cgreen_c COMMAND cgreen-runner ${cgreen_runner_args} ./${CMAKE_SHARED_LIBRARY_PREFIX}${CGREEN_C_TESTS_LIBRARY}${CMAKE_SHARED_LIBRARY_SUFFIX})
97
98
99 # C++ tests, library to use with runner, and a main program
100 # NOTE that .cpp-versions should be links to .c-versions so we avoid duplication
101 # so we just use the same list and add the CPP-specific tests here
102 foreach(c_test_file ${c_tests_library_SRCS})
103 string(REGEX REPLACE "\\.c" ".cpp" cpp_test_file ${c_test_file})
104 list(APPEND cpp_tests_library_SRCS ${cpp_test_file})
105 endforeach()
106
107 set(cpp_tests_library_SRCS
108 ${cpp_tests_library_SRCS}
109 cpp_assertion_tests.cpp
110 )
111
112 SET_SOURCE_FILES_PROPERTIES(${cpp_tests_library_SRCS} PROPERTIES LANGUAGE CXX)
113
114 set(CGREEN_CPP_TESTS_LIBRARY
115 cgreen_cpp_tests
116 CACHE INTERNAL "cgreen shared library with tests for C++"
117 )
118 add_library(${CGREEN_CPP_TESTS_LIBRARY} SHARED ${cpp_tests_library_SRCS})
119 target_link_libraries(${CGREEN_CPP_TESTS_LIBRARY} ${CGREEN_LIBRARY} ${CMAKE_CXX_IMPLICIT_LINK_LIBRARIES})
120 macro_add_valgrind_test(${CGREEN_CPP_TESTS_LIBRARY})
121
122
123 set(cpp_tests_SRCS
124 all_cpp_tests.cpp
125 ${cpp_tests_library_SRCS}
126 )
127 SET_SOURCE_FILES_PROPERTIES(${cpp_tests_SRCS} PROPERTIES LANGUAGE CXX)
128
129 macro_add_unit_test(test_cgreen_cpp "${cpp_tests_SRCS}" "${TEST_TARGET_LIBRARIES}" ${CMAKE_CXX_IMPLICIT_LINK_LIBRARIES})
130 macro_add_test(NAME test_cgreen_cpp_run_named_test COMMAND test_cgreen_cpp different_pointers_with_same_contents_should_assert_equal)
131 macro_add_test(NAME runner_test_cgreen_cpp COMMAND cgreen-runner ${cgreen_runner_args} ./${CMAKE_SHARED_LIBRARY_PREFIX}${CGREEN_CPP_TESTS_LIBRARY}${CMAKE_SHARED_LIBRARY_SUFFIX})
132
133 # Temporary single CUT test library
134 # Maybe we should do this for all tests instead
135 # and then aggregate the DLL/so/dylibs instead...
136 # Then this might be possible to turn into a macro
137 # which could allow "add_runner_lib(text_reporter)"
138 foreach(case
139 assertion
140 breadcrumb
141 cdash_reporter
142 cgreen_value
143 constraint
144 cute_reporter
145 double
146 message_formatting
147 messaging
148 mocks
149 mocks_struct
150 parameters
151 reflective
152 reflective_runner_no_teardown
153 text_reporter
154 unit
155 vector
156 )
157 set(${case}_tests_SRCS
158 ${case}_tests.c
159 )
160 set(${case}_tests_library
161 ${case}_tests
162 )
163 add_library(${${case}_tests_library} SHARED ${${case}_tests_SRCS})
164 target_link_libraries(${${case}_tests_library} ${CGREEN_LIBRARY})
165 endforeach(case)
166 if (CGREEN_WITH_XML)
167 add_library(xml_reporter_tests SHARED xml_reporter_tests.c)
168 target_link_libraries(xml_reporter_tests ${CGREEN_LIBRARY})
169 endif (CGREEN_WITH_XML)
170 if (CGREEN_WITH_LIBXML2)
171 add_library(libxml_reporter_tests SHARED libxml_reporter_tests.c)
172 target_link_libraries(libxml_reporter_tests ${CGREEN_LIBRARY})
173 endif (CGREEN_WITH_LIBXML2)
174
175
176 # Libraries for a set of output comparing tests to run with runner
177
178 set(constraint_messages_library constraint_messages_tests)
179 set(constraint_messages_library_SRCS constraint_messages_tests.c)
180 add_library(${constraint_messages_library} SHARED ${constraint_messages_library_SRCS})
181 target_link_libraries(${constraint_messages_library} ${CGREEN_LIBRARY})
182
183 set(custom_constraint_messages_library custom_constraint_messages_tests)
184 set(custom_constraint_messages_library_SRCS custom_constraint_messages_tests.c)
185 add_library(${custom_constraint_messages_library} SHARED ${custom_constraint_messages_library_SRCS})
186 target_link_libraries(${custom_constraint_messages_library} ${CGREEN_LIBRARY})
187
188 set(mock_messages_library mock_messages_tests)
189 set(mock_messages_library_SRCS mock_messages_tests.c)
190 add_library(${mock_messages_library} SHARED ${mock_messages_library_SRCS})
191 target_link_libraries(${mock_messages_library} ${CGREEN_LIBRARY})
192
193 set(failure_messages_library failure_messages_tests)
194 set(failure_messages_library_SRCS failure_messages_tests.c)
195 add_library(${failure_messages_library} SHARED ${failure_messages_library_SRCS})
196 target_link_libraries(${failure_messages_library} ${CGREEN_LIBRARY})
197
198 set(assertion_messages_library assertion_messages_tests)
199 set(assertion_messages_library_SRCS assertion_messages_tests.c)
200 add_library(${assertion_messages_library} SHARED ${assertion_messages_library_SRCS})
201 target_link_libraries(${assertion_messages_library} ${CGREEN_LIBRARY})
202
203 set(ignore_messages_library ignore_messages_tests)
204 set(ignore_messages_library_SRCS ignore_messages_tests.c)
205 add_library(${ignore_messages_library} SHARED ${ignore_messages_library_SRCS})
206 target_link_libraries(${ignore_messages_library} ${CGREEN_LIBRARY})
207
208 if (CGREEN_WITH_XML)
209 set(xml_output_library xml_output_tests)
210 set(xml_output_library_SRCS xml_output_tests.c)
211 add_library(${xml_output_library} SHARED ${xml_output_library_SRCS})
212 target_link_libraries(${xml_output_library} ${CGREEN_LIBRARY})
213 endif (CGREEN_WITH_XML)
214
215 if (CGREEN_WITH_LIBXML2)
216 set(libxml_output_library libxml_output_tests)
217 set(libxml_output_library_SRCS libxml_output_tests.c)
218 add_library(${libxml_output_library} SHARED ${libxml_output_library_SRCS})
219 target_link_libraries(${libxml_output_library} ${CGREEN_LIBRARY})
220 endif (CGREEN_WITH_LIBXML2)
221
222 # TODO We should not add these if the cgreen-runner was not built e.g. no 'nm' available
223 macro_add_test(
224 NAME constraint_messsages
225 COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/../tools/cgreen_runner_output_diff
226 constraint_messages_tests # Name
227 ${CMAKE_CURRENT_SOURCE_DIR} # Where sources are
228 ${constraint_messages_library}.expected
229 )
230
231 macro_add_test(
232 NAME custom_constraint_messsages
233 COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/../tools/cgreen_runner_output_diff
234 custom_constraint_messages_tests # Name
235 ${CMAKE_CURRENT_SOURCE_DIR} # Where sources are
236 ${custom_constraint_messages_library}.expected
237 )
238
239 macro_add_test(
240 NAME mock_messsages
241 COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/../tools/cgreen_runner_output_diff
242 mock_messages_tests # Name
243 ${CMAKE_CURRENT_SOURCE_DIR} # Where sources are
244 ${mock_messages_library}.expected
245 )
246
247 macro_add_test(NAME failure_messages
248 COMMAND env "CGREEN_PER_TEST_TIMEOUT=2" ${CMAKE_CURRENT_SOURCE_DIR}/../tools/cgreen_runner_output_diff
249 failure_messages_tests # Name
250 ${CMAKE_CURRENT_SOURCE_DIR} # Where sources are
251 ${failure_messages_library}.expected
252 )
253
254 macro_add_test(NAME assertion_messages
255 COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/../tools/cgreen_runner_output_diff
256 assertion_messages_tests # Name
257 ${CMAKE_CURRENT_SOURCE_DIR} # Where sources are
258 ${assertion_messages_library}.expected
259 )
260
261 macro_add_test(NAME ignore_messages
262 COMMAND env "CGREEN_PER_TEST_TIMEOUT=2" ${CMAKE_CURRENT_SOURCE_DIR}/../tools/cgreen_runner_output_diff
263 ignore_messages_tests # Name
264 ${CMAKE_CURRENT_SOURCE_DIR} # Where sources are
265 ${ignore_messages_library}.expected
266 )
267
268 if (CGREEN_WITH_XML)
269 macro_add_test(NAME xml_output
270 COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/../tools/cgreen_xml_output_diff
271 xml_output_tests # Name
272 ${CMAKE_CURRENT_SOURCE_DIR} # Where sources are
273 ${xml_output_library}.expected
274 )
275 endif (CGREEN_WITH_XML)
276
277 if (CGREEN_WITH_LIBXML2)
278 macro_add_test(NAME libxml_output
279 COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/../tools/cgreen_libxml_output_diff
280 libxml_output_tests
281 ${CMAKE_CURRENT_SOURCE_DIR}
282 ${libxml_output_library}.expected
283 )
284 endif (CGREEN_WITH_LIBXML2)
285
286 # add verification that all public api is available as it should
287 add_subdirectory(api)