From c647e933c00f1e24cbc276a8f743675ce7652a83 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Sat, 28 Oct 2017 22:15:49 +0200 Subject: [PATCH] enable 'make check' with cmake --- CMakeLists.txt | 8 +++++ platforms/packaging/bareos.spec | 3 +- src/findlib/CMakeLists.txt | 2 ++ src/findlib/unittests/CMakeLists.txt | 40 +++++++++++++++++++++ src/lib/CMakeLists.txt | 4 +++ src/lib/unittests/CMakeLists.txt | 53 ++++++++++++++++++++++++++++ 6 files changed, 108 insertions(+), 2 deletions(-) create mode 100644 src/findlib/unittests/CMakeLists.txt create mode 100644 src/lib/unittests/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 5042cdc2159..5ddefbf1253 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,6 +30,14 @@ SET(host ${CMAKE_SYSTEM}) SET(CMAKE_EXPORT_COMPILE_COMMANDS ON) + + +# enable "make check" +enable_testing() +set(CMAKE_CTEST_COMMAND ctest -V) +add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND}) + + # run git-info to collect sourcecode info file(MAKE_DIRECTORY build) execute_process( diff --git a/platforms/packaging/bareos.spec b/platforms/packaging/bareos.spec index eb0a9532603..13fe559496e 100644 --- a/platforms/packaging/bareos.spec +++ b/platforms/packaging/bareos.spec @@ -782,8 +782,7 @@ make DESTDIR=%{buildroot} %check # run unit tests -# todo with cmake, does not work right now -#%__make CFLAGS="$RPM_OPT_FLAGS" CXXFLAGS="$RPM_OPT_FLAGS" %{?_smp_mflags} check; +make check; %install ##if 0#{?suse_version} diff --git a/src/findlib/CMakeLists.txt b/src/findlib/CMakeLists.txt index f02a59b049b..f8f2e6d69e9 100644 --- a/src/findlib/CMakeLists.txt +++ b/src/findlib/CMakeLists.txt @@ -31,3 +31,5 @@ INSTALL(TARGETS bareosfind DESTINATION ${libdir}) set_target_properties(bareosfind PROPERTIES VERSION "${VERSION}" SOVERSION "${SOVERSION}" ) + +add_subdirectory(unittests EXCLUDE_FROM_ALL) diff --git a/src/findlib/unittests/CMakeLists.txt b/src/findlib/unittests/CMakeLists.txt new file mode 100644 index 00000000000..ff6e409d530 --- /dev/null +++ b/src/findlib/unittests/CMakeLists.txt @@ -0,0 +1,40 @@ +# BAREOS�� - Backup Archiving REcovery Open Sourced +# +# Copyright (C) 2017-2017 Bareos GmbH & Co. KG +# +# This program is Free Software; you can redistribute it and/or +# modify it under the terms of version three of the GNU Affero General Public +# License as published by the Free Software Foundation and included +# in the file LICENSE. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA. + +include_directories(.. ../.. ../../include/) + +set (TEST_SRC + drivetype_test.cc + fstype_test.cc + test_findlib.cc + ) + + +add_executable(test_findlib + ${TEST_SRC} + ) +target_link_libraries(test_findlib + bareos bareosfind + ${JANSSON_LIBRARIES} + ${CMOCKA_LIBRARIES} + ) + +add_test(NAME test_findlib + COMMAND test_findlib) +add_dependencies(check test_findlib) diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index c8187c97a9f..a573cb7c735 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -78,3 +78,7 @@ set_target_properties(bareos PROPERTIES VERSION "${VERSION}" ) INSTALL(FILES ${INCLUDE_FILES} DESTINATION ${includedir}) + + + +add_subdirectory(unittests EXCLUDE_FROM_ALL) diff --git a/src/lib/unittests/CMakeLists.txt b/src/lib/unittests/CMakeLists.txt new file mode 100644 index 00000000000..31b3111d6fe --- /dev/null +++ b/src/lib/unittests/CMakeLists.txt @@ -0,0 +1,53 @@ +# BAREOS�� - Backup Archiving REcovery Open Sourced +# +# Copyright (C) 2017-2017 Bareos GmbH & Co. KG +# +# This program is Free Software; you can redistribute it and/or +# modify it under the terms of version three of the GNU Affero General Public +# License as published by the Free Software Foundation and included +# in the file LICENSE. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA. + +include_directories(.. ../.. ../../include/) + +set (TEST_SRC + alist_test.cc + base64_test.cc + bsnprintf_test.cc + devlock_test.cc + dlist_test.cc + edit_test.cc + htable_test.cc + #ini_test.cc + junction_test.cc + passphrase_test.cc + rblist_test.cc + rwlock_test.cc + scan_test.cc + sellist_test.cc + test_lib.cc + #tree_test.cc + ) + + +add_executable(test_lib + ${TEST_SRC} + ) +target_link_libraries(test_lib + bareos + ${JANSSON_LIBRARIES} + ${CMOCKA_LIBRARIES} + ) + +add_test(NAME test_lib + COMMAND test_lib) +add_dependencies(check test_lib)