From bba0a9d9623c88ac0bdee34302651d51ac289c5f Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Fri, 30 Jul 2021 07:02:49 -0700 Subject: [PATCH] Make flush public --- include/fmt/os.h | 12 ++++++------ test/os-test.cc | 8 ++++++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/include/fmt/os.h b/include/fmt/os.h index f6c0f329858c..43ffd3cf0ac8 100644 --- a/include/fmt/os.h +++ b/include/fmt/os.h @@ -401,12 +401,6 @@ class FMT_API ostream final : private detail::buffer { private: file file_; - void flush() { - if (size() == 0) return; - file_.write(data(), size()); - clear(); - } - void grow(size_t) override; ostream(cstring_view path, const detail::ostream_params& params) @@ -426,6 +420,12 @@ class FMT_API ostream final : private detail::buffer { delete[] data(); } + void flush() { + if (size() == 0) return; + file_.write(data(), size()); + clear(); + } + template friend ostream output_file(cstring_view path, T... params); diff --git a/test/os-test.cc b/test/os-test.cc index b2bd20f2a2c9..01ab7036c678 100644 --- a/test/os-test.cc +++ b/test/os-test.cc @@ -336,6 +336,14 @@ TEST(ostream_test, truncate) { EXPECT_EQ("foo", read(in, 4)); } +TEST(ostream_test, flush) { + auto out = fmt::output_file("test-file"); + out.print("x"); + out.flush(); + auto in = fmt::file("test-file", file::RDONLY); + EXPECT_READ(in, "x"); +} + TEST(file_test, default_ctor) { file f; EXPECT_EQ(-1, f.descriptor());