From 25f87306b427c39e14591e19754d56633e940b92 Mon Sep 17 00:00:00 2001 From: Josh Cooper Date: Fri, 11 Nov 2022 18:46:46 -0800 Subject: [PATCH] Removes separated unit test executables --- CMakeLists.txt | 19 +++++++++++++------ library/CMakeLists.txt | 17 +---------------- library/tests/CMakeLists.txt | 7 +++++++ library/{ => tests}/MiscUtils.test.cpp | 7 ------- library/{ => tests}/test.cpp | 2 +- 5 files changed, 22 insertions(+), 30 deletions(-) create mode 100644 library/tests/CMakeLists.txt rename library/{ => tests}/MiscUtils.test.cpp (59%) rename library/{ => tests}/test.cpp (98%) diff --git a/CMakeLists.txt b/CMakeLists.txt index c78c45bec..29103d495 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -394,11 +394,6 @@ else() endif() endif() -find_package(ZLIB REQUIRED) -include_directories(depends/protobuf) -include_directories(depends/lua/include) -include_directories(depends/md5) - # Support linking against external tinyxml # If we find an external tinyxml, set the DFHACK_TINYXML variable to "tinyxml" # Otherwise, set it to "dfhack-tinyxml" @@ -420,9 +415,15 @@ if(BUILD_TESTING) set(BUILD_CORE_TESTS ON FORCE) endif() +find_package(ZLIB REQUIRED) + if(BUILD_CORE_TESTS) include_directories(depends/googletest/googletest/include) endif() + +include_directories(depends/protobuf) +include_directories(depends/lua/include) +include_directories(depends/md5) include_directories(depends/lodepng) include_directories(depends/tthread) include_directories(${ZLIB_INCLUDE_DIRS}) @@ -433,7 +434,13 @@ add_subdirectory(depends) # Testing with CTest 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) endif() diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 035fcda73..5e7488027 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -82,23 +82,8 @@ set(MAIN_SOURCES 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) - file(GLOB_RECURSE TEST_SOURCES LIST_DIRECTORIES false *.test.cpp) - 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) + add_subdirectory(tests) endif() if(WIN32) diff --git a/library/tests/CMakeLists.txt b/library/tests/CMakeLists.txt new file mode 100644 index 000000000..3e5a2b3ca --- /dev/null +++ b/library/tests/CMakeLists.txt @@ -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) diff --git a/library/MiscUtils.test.cpp b/library/tests/MiscUtils.test.cpp similarity index 59% rename from library/MiscUtils.test.cpp rename to library/tests/MiscUtils.test.cpp index e0cabe234..033b226a7 100644 --- a/library/MiscUtils.test.cpp +++ b/library/tests/MiscUtils.test.cpp @@ -1,26 +1,19 @@ #include "MiscUtils.h" #include -#include #include TEST(MiscUtils, wordwrap) { std::vector result; - std::cout << "MiscUtils.wordwrap: 0 wrap" << "... "; word_wrap(&result, "123", 3); ASSERT_EQ(result.size(), 1); - std::cout << "ok\n"; result.clear(); - std::cout << "MiscUtils.wordwrap: 1 wrap" << "... "; word_wrap(&result, "12345", 3); ASSERT_EQ(result.size(), 2); - std::cout << "ok\n"; result.clear(); - std::cout << "MiscUtils.wordwrap: 2 wrap" << "... "; word_wrap(&result, "1234567", 3); ASSERT_EQ(result.size(), 3); - std::cout << "ok\n"; } diff --git a/library/test.cpp b/library/tests/test.cpp similarity index 98% rename from library/test.cpp rename to library/tests/test.cpp index 2dc3787b7..76f841f1b 100644 --- a/library/test.cpp +++ b/library/tests/test.cpp @@ -3,4 +3,4 @@ int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); -} \ No newline at end of file +}