From 98007e975385713df526db9dba7c85f53ff5c6d6 Mon Sep 17 00:00:00 2001 From: Guillaume Chatelet Date: Wed, 29 Jun 2022 15:12:24 +0000 Subject: [PATCH] Revert "[libc][test] Remove dependency on sstream in algorithm_test.cpp" This reverts commit 292b281caf8c3750cc0796b971af2ca24236a926. --- libc/test/src/string/memory_utils/CMakeLists.txt | 3 +- .../src/string/memory_utils/algorithm_test.cpp | 47 ++++------------------ 2 files changed, 10 insertions(+), 40 deletions(-) diff --git a/libc/test/src/string/memory_utils/CMakeLists.txt b/libc/test/src/string/memory_utils/CMakeLists.txt index 9b777a7..df481ee15 100644 --- a/libc/test/src/string/memory_utils/CMakeLists.txt +++ b/libc/test/src/string/memory_utils/CMakeLists.txt @@ -4,7 +4,7 @@ add_libc_unittest( libc_string_unittests SRCS address_test.cpp - algorithm_test.cpp + # algorithm_test.cpp backend_test.cpp elements_test.cpp memory_access_test.cpp @@ -12,6 +12,7 @@ add_libc_unittest( COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE} -ffreestanding + -pthread DEPENDS libc.src.string.memory_utils.memory_utils libc.src.__support.CPP.array diff --git a/libc/test/src/string/memory_utils/algorithm_test.cpp b/libc/test/src/string/memory_utils/algorithm_test.cpp index aeadafd..3c6303a 100644 --- a/libc/test/src/string/memory_utils/algorithm_test.cpp +++ b/libc/test/src/string/memory_utils/algorithm_test.cpp @@ -6,9 +6,7 @@ #include #include -#include -#include -#include +#include namespace __llvm_libc { @@ -25,26 +23,7 @@ struct alignas(64) Buffer : cpp::Array { static Buffer buffer1; static Buffer buffer2; -struct Logger { - Logger &operator<<(const char *str) { - Buffer.append(str); - return *this; - } - Logger &operator<<(char c) { - Buffer.push_back(c); - return *this; - } - template - std::enable_if_t::value, Logger &> - operator<<(Scalar number) { - Buffer.append(std::to_string(number)); - return *this; - } - const std::string &str() const { return Buffer; } - -private: - std::string Buffer; -} LOG; +static std::ostringstream LOG; struct TestBackend { static constexpr bool IS_BACKEND_TYPE = true; @@ -93,7 +72,7 @@ struct TestBackend { struct LlvmLibcAlgorithm : public testing::Test { void SetUp() override { - LOG = Logger(); + LOG = std::ostringstream(); LOG << '\n'; } @@ -112,20 +91,11 @@ struct LlvmLibcAlgorithm : public testing::Test { return trace_.c_str(); } - const char *stripComments(std::string expected) { + const char *stripComments(const char *expected) { expected_.clear(); - // split expected by lines - std::vector lines; - lines.emplace_back(); - for (const char c : expected) { - if (c == '\n') { - lines.emplace_back(); - } else { - lines.back().push_back(c); - } - } - // strip comment for each lines - for (const std::string &line : lines) { + std::stringstream ss(expected); + std::string line; + while (std::getline(ss, line, '\n')) { const auto pos = line.find('#'); if (pos == std::string::npos) { expected_ += line; @@ -135,8 +105,7 @@ struct LlvmLibcAlgorithm : public testing::Test { log.pop_back(); expected_ += log; } - if (expected_.back() != '\n') - expected_.push_back('\n'); + expected_ += '\n'; } return expected_.c_str(); } -- 2.7.4