Add support for line buffering

This commit is contained in:
Victor Zverovich
2024-01-27 08:57:21 -08:00
parent 6f260455aa
commit 6435b169ec
2 changed files with 24 additions and 0 deletions
+15
View File
@@ -1752,6 +1752,21 @@ TEST(format_test, big_print) {
EXPECT_WRITE(stdout, big_print(), std::string(count, 'x'));
}
// Windows CRT implements _IOLBF incorrectly (full buffering).
#if FMT_USE_FCNTL && !defined(_WIN32)
TEST(format_test, line_buffering) {
auto pipe = fmt::pipe();
auto read_end = pipe.read_end.fdopen("r");
auto write_end = pipe.write_end.fdopen("w");
setvbuf(write_end.get(), nullptr, _IOLBF, 4096);
write_end.print("42\n");
int n = 0;
int result = fscanf(read_end.get(), "%d", &n);
(void)result;
EXPECT_EQ(n, 42);
}
#endif
TEST(format_test, variadic) {
EXPECT_EQ(fmt::format("{}c{}", "ab", 1), "abc1");
}