From 0d56fb946d8399fa3098e1694d69fa654bec2b7e Mon Sep 17 00:00:00 2001 From: Diadlo Date: Mon, 30 Jan 2017 23:39:52 +0300 Subject: [PATCH] chore(cmake): Add unit_test build --- CMakeLists.txt | 20 +------------------- cmake/Testing.cmake | 22 ++++++++++++++++++++++ test/common.h | 13 +++++++++++++ 3 files changed, 36 insertions(+), 19 deletions(-) create mode 100644 cmake/Testing.cmake create mode 100644 test/common.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 504398a77..83f5f4ec8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,7 +33,6 @@ set(CMAKE_OSX_SYSROOT ${CMAKE_OSX_SYSROOT}/Platforms/MacOSX.platform/Developer/SDKs/MacOSX${CMAKE_OSX_DEPLOYMENT_TARGET}.sdk) project(qtox) -include(CTest) # Instruct CMake to run moc automatically when needed. set(CMAKE_AUTOMOC ON) @@ -498,22 +497,5 @@ target_link_libraries(${PROJECT_NAME} ${PROJECT_NAME}_static ${ALL_LIBRARIES}) -################################################################################ -# -# :: Tests -# -################################################################################ - -function(auto_test subsystem module) - add_executable(${module}_test - test/${subsystem}/${module}_test.cpp) - target_link_libraries(${module}_test - ${PROJECT_NAME}_static - ${ALL_LIBRARIES} - Qt5::Test) - add_test( - NAME test_${module} - COMMAND ${module}_test) -endfunction() - +include(Testing) include(Installation) diff --git a/cmake/Testing.cmake b/cmake/Testing.cmake new file mode 100644 index 000000000..c39f6b703 --- /dev/null +++ b/cmake/Testing.cmake @@ -0,0 +1,22 @@ +################################################################################ +# +# :: Testing +# +################################################################################ + +include(CTest) + +enable_testing() + +function(auto_test subsystem module) + add_executable(test_${module} + test/common.h + test/${subsystem}/${module}_test.cpp) + target_link_libraries(test_${module} + ${PROJECT_NAME}_static + ${ALL_LIBRARIES} + Qt5::Test) + add_test( + NAME test_${module} + COMMAND test_${module}) +endfunction() diff --git a/test/common.h b/test/common.h new file mode 100644 index 000000000..1fc564dca --- /dev/null +++ b/test/common.h @@ -0,0 +1,13 @@ +#ifndef _TEST_COMMON_H_ +#define _TEST_COMMON_H_ + +#define DEFTESTCASE(NAME) \ + TCase *tc_##NAME = tcase_create(#NAME); \ + tcase_add_test(tc_##NAME, NAME##Test); \ + suite_add_tcase(s, tc_##NAME); + +#define DEFTESTCASE_SLOW(NAME, TIMEOUT) \ + DEFTESTCASE(NAME) \ + tcase_set_timeout(tc_##NAME, TIMEOUT); + +#endif // _TEST_COMMON_H_