Skip to content

Commit

Permalink
console: Handle Windows translating "\n" to "\r\n" on text-mode FDs
Browse files Browse the repository at this point in the history
  • Loading branch information
dragonmux committed Nov 3, 2023
1 parent eb6c581 commit fb4dbe0
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion test/console.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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<char> 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]")
{
Expand Down

0 comments on commit fb4dbe0

Please sign in to comment.