From f92d7b39ddf548b99d7b857c868ad8660ae0e5e7 Mon Sep 17 00:00:00 2001 From: Martchus Date: Fri, 18 Aug 2023 23:25:49 +0200 Subject: [PATCH] Allow running CLI tests under Windows as well Not all tests pass yet but it is a start --- tests/cli.cpp | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/tests/cli.cpp b/tests/cli.cpp index 3f81717..13c4ce9 100644 --- a/tests/cli.cpp +++ b/tests/cli.cpp @@ -38,6 +38,13 @@ using namespace CppUtilities; #include #include +#ifdef stdout +#undef stdout +#endif +#ifdef stderr +#undef stderr +#endif + using namespace std; using namespace CppUtilities::Literals; using namespace TagParser; @@ -50,7 +57,7 @@ enum class TagStatus { Original, TestMetaDataPresent, Removed }; */ class CliTests : public TestFixture { CPPUNIT_TEST_SUITE(CliTests); -#ifdef PLATFORM_UNIX +#if defined(PLATFORM_UNIX) || defined(CPP_UTILITIES_HAS_EXEC_APP) CPPUNIT_TEST(testBasicReading); CPPUNIT_TEST(testBasicWriting); CPPUNIT_TEST(testModifyingCover); @@ -76,7 +83,7 @@ public: void setUp() override; void tearDown() override; -#ifdef PLATFORM_UNIX +#if defined(PLATFORM_UNIX) || defined(CPP_UTILITIES_HAS_EXEC_APP) void testBasicReading(); void testBasicWriting(); void testModifyingCover(); @@ -110,17 +117,34 @@ void CliTests::tearDown() { } -#ifdef PLATFORM_UNIX +#if defined(PLATFORM_UNIX) || defined(CPP_UTILITIES_HAS_EXEC_APP) template bool testContainsSubstrings(const StringType &str, std::initializer_list substrings) { - vector failedSubstrings; - typename StringType::size_type currentPos = 0; +#if defined(PLATFORM_WINDOWS) + auto substringsWindows = std::vector(); + substringsWindows.reserve(substrings.size()); + for (const auto *const substring : substrings) { + findAndReplace(substringsWindows.emplace_back(substring), "\n", "\r\n"); + } +#endif + auto failedSubstrings = std::vector(); + auto currentPos = typename StringType::size_type(); +#if defined(PLATFORM_WINDOWS) + auto currentSubstr = substrings.begin(); + for (const auto &substr : substringsWindows) { + if ((currentPos = str.find(substr, currentPos)) == StringType::npos) { + failedSubstrings.emplace_back(*currentSubstr); + } + currentPos += substr.size(); + ++currentSubstr; +#else for (const auto *substr : substrings) { if ((currentPos = str.find(substr, currentPos)) == StringType::npos) { failedSubstrings.emplace_back(substr); } currentPos += std::strlen(substr); +#endif } bool res = failedSubstrings.empty();