Skip to content

Commit d99f540

Browse files
committed
tests: added cmake config for unit tests
Signed-off-by: Johannes Meyer <[email protected]>
1 parent 683cbb7 commit d99f540

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,9 @@ IF ( DOXYGEN_EXECUTABLE )
166166
CONFIGURE_FILE(doc/Doxyfile.in Doxyfile @ONLY)
167167
ADD_CUSTOM_TARGET(docs ${DOXYGEN_EXECUTABLE} "Doxyfile")
168168
ENDIF ( DOXYGEN_EXECUTABLE )
169+
170+
###########################################################
171+
# TESTS
172+
###########################################################
173+
174+
add_subdirectory(tests)

tests/CMakeLists.txt

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
include(CTest)
2+
3+
# catkin compatibility
4+
if(NOT TARGET run_tests)
5+
add_custom_target(run_tests)
6+
endif()
7+
8+
if(BUILD_TESTING)
9+
set(TESTS
10+
testmain
11+
testCategory testFixedContextCategory testNDC testPattern
12+
testErrorCollision testPriority testFilter testProperties
13+
testConfig testPropertyConfig testRollingFileAppender testDailyRollingFileAppender
14+
)
15+
16+
set(DATA log4cpp.init log4cpp.properties testProperties.properties
17+
testConfig.log4cpp.properties testConfig.log4cpp.dailyroll.properties
18+
)
19+
20+
# copy test data
21+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
22+
foreach(file ${DATA})
23+
configure_file(${file} ${CMAKE_CURRENT_BINARY_DIR}/${file} COPYONLY)
24+
endforeach()
25+
26+
include_directories(
27+
${PROJECT_SOURCE_DIR}/include
28+
${PROJECT_SOURCE_DIR}/src
29+
)
30+
31+
foreach(test ${TESTS})
32+
add_executable(${test} EXCLUDE_FROM_ALL ${test}.cpp)
33+
target_link_libraries(${test} ${LOG4CPP_LIBRARY_NAME} -pthread)
34+
add_test(NAME ${test} COMMAND ${test})
35+
endforeach()
36+
37+
add_executable(testbench EXCLUDE_FROM_ALL Clock.cpp Clock.hh testbench.cpp)
38+
target_link_libraries(testbench ${LOG4CPP_LIBRARY_NAME} -pthread)
39+
add_test(NAME testbench COMMAND testbench)
40+
41+
add_custom_target(check
42+
COMMAND ctest -V
43+
DEPENDS ${TESTS} testbench
44+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
45+
)
46+
47+
add_dependencies(run_tests check)
48+
endif()

0 commit comments

Comments
 (0)