aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarbenium <carbenium@outlook.com>2020-07-22 20:27:54 +0200
committerPeter Keresztes Schmidt <carbenium@outlook.com>2020-07-24 12:00:54 +0200
commit6a28ee7b2a4269aa7e43265d1cd0067537e3e883 (patch)
tree0318b45951240f81cdf9c3c36e493e16d75f81be
parent3c0ac7302f902d1811d2c215217a3d701f8b5b19 (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
-rw-r--r--.circleci/config.yml12
-rw-r--r--CMakeLists.txt11
-rw-r--r--cmake/options.cmake1
-rw-r--r--cmake/showoptions.cmake6
-rw-r--r--dep/CMakeLists.txt9
-rw-r--r--dep/PackageList.txt4
-rw-r--r--tests/CMakeLists.txt23
-rw-r--r--tests/common/test-main.cpp20
8 files changed, 83 insertions, 3 deletions
diff --git a/.circleci/config.yml b/.circleci/config.yml
index 1f4f0463cc6..e96539968a4 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
@@ -42,7 +42,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
./authserver --version
./worldserver --version
nopch:
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0895367e778..ef7a576a7b1 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 7dffa37bdb0..e57ca22fb17 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 9d4678335f0..45e06b3321e 100644
--- a/cmake/showoptions.cmake
+++ b/cmake/showoptions.cmake
@@ -40,6 +40,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 73192a57fdd..9c1b5cd9b97 100644
--- a/dep/CMakeLists.txt
+++ b/dep/CMakeLists.txt
@@ -35,3 +35,12 @@ if(TOOLS)
add_subdirectory(bzip2)
add_subdirectory(libmpq)
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 ebba25cf3ad..2647a039365 100644
--- a/dep/PackageList.txt
+++ b/dep/PackageList.txt
@@ -68,3 +68,7 @@ recastnavigation (Recast is state of the art navigation mesh construction toolse
argon2
https://github.com/P-H-C/phc-winner-argon2
Version: 62358ba
+
+catch2
+ https://github.com/catchorg/Catch2
+ Version: v2.13.0 \ No newline at end of file
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"