diff options
author | Carbenium <carbenium@outlook.com> | 2020-07-22 20:27:54 +0200 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2022-01-23 22:48:35 +0100 |
commit | f837f28171970b56781a57b5dc503e6067abecd2 (patch) | |
tree | 77612e6204d75908228bff2915e42771880855fd | |
parent | e8583d04f6a7744bd3576c3241873a8ad33f4f7a (diff) |
dep: Add catch2 unit test framework and wire it up
To enable the test suite, make sure to configure CMake with -DBUILD_TESTING=1 , since it is disabled by default. The catch2 dependency will be downloaded during configure time.
Also add a new target "tests-common", which includes unit tests for the "common" project. To finally run the tests use the "test" target.
CircleCI: Run unit tests
(cherry picked from commit 6a28ee7b2a4269aa7e43265d1cd0067537e3e883)
-rw-r--r-- | .circleci/config.yml | 12 | ||||
-rw-r--r-- | CMakeLists.txt | 11 | ||||
-rw-r--r-- | cmake/options.cmake | 1 | ||||
-rw-r--r-- | cmake/showoptions.cmake | 6 | ||||
-rw-r--r-- | dep/CMakeLists.txt | 9 | ||||
-rw-r--r-- | dep/PackageList.txt | 4 | ||||
-rw-r--r-- | tests/CMakeLists.txt | 23 | ||||
-rw-r--r-- | tests/common/test-main.cpp | 20 |
8 files changed, 83 insertions, 3 deletions
diff --git a/.circleci/config.yml b/.circleci/config.yml index 16eb6cbf519..17cb3c89f74 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -23,7 +23,7 @@ jobs: command: | mkdir bin cd bin - cmake ../ -DWITH_WARNINGS=1 -DWITH_COREDEBUG=0 -DUSE_COREPCH=1 -DUSE_SCRIPTPCH=1 -DTOOLS=1 -DSCRIPTS=dynamic -DSERVERS=1 -DNOJEM=0 -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_FLAGS="-Werror" -DCMAKE_CXX_FLAGS="-Werror" -DCMAKE_C_FLAGS_DEBUG="-DNDEBUG" -DCMAKE_CXX_FLAGS_DEBUG="-DNDEBUG" -DCMAKE_INSTALL_PREFIX=check_install + cmake ../ -DWITH_WARNINGS=1 -DWITH_COREDEBUG=0 -DUSE_COREPCH=1 -DUSE_SCRIPTPCH=1 -DTOOLS=1 -DSCRIPTS=dynamic -DSERVERS=1 -DNOJEM=0 -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_FLAGS="-Werror" -DCMAKE_CXX_FLAGS="-Werror" -DCMAKE_C_FLAGS_DEBUG="-DNDEBUG" -DCMAKE_CXX_FLAGS_DEBUG="-DNDEBUG" -DCMAKE_INSTALL_PREFIX=check_install -DBUILD_TESTING=1 cd .. - run: name: SQL checks @@ -48,7 +48,15 @@ jobs: command: | cd bin make -j 4 -k && make install - cd check_install/bin + - run: + name: Unit tests + command: | + cd bin + make test + - run: + name: Check executables + command: | + cd bin/check_install/bin ./bnetserver --version ./worldserver --version nopch: diff --git a/CMakeLists.txt b/CMakeLists.txt index 739bceab5e6..5bb85d960dd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -cmake_minimum_required(VERSION 3.8) +cmake_minimum_required(VERSION 3.11) # add this options before PROJECT keyword set(CMAKE_DISABLE_SOURCE_CHANGES ON) @@ -90,3 +90,12 @@ add_subdirectory(dep) # add core sources add_subdirectory(src) + +include(CTest) +if(BUILD_TESTING) + list(APPEND CMAKE_MODULE_PATH + "${Catch2_SOURCE_DIR}/contrib") + include(Catch) + + add_subdirectory(tests) +endif() diff --git a/cmake/options.cmake b/cmake/options.cmake index 2551ec72140..9cc6f9cbe87 100644 --- a/cmake/options.cmake +++ b/cmake/options.cmake @@ -54,3 +54,4 @@ option(COPY_CONF "Copy authserver and worldserver .conf.dist files to the set(WITH_SOURCE_TREE "hierarchical" CACHE STRING "Build the source tree for IDE's.") set_property(CACHE WITH_SOURCE_TREE PROPERTY STRINGS no flat hierarchical hierarchical-folders) option(WITHOUT_GIT "Disable the GIT testing routines" 0) +option(BUILD_TESTING "Build test suite" 0) diff --git a/cmake/showoptions.cmake b/cmake/showoptions.cmake index 66cec73089b..8cf5d85b913 100644 --- a/cmake/showoptions.cmake +++ b/cmake/showoptions.cmake @@ -39,6 +39,12 @@ else() message("* Build map/vmap tools : No") endif() +if(BUILD_TESTING) + message("* Build unit tests : Yes") +else() + message("* Build unit tests : No (default)") +endif() + if(USE_COREPCH) message("* Build core w/PCH : Yes (default)") else() diff --git a/dep/CMakeLists.txt b/dep/CMakeLists.txt index cd157398f42..8ef8d7488b8 100644 --- a/dep/CMakeLists.txt +++ b/dep/CMakeLists.txt @@ -36,3 +36,12 @@ endif() if(TOOLS) add_subdirectory(CascLib) endif() + +if(BUILD_TESTING) + include(FetchContent) + FetchContent_Declare(Catch2 + GIT_REPOSITORY https://github.com/catchorg/Catch2.git + GIT_TAG v2.13.0 + GIT_SHALLOW 1) + FetchContent_MakeAvailable(Catch2) +endif() diff --git a/dep/PackageList.txt b/dep/PackageList.txt index 09721c97fc3..0443c981a5d 100644 --- a/dep/PackageList.txt +++ b/dep/PackageList.txt @@ -61,6 +61,10 @@ argon2 https://github.com/P-H-C/phc-winner-argon2 Version: 62358ba +catch2 + https://github.com/catchorg/Catch2 + Version: v2.13.0 + CascLib (An open-source implementation of library for reading CASC storage from Blizzard games since 2014) https://github.com/ladislav-zezula/CascLib Version: 4fc4c18bd5a49208337199a7f4256271675cae44 diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 00000000000..fdbfe689fc2 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,23 @@ +# This file is part of the TrinityCore Project. See AUTHORS file for Copyright information +# +# This file is free software; as a special exception the author gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +CollectSourceFiles( + ${CMAKE_CURRENT_SOURCE_DIR}/common + COMMON_SOURCES +) + +add_executable(tests-common ${COMMON_SOURCES}) + +target_link_libraries(tests-common + PRIVATE + common + Catch2::Catch2) + +catch_discover_tests(tests-common) diff --git a/tests/common/test-main.cpp b/tests/common/test-main.cpp new file mode 100644 index 00000000000..8ed9dd5863b --- /dev/null +++ b/tests/common/test-main.cpp @@ -0,0 +1,20 @@ +/* + * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * 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 General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + + +#define CATCH_CONFIG_MAIN +#include "catch2/catch.hpp" |