From 88074dacf047f9002fdba88039f59c5e89c05c62 Mon Sep 17 00:00:00 2001 From: myk002 Date: Mon, 28 Nov 2022 17:31:10 -0800 Subject: [PATCH] move tests into the same dir as the main files --- library/CMakeLists.txt | 5 ++- library/MiscUtils.test.cpp | 52 ++++++----------------- library/{tests/test.cpp => main.test.cpp} | 0 library/tests/CMakeLists.txt | 4 -- library/tests/MiscUtils.test.cpp | 19 --------- 5 files changed, 16 insertions(+), 64 deletions(-) rename library/{tests/test.cpp => main.test.cpp} (100%) delete mode 100644 library/tests/CMakeLists.txt delete mode 100644 library/tests/MiscUtils.test.cpp diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 39c5d92d9..d53f098f8 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -82,7 +82,10 @@ set(MAIN_SOURCES RemoteTools.cpp ) -add_subdirectory(tests) +file(GLOB_RECURSE TEST_SOURCES + LIST_DIRECTORIES false + *test.cpp) +dfhack_test(dfhack-test "${TEST_SOURCES}") if(WIN32) set(CONSOLE_SOURCES Console-windows.cpp) diff --git a/library/MiscUtils.test.cpp b/library/MiscUtils.test.cpp index f3360b121..033b226a7 100644 --- a/library/MiscUtils.test.cpp +++ b/library/MiscUtils.test.cpp @@ -1,47 +1,19 @@ -#include "Internal.h" -#include "MiscUtils.h" -#include +#include "MiscUtils.h" +#include #include -using namespace std; -int compare_result(const vector &expect, const vector &result) -{ - if (result == expect) - { - cout << "ok\n"; - return 0; - } - else { - cout << "not ok\n"; - auto e = expect.begin(); - auto r = result.begin(); - cout << "# " << setw(20) << left << "Expected" << " " << left << "Got\n"; - while (e < expect.end() || r < result.end()) - { - cout - << "# " - << setw(20) << left << ":" + (e < expect.end() ? *e++ : "") + ":" - << " " - << setw(20) << left << ":" + (r < result.end() ? *r++ : "") + ":" - << "\n"; - } - return 1; - } -} +TEST(MiscUtils, wordwrap) { + std::vector result; -int main() -{ - int fails = 0; -#define TEST_WORDWRAP(label, expect, args) \ - { \ - vector result; \ - cout << label << "... "; \ - word_wrap args; \ - fails += compare_result(expect, result); \ - } + word_wrap(&result, "123", 3); + ASSERT_EQ(result.size(), 1); - TEST_WORDWRAP("Short line, no wrap", vector({"12345"}), (&result, "12345", 15)); + result.clear(); + word_wrap(&result, "12345", 3); + ASSERT_EQ(result.size(), 2); - return fails == 0 ? 0 : 1; + result.clear(); + word_wrap(&result, "1234567", 3); + ASSERT_EQ(result.size(), 3); } diff --git a/library/tests/test.cpp b/library/main.test.cpp similarity index 100% rename from library/tests/test.cpp rename to library/main.test.cpp diff --git a/library/tests/CMakeLists.txt b/library/tests/CMakeLists.txt deleted file mode 100644 index 8bbc34065..000000000 --- a/library/tests/CMakeLists.txt +++ /dev/null @@ -1,4 +0,0 @@ -file(GLOB_RECURSE TEST_SOURCES - LIST_DIRECTORIES false - *test.cpp) -dfhack_test(test-library "${TEST_SOURCES}") diff --git a/library/tests/MiscUtils.test.cpp b/library/tests/MiscUtils.test.cpp deleted file mode 100644 index 033b226a7..000000000 --- a/library/tests/MiscUtils.test.cpp +++ /dev/null @@ -1,19 +0,0 @@ - -#include "MiscUtils.h" -#include -#include - -TEST(MiscUtils, wordwrap) { - std::vector result; - - word_wrap(&result, "123", 3); - ASSERT_EQ(result.size(), 1); - - result.clear(); - word_wrap(&result, "12345", 3); - ASSERT_EQ(result.size(), 2); - - result.clear(); - word_wrap(&result, "1234567", 3); - ASSERT_EQ(result.size(), 3); -}