From fb4dbe0871ba2e74eacdff6ae9e6bf63dd125a5a Mon Sep 17 00:00:00 2001 From: dragonmux Date: Thu, 2 Nov 2023 00:21:44 +0000 Subject: [PATCH] console: Handle Windows translating "\n" to "\r\n" on text-mode FDs --- test/console.cxx | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/test/console.cxx b/test/console.cxx index 434510fc..fc9e61a5 100644 --- a/test/console.cxx +++ b/test/console.cxx @@ -106,7 +106,6 @@ TEST_CASE("console_t PTY write", "[console_t]") console = {}; REQUIRE_FALSE(console.valid()); } -#endif void assertPipeRead(const readPipe_t &fd, const std::string &expected) { @@ -115,6 +114,21 @@ void assertPipeRead(const readPipe_t &fd, const std::string &expected) REQUIRE(fd.read(result.data(), result.size())); REQUIRE(memcmp(result.data(), expected.data(), expected.length()) == 0); } +#else + +void assertPipeRead(const readPipe_t &fd, const std::string &expected) +{ + // Assume all expected strings end in '\n' and thus will translate to '\r\n' + fixedVector_t result{expected.length() + 1U}; + REQUIRE(result.valid()); + REQUIRE(fd.read(result.data(), result.size())); + // Truncate the check on the held data by the '\n' + REQUIRE(memcmp(result.data(), expected.data(), expected.length() - 1U) == 0); + // And check it manually after to validate the opening assumption + REQUIRE(result[expected.length() - 1U] == '\r'); + REQUIRE(result[expected.length()] == '\n'); +} +#endif TEST_CASE("console_t pipe write", "[console_t]") {