forked from OSchip/llvm-project
Revert "[libc][test] Remove dependency on sstream in algorithm_test.cpp"
This reverts commit 292b281caf
.
This commit is contained in:
parent
292b281caf
commit
98007e9753
|
@ -4,7 +4,7 @@ add_libc_unittest(
|
||||||
libc_string_unittests
|
libc_string_unittests
|
||||||
SRCS
|
SRCS
|
||||||
address_test.cpp
|
address_test.cpp
|
||||||
algorithm_test.cpp
|
# algorithm_test.cpp
|
||||||
backend_test.cpp
|
backend_test.cpp
|
||||||
elements_test.cpp
|
elements_test.cpp
|
||||||
memory_access_test.cpp
|
memory_access_test.cpp
|
||||||
|
@ -12,6 +12,7 @@ add_libc_unittest(
|
||||||
COMPILE_OPTIONS
|
COMPILE_OPTIONS
|
||||||
${LIBC_COMPILE_OPTIONS_NATIVE}
|
${LIBC_COMPILE_OPTIONS_NATIVE}
|
||||||
-ffreestanding
|
-ffreestanding
|
||||||
|
-pthread
|
||||||
DEPENDS
|
DEPENDS
|
||||||
libc.src.string.memory_utils.memory_utils
|
libc.src.string.memory_utils.memory_utils
|
||||||
libc.src.__support.CPP.array
|
libc.src.__support.CPP.array
|
||||||
|
|
|
@ -6,9 +6,7 @@
|
||||||
#include <src/string/memory_utils/algorithm.h>
|
#include <src/string/memory_utils/algorithm.h>
|
||||||
#include <src/string/memory_utils/backends.h>
|
#include <src/string/memory_utils/backends.h>
|
||||||
|
|
||||||
#include <string>
|
#include <sstream>
|
||||||
#include <type_traits>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
namespace __llvm_libc {
|
namespace __llvm_libc {
|
||||||
|
|
||||||
|
@ -25,26 +23,7 @@ struct alignas(64) Buffer : cpp::Array<char, 128> {
|
||||||
|
|
||||||
static Buffer buffer1;
|
static Buffer buffer1;
|
||||||
static Buffer buffer2;
|
static Buffer buffer2;
|
||||||
struct Logger {
|
static std::ostringstream LOG;
|
||||||
Logger &operator<<(const char *str) {
|
|
||||||
Buffer.append(str);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
Logger &operator<<(char c) {
|
|
||||||
Buffer.push_back(c);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
template <typename Scalar>
|
|
||||||
std::enable_if_t<std::is_integral<Scalar>::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;
|
|
||||||
|
|
||||||
struct TestBackend {
|
struct TestBackend {
|
||||||
static constexpr bool IS_BACKEND_TYPE = true;
|
static constexpr bool IS_BACKEND_TYPE = true;
|
||||||
|
@ -93,7 +72,7 @@ struct TestBackend {
|
||||||
|
|
||||||
struct LlvmLibcAlgorithm : public testing::Test {
|
struct LlvmLibcAlgorithm : public testing::Test {
|
||||||
void SetUp() override {
|
void SetUp() override {
|
||||||
LOG = Logger();
|
LOG = std::ostringstream();
|
||||||
LOG << '\n';
|
LOG << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,20 +91,11 @@ struct LlvmLibcAlgorithm : public testing::Test {
|
||||||
return trace_.c_str();
|
return trace_.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *stripComments(std::string expected) {
|
const char *stripComments(const char *expected) {
|
||||||
expected_.clear();
|
expected_.clear();
|
||||||
// split expected by lines
|
std::stringstream ss(expected);
|
||||||
std::vector<std::string> lines;
|
std::string line;
|
||||||
lines.emplace_back();
|
while (std::getline(ss, line, '\n')) {
|
||||||
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) {
|
|
||||||
const auto pos = line.find('#');
|
const auto pos = line.find('#');
|
||||||
if (pos == std::string::npos) {
|
if (pos == std::string::npos) {
|
||||||
expected_ += line;
|
expected_ += line;
|
||||||
|
@ -135,8 +105,7 @@ struct LlvmLibcAlgorithm : public testing::Test {
|
||||||
log.pop_back();
|
log.pop_back();
|
||||||
expected_ += log;
|
expected_ += log;
|
||||||
}
|
}
|
||||||
if (expected_.back() != '\n')
|
expected_ += '\n';
|
||||||
expected_.push_back('\n');
|
|
||||||
}
|
}
|
||||||
return expected_.c_str();
|
return expected_.c_str();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue