move tests into the same dir as the main files

develop
myk002 2022-11-28 17:31:10 -08:00
parent 7fbeb215d7
commit 88074dacf0
No known key found for this signature in database
GPG Key ID: 8A39CA0FA0C16E78
5 changed files with 16 additions and 64 deletions

@ -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)

@ -1,47 +1,19 @@
#include "Internal.h"
#include "MiscUtils.h"
#include <iostream>
#include "MiscUtils.h"
#include <gtest/gtest.h>
#include <string>
using namespace std;
int compare_result(const vector<string> &expect, const vector<string> &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<std::string> result;
int main()
{
int fails = 0;
#define TEST_WORDWRAP(label, expect, args) \
{ \
vector<string> 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<string>({"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);
}

@ -1,4 +0,0 @@
file(GLOB_RECURSE TEST_SOURCES
LIST_DIRECTORIES false
*test.cpp)
dfhack_test(test-library "${TEST_SOURCES}")

@ -1,19 +0,0 @@
#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, "12345", 3);
ASSERT_EQ(result.size(), 2);
result.clear();
word_wrap(&result, "1234567", 3);
ASSERT_EQ(result.size(), 3);
}