feature(testing-automation): unit tests with Google Framework (#3273)
This commit is contained in:
@@ -42,6 +42,8 @@ jobs:
|
|||||||
run: source ./apps/ci/ci-worldserver-dry-run.sh
|
run: source ./apps/ci/ci-worldserver-dry-run.sh
|
||||||
- name: Check startup errors
|
- name: Check startup errors
|
||||||
run: source ./apps/ci/ci-error-check.sh
|
run: source ./apps/ci/ci-error-check.sh
|
||||||
|
- name: Run unit tests
|
||||||
|
run: source ./apps/ci/ci-run-unit-tests.sh
|
||||||
|
|
||||||
docker-build:
|
docker-build:
|
||||||
strategy:
|
strategy:
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ nbproject/
|
|||||||
.vscode
|
.vscode
|
||||||
.idea
|
.idea
|
||||||
cmake-build-debug/*
|
cmake-build-debug/*
|
||||||
|
cmake-build-debug-coverage/*
|
||||||
|
|
||||||
#
|
#
|
||||||
# Eclipse
|
# Eclipse
|
||||||
|
|||||||
@@ -138,3 +138,19 @@ CU_RUN_HOOK("BEFORE_SRC_LOAD")
|
|||||||
add_subdirectory(src)
|
add_subdirectory(src)
|
||||||
|
|
||||||
CU_RUN_HOOK("AFTER_SRC_LOAD")
|
CU_RUN_HOOK("AFTER_SRC_LOAD")
|
||||||
|
|
||||||
|
if( UNIT_TESTS )
|
||||||
|
# we use this to get code coverage
|
||||||
|
if(CMAKE_CXX_COMPILER_ID MATCHES GNU)
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
include(src/cmake/googletest.cmake)
|
||||||
|
fetch_googletest(
|
||||||
|
${PROJECT_SOURCE_DIR}/src/cmake
|
||||||
|
${PROJECT_BINARY_DIR}/googletest
|
||||||
|
)
|
||||||
|
|
||||||
|
enable_testing()
|
||||||
|
add_subdirectory(src/test)
|
||||||
|
endif()
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ CWARNINGS=ON
|
|||||||
CDEBUG=OFF
|
CDEBUG=OFF
|
||||||
CTYPE=Release
|
CTYPE=Release
|
||||||
CSCRIPTS=ON
|
CSCRIPTS=ON
|
||||||
|
CUNIT_TESTS=ON
|
||||||
CSERVERS=ON
|
CSERVERS=ON
|
||||||
CTOOLS=ON
|
CTOOLS=ON
|
||||||
CSCRIPTPCH=OFF
|
CSCRIPTPCH=OFF
|
||||||
|
|||||||
Executable
+3
@@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
time /home/runner/work/azerothcore-wotlk/azerothcore-wotlk/var/build/obj/src/test/unit_tests
|
||||||
@@ -35,6 +35,7 @@ function comp_configure() {
|
|||||||
|
|
||||||
cmake $SRCPATH -DCMAKE_INSTALL_PREFIX=$BINPATH $DCONF -DSERVERS=$CSERVERS \
|
cmake $SRCPATH -DCMAKE_INSTALL_PREFIX=$BINPATH $DCONF -DSERVERS=$CSERVERS \
|
||||||
-DSCRIPTS=$CSCRIPTS \
|
-DSCRIPTS=$CSCRIPTS \
|
||||||
|
-DUNIT_TESTS=$CUNIT_TESTS \
|
||||||
-DTOOLS=$CTOOLS -DUSE_SCRIPTPCH=$CSCRIPTPCH -DUSE_COREPCH=$CCOREPCH -DWITH_COREDEBUG=$CDEBUG -DCMAKE_BUILD_TYPE=$CTYPE -DWITH_WARNINGS=$CWARNINGS \
|
-DTOOLS=$CTOOLS -DUSE_SCRIPTPCH=$CSCRIPTPCH -DUSE_COREPCH=$CCOREPCH -DWITH_COREDEBUG=$CDEBUG -DCMAKE_BUILD_TYPE=$CTYPE -DWITH_WARNINGS=$CWARNINGS \
|
||||||
-DCMAKE_C_COMPILER=$CCOMPILERC -DCMAKE_CXX_COMPILER=$CCOMPILERCXX "-DDISABLED_AC_MODULES=$CDISABLED_AC_MODULES" $CCUSTOMOPTIONS
|
-DCMAKE_C_COMPILER=$CCOMPILERC -DCMAKE_CXX_COMPILER=$CCOMPILERCXX "-DDISABLED_AC_MODULES=$CDISABLED_AC_MODULES" $CCUSTOMOPTIONS
|
||||||
|
|
||||||
|
|||||||
Vendored
+1
@@ -1,5 +1,6 @@
|
|||||||
option(SERVERS "Build worldserver and authserver" 1)
|
option(SERVERS "Build worldserver and authserver" 1)
|
||||||
option(SCRIPTS "Build core with scripts included" 1)
|
option(SCRIPTS "Build core with scripts included" 1)
|
||||||
|
option(UNIT_TESTS "Build unit tests" 0)
|
||||||
option(TOOLS "Build map/vmap/mmap extraction/assembler tools" 0)
|
option(TOOLS "Build map/vmap/mmap extraction/assembler tools" 0)
|
||||||
option(USE_SCRIPTPCH "Use precompiled headers when compiling scripts" 1)
|
option(USE_SCRIPTPCH "Use precompiled headers when compiling scripts" 1)
|
||||||
option(USE_COREPCH "Use precompiled headers when compiling servers" 1)
|
option(USE_COREPCH "Use precompiled headers when compiling servers" 1)
|
||||||
|
|||||||
Vendored
+2
@@ -47,6 +47,8 @@ CDEBUG=OFF
|
|||||||
CTYPE=Release
|
CTYPE=Release
|
||||||
# compile scripts
|
# compile scripts
|
||||||
CSCRIPTS=ON
|
CSCRIPTS=ON
|
||||||
|
# compile unit tests
|
||||||
|
CUNIT_TESTS=OFF
|
||||||
# compile server
|
# compile server
|
||||||
CSERVERS=ON
|
CSERVERS=ON
|
||||||
# compile tools
|
# compile tools
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
# code copied from https://crascit.com/2015/07/25/cmake-gtest/
|
||||||
|
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
|
||||||
|
|
||||||
|
project(googletest-download NONE)
|
||||||
|
|
||||||
|
include(ExternalProject)
|
||||||
|
|
||||||
|
ExternalProject_Add(
|
||||||
|
googletest
|
||||||
|
SOURCE_DIR "@GOOGLETEST_DOWNLOAD_ROOT@/googletest-src"
|
||||||
|
BINARY_DIR "@GOOGLETEST_DOWNLOAD_ROOT@/googletest-build"
|
||||||
|
GIT_REPOSITORY
|
||||||
|
https://github.com/google/googletest.git
|
||||||
|
GIT_TAG
|
||||||
|
release-1.10.0
|
||||||
|
CONFIGURE_COMMAND ""
|
||||||
|
BUILD_COMMAND ""
|
||||||
|
INSTALL_COMMAND ""
|
||||||
|
TEST_COMMAND ""
|
||||||
|
)
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
# the following code to fetch googletest
|
||||||
|
# is inspired by and adapted after https://crascit.com/2015/07/25/cmake-gtest/
|
||||||
|
# download and unpack googletest at configure time
|
||||||
|
|
||||||
|
macro(fetch_googletest _download_module_path _download_root)
|
||||||
|
set(GOOGLETEST_DOWNLOAD_ROOT ${_download_root})
|
||||||
|
configure_file(
|
||||||
|
${_download_module_path}/googletest-download.cmake
|
||||||
|
${_download_root}/CMakeLists.txt
|
||||||
|
@ONLY
|
||||||
|
)
|
||||||
|
unset(GOOGLETEST_DOWNLOAD_ROOT)
|
||||||
|
|
||||||
|
execute_process(
|
||||||
|
COMMAND
|
||||||
|
"${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" .
|
||||||
|
WORKING_DIRECTORY
|
||||||
|
${_download_root}
|
||||||
|
)
|
||||||
|
execute_process(
|
||||||
|
COMMAND
|
||||||
|
"${CMAKE_COMMAND}" --build .
|
||||||
|
WORKING_DIRECTORY
|
||||||
|
${_download_root}
|
||||||
|
)
|
||||||
|
|
||||||
|
# adds the targers: gtest, gtest_main, gmock, gmock_main
|
||||||
|
add_subdirectory(
|
||||||
|
${_download_root}/googletest-src
|
||||||
|
${_download_root}/googletest-build
|
||||||
|
)
|
||||||
|
endmacro()
|
||||||
@@ -40,6 +40,12 @@ else()
|
|||||||
message("* Build map/vmap tools : No (default)")
|
message("* Build map/vmap tools : No (default)")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if( UNIT_TESTS )
|
||||||
|
message("* Build unit tests : Yes")
|
||||||
|
else()
|
||||||
|
message("* Build unit tests : No (default)")
|
||||||
|
endif()
|
||||||
|
|
||||||
if( USE_COREPCH )
|
if( USE_COREPCH )
|
||||||
message("* Build core w/PCH : Yes (default)")
|
message("* Build core w/PCH : Yes (default)")
|
||||||
else()
|
else()
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
CollectSourceFiles(
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
|
PRIVATE_SOURCES
|
||||||
|
)
|
||||||
|
|
||||||
|
add_executable(
|
||||||
|
unit_tests
|
||||||
|
${PRIVATE_SOURCES}
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(
|
||||||
|
unit_tests
|
||||||
|
gtest_main
|
||||||
|
game
|
||||||
|
game-interface
|
||||||
|
)
|
||||||
|
|
||||||
|
add_test(
|
||||||
|
NAME
|
||||||
|
unit
|
||||||
|
COMMAND
|
||||||
|
${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}/unit_tests
|
||||||
|
)
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
#include "gtest/gtest.h"
|
||||||
|
#include "Formulas.h"
|
||||||
|
|
||||||
|
TEST(FormulasTest, hk_honor_at_level)
|
||||||
|
{
|
||||||
|
EXPECT_EQ(acore::Honor::hk_honor_at_level(80), 124);
|
||||||
|
EXPECT_EQ(acore::Honor::hk_honor_at_level(80, 2), 248);
|
||||||
|
EXPECT_EQ(acore::Honor::hk_honor_at_level(80, 0.5), 62);
|
||||||
|
EXPECT_EQ(acore::Honor::hk_honor_at_level(1), 2);
|
||||||
|
EXPECT_EQ(acore::Honor::hk_honor_at_level(1, 10), 16);
|
||||||
|
EXPECT_EQ(acore::Honor::hk_honor_at_level(2), 4);
|
||||||
|
EXPECT_EQ(acore::Honor::hk_honor_at_level(3), 5);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user