Merge pull request #2437 from myk002/myk_ctest

Combine unit testing branches and simplify
develop
Myk 2022-11-29 15:07:47 -08:00 committed by GitHub
commit 9038c1c568
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 55 additions and 2 deletions

@ -96,8 +96,13 @@ jobs:
run: | run: |
ninja -C build-ci install ninja -C build-ci install
ccache --show-stats ccache --show-stats
- name: Run tests - name: Run cpp unit tests
id: run_tests id: run_tests_cpp
run: |
ninja -C build-ci test
exit $?
- name: Run lua tests
id: run_tests_lua
run: | run: |
export TERM=dumb export TERM=dumb
status=0 status=0

2
.gitignore vendored

@ -29,6 +29,8 @@ build/Makefile
build/CMakeCache.txt build/CMakeCache.txt
build/cmake_install.cmake build/cmake_install.cmake
build/CMakeFiles build/CMakeFiles
build/CTestTestfile.cmake
build/DartConfiguration.tcl
build/data build/data
build/docs build/docs
build/lua build/lua

3
.gitmodules vendored

@ -28,3 +28,6 @@
[submodule "depends/luacov"] [submodule "depends/luacov"]
path = depends/luacov path = depends/luacov
url = ../../DFHack/luacov.git url = ../../DFHack/luacov.git
[submodule "depends/googletest"]
path = depends/googletest
url = ../../google/googletest.git

@ -421,6 +421,16 @@ include_directories(depends/clsocket/src)
include_directories(depends/xlsxio/include) include_directories(depends/xlsxio/include)
add_subdirectory(depends) add_subdirectory(depends)
# Testing with CTest
macro(dfhack_test name files)
message("dfhack_test(${name}, ${files})")
add_executable(${name} ${files})
target_include_directories(${name} PUBLIC depends/googletest/googletest/include)
target_link_libraries(${name} dfhack gtest SDL)
add_test(NAME ${name} COMMAND ${name})
endmacro()
include(CTest)
find_package(Git REQUIRED) find_package(Git REQUIRED)
if(NOT GIT_FOUND) if(NOT GIT_FOUND)
message(SEND_ERROR "could not find git") message(SEND_ERROR "could not find git")

@ -3,6 +3,8 @@ add_subdirectory(lodepng)
add_subdirectory(lua) add_subdirectory(lua)
add_subdirectory(md5) add_subdirectory(md5)
add_subdirectory(protobuf) add_subdirectory(protobuf)
add_subdirectory(googletest)
set_target_properties(gtest PROPERTIES COMPILE_FLAGS "-Wno-maybe-uninitialized -Wno-sign-compare")
# Don't build tinyxml if it's being externally linked against. # Don't build tinyxml if it's being externally linked against.
if(NOT TinyXML_FOUND) if(NOT TinyXML_FOUND)

@ -0,0 +1 @@
Subproject commit 2fe3bd994b3189899d93f1d5a881e725e046fdc2

@ -82,6 +82,11 @@ set(MAIN_SOURCES
RemoteTools.cpp RemoteTools.cpp
) )
file(GLOB_RECURSE TEST_SOURCES
LIST_DIRECTORIES false
*test.cpp)
dfhack_test(dfhack-test "${TEST_SOURCES}")
if(WIN32) if(WIN32)
set(CONSOLE_SOURCES Console-windows.cpp) set(CONSOLE_SOURCES Console-windows.cpp)
else() else()

@ -0,0 +1,19 @@
#include "MiscUtils.h"
#include <gtest/gtest.h>
#include <string>
TEST(MiscUtils, wordwrap) {
std::vector<std::string> result;
word_wrap(&result, "123", 3);
ASSERT_EQ(result.size(), 1);
result.clear();
word_wrap(&result, "123456", 3);
ASSERT_EQ(result.size(), 2);
result.clear();
word_wrap(&result, "1234567", 3);
ASSERT_EQ(result.size(), 3);
}

@ -0,0 +1,6 @@
#include <gtest/gtest.h>
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}