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 6a28ee7b2a)
This commit is contained in:
Carbenium
2020-07-22 20:27:54 +02:00
committed by Shauren
parent e8583d04f6
commit f837f28171
8 changed files with 83 additions and 3 deletions

View File

@@ -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:

View File

@@ -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()

View File

@@ -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)

View File

@@ -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()

View File

@@ -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()

View File

@@ -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

23
tests/CMakeLists.txt Normal file
View File

@@ -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)

View File

@@ -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"