Removes separated unit test executables

develop
Josh Cooper 2022-11-11 18:46:46 -08:00
parent 69d988332c
commit 25f87306b4
5 changed files with 22 additions and 30 deletions

@ -394,11 +394,6 @@ else()
endif() endif()
endif() endif()
find_package(ZLIB REQUIRED)
include_directories(depends/protobuf)
include_directories(depends/lua/include)
include_directories(depends/md5)
# Support linking against external tinyxml # Support linking against external tinyxml
# If we find an external tinyxml, set the DFHACK_TINYXML variable to "tinyxml" # If we find an external tinyxml, set the DFHACK_TINYXML variable to "tinyxml"
# Otherwise, set it to "dfhack-tinyxml" # Otherwise, set it to "dfhack-tinyxml"
@ -420,9 +415,15 @@ if(BUILD_TESTING)
set(BUILD_CORE_TESTS ON FORCE) set(BUILD_CORE_TESTS ON FORCE)
endif() endif()
find_package(ZLIB REQUIRED)
if(BUILD_CORE_TESTS) if(BUILD_CORE_TESTS)
include_directories(depends/googletest/googletest/include) include_directories(depends/googletest/googletest/include)
endif() endif()
include_directories(depends/protobuf)
include_directories(depends/lua/include)
include_directories(depends/md5)
include_directories(depends/lodepng) include_directories(depends/lodepng)
include_directories(depends/tthread) include_directories(depends/tthread)
include_directories(${ZLIB_INCLUDE_DIRS}) include_directories(${ZLIB_INCLUDE_DIRS})
@ -433,7 +434,13 @@ add_subdirectory(depends)
# Testing with CTest # Testing with CTest
if(BUILD_TESTING OR BUILD_CORE_TESTS) if(BUILD_TESTING OR BUILD_CORE_TESTS)
message("Including CTest") macro(dfhack_test name files)
message("dfhack_test(${name}, ${files})")
add_executable(${name} ${files})
target_link_libraries(${name} dfhack gtest)
add_test(NAME ${name} COMMAND ${name})
set_target_properties(${name} PROPERTIES COMPILE_FLAGS "-Wno-sign-compare")
endmacro()
include(CTest) include(CTest)
endif() endif()

@ -82,23 +82,8 @@ set(MAIN_SOURCES
RemoteTools.cpp RemoteTools.cpp
) )
macro(dfhack_test name files)
message("dfhack_test files: ${files}")
add_executable(${name} test.cpp ${files})
target_link_libraries(${name} dfhack gtest)
add_test(NAME ${name} COMMAND ${name})
set_target_properties(${name} PROPERTIES COMPILE_FLAGS "-Wno-sign-compare")
endmacro()
if(BUILD_CORE_TESTS) if(BUILD_CORE_TESTS)
file(GLOB_RECURSE TEST_SOURCES LIST_DIRECTORIES false *.test.cpp) add_subdirectory(tests)
dfhack_test(test-all ${TEST_SOURCES})
dfhack_test(test-MiscUtils MiscUtils.test.cpp)
# How to get `test` to ensure everything is up to date before running
# tests? This add_dependencies() fails with:
# Cannot add target-level dependencies to non-existent target "test".
#add_dependencies(test MiscUtils.test)
endif() endif()
if(WIN32) if(WIN32)

@ -0,0 +1,7 @@
file(GLOB_RECURSE TEST_SOURCES LIST_DIRECTORIES false *test.cpp)
dfhack_test(test-library "${TEST_SOURCES}")
# How to get `test` to ensure everything is up to date before running
# tests? This add_dependencies() fails with:
# Cannot add target-level dependencies to non-existent target "test".
#add_dependencies(test MiscUtils.test)

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

@ -3,4 +3,4 @@
int main(int argc, char **argv) { int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv); ::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS(); return RUN_ALL_TESTS();
} }