From c64791172313ca2b0392337281ebed755ebd9122 Mon Sep 17 00:00:00 2001 From: Hristo Hristov Date: Fri, 19 Apr 2024 19:04:16 +0300 Subject: [PATCH 01/12] P3142R0: `println` blank line Implements https://wg21.link/P3142R0 Applied retroactively as DR, same as stdlibc++ and MS STL: https://github.com/orgs/microsoft/projects/1143?pane=issue&itemId=57457187 --- stl/inc/ostream | 4 +++ stl/inc/print | 8 +++++ .../include/test_header_units_and_modules.hpp | 2 ++ .../tests/P2093R14_formatted_output/test.cpp | 35 ++++++++++++++++--- 4 files changed, 44 insertions(+), 5 deletions(-) diff --git a/stl/inc/ostream b/stl/inc/ostream index 3ce22b869b..8938b62471 100644 --- a/stl/inc/ostream +++ b/stl/inc/ostream @@ -1272,6 +1272,10 @@ void println(ostream& _Ostr, const format_string<_Types...> _Fmt, _Types&&... _A _STD _Print_impl(_Add_newline::_Yes, _Ostr, _Fmt, _STD forward<_Types>(_Args)...); } +_EXPORT_STD inline void println(ostream& _Ostr) { + _STD print(_Ostr, "\n"); +} + _EXPORT_STD template // improves throughput, see GH-2329 void vprint_unicode(ostream& _Ostr, const string_view _Fmt_str, const format_args _Fmt_args) { _STD _Vprint_unicode_impl(_Add_newline::_Nope, _Ostr, _Fmt_str, _Fmt_args); diff --git a/stl/inc/print b/stl/inc/print index 3d19c7aa4f..5994bcb0e7 100644 --- a/stl/inc/print +++ b/stl/inc/print @@ -131,6 +131,14 @@ void println(FILE* const _Stream, const format_string<_Types...> _Fmt, _Types&&. _STD _Print_impl(_Add_newline::_Yes, _Stream, _Fmt, _STD forward<_Types>(_Args)...); } +_EXPORT_STD inline void println(FILE* _Stream) { + _STD print(_Stream, "\n"); +} + +_EXPORT_STD inline void println() { + println(stdout); +} + _EXPORT_STD template void println(const format_string<_Types...> _Fmt, _Types&&... _Args) { _STD println(stdout, _Fmt, _STD forward<_Types>(_Args)...); diff --git a/tests/std/include/test_header_units_and_modules.hpp b/tests/std/include/test_header_units_and_modules.hpp index 25576a13c3..ceab5eb2d5 100644 --- a/tests/std/include/test_header_units_and_modules.hpp +++ b/tests/std/include/test_header_units_and_modules.hpp @@ -545,9 +545,11 @@ void test_print() { using namespace std; puts("Testing ."); println("Hello, world!"); + println(); #ifdef _CPPRTTI println(cout, "The answer to life, the universe, and everything: {}", 42); + println(cout); #endif // _CPPRTTI } #endif // TEST_STANDARD >= 23 diff --git a/tests/std/tests/P2093R14_formatted_output/test.cpp b/tests/std/tests/P2093R14_formatted_output/test.cpp index 68b9ff5d28..bd3b41b231 100644 --- a/tests/std/tests/P2093R14_formatted_output/test.cpp +++ b/tests/std/tests/P2093R14_formatted_output/test.cpp @@ -491,13 +491,25 @@ void test_stream_flush_console() { } } + println(console_file_stream); + + { + const wstring extractedStr{temp_console.get_console_line(0)}; + + if constexpr (_Is_ordinary_literal_encoding_utf8()) { + assert(extractedStr == L"Hello,\n"); + } else { + assert(extractedStr.empty()); + } + } + println(console_file_stream, " world!"); { const wstring extractedStr{temp_console.get_console_line(0)}; if constexpr (_Is_ordinary_literal_encoding_utf8()) { - assert(extractedStr == L"Hello, world!"); + assert(extractedStr == L"Hello,\n world!"); } else { assert(extractedStr.empty()); } @@ -507,7 +519,7 @@ void test_stream_flush_console() { { const wstring extractedStr{temp_console.get_console_line(0)}; - assert(extractedStr == L"Hello, world!"); + assert(extractedStr == L"Hello,\n world!"); } } @@ -519,7 +531,7 @@ void test_stream_flush_file() { { ofstream output_file_stream{temp_file_name_str}; - print(output_file_stream, "Hello, "); + print(output_file_stream, "Hello,"); { ifstream input_file_stream{temp_file_name_str}; @@ -530,7 +542,18 @@ void test_stream_flush_file() { assert(extracted_line_str.empty()); } - println(output_file_stream, "world!"); + println(output_file_stream); + + { + ifstream input_file_stream{temp_file_name_str}; + + string extracted_line_str; + getline(input_file_stream, extracted_line_str); + + assert(extracted_line_str.empty()); + } + + println(output_file_stream, " world!"); { ifstream input_file_stream{temp_file_name_str}; @@ -549,7 +572,7 @@ void test_stream_flush_file() { string extracted_line_str; getline(input_file_stream, extracted_line_str); - assert(extracted_line_str == "Hello, world!"); + assert(extracted_line_str == "Hello,\n world!"); } } @@ -567,6 +590,7 @@ void test_empty_strings_and_newlines() { print(output_file_stream, "-D\n"); print(output_file_stream, "{{}} for {}!\n", "impact"); + println(output_file_stream); println(output_file_stream, "I have {} cute {} kittens.", 1729, "fluffy"); println(output_file_stream, ""); println(output_file_stream, "What are an orthodontist's favorite characters? '{{' and '}}', of course!"); @@ -585,6 +609,7 @@ void test_empty_strings_and_newlines() { const vector expected_lines{ "NCC-1701-D", "{} for impact!", + "", "I have 1729 cute fluffy kittens.", "", "What are an orthodontist's favorite characters? '{' and '}', of course!", From 5a4dc42eaf039926aa2473e280896f43046b013e Mon Sep 17 00:00:00 2001 From: Hristo Hristov Date: Sat, 20 Apr 2024 09:21:40 +0300 Subject: [PATCH 02/12] Applied template according to GH-2329 ... see https://github.com/microsoft/STL/issues/2329 --- stl/inc/ostream | 3 ++- stl/inc/print | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/stl/inc/ostream b/stl/inc/ostream index 8938b62471..b682a8b68b 100644 --- a/stl/inc/ostream +++ b/stl/inc/ostream @@ -1272,7 +1272,8 @@ void println(ostream& _Ostr, const format_string<_Types...> _Fmt, _Types&&... _A _STD _Print_impl(_Add_newline::_Yes, _Ostr, _Fmt, _STD forward<_Types>(_Args)...); } -_EXPORT_STD inline void println(ostream& _Ostr) { +_EXPORT_STD template // improves throughput, see GH-2329 +void println(ostream& _Ostr) { _STD print(_Ostr, "\n"); } diff --git a/stl/inc/print b/stl/inc/print index 5994bcb0e7..bac2bf3903 100644 --- a/stl/inc/print +++ b/stl/inc/print @@ -131,11 +131,13 @@ void println(FILE* const _Stream, const format_string<_Types...> _Fmt, _Types&&. _STD _Print_impl(_Add_newline::_Yes, _Stream, _Fmt, _STD forward<_Types>(_Args)...); } -_EXPORT_STD inline void println(FILE* _Stream) { +_EXPORT_STD template // improves throughput, see GH-2329 +void println(FILE* _Stream) { _STD print(_Stream, "\n"); } -_EXPORT_STD inline void println() { +_EXPORT_STD template // improves throughput, see GH-2329 +void println() { println(stdout); } From e1089d5e5461ead8d0b6f815366043b07d5c41d3 Mon Sep 17 00:00:00 2001 From: Hristo Hristov Date: Tue, 23 Apr 2024 22:16:46 +0300 Subject: [PATCH 03/12] Revert test --- .../tests/P2093R14_formatted_output/test.cpp | 35 +++---------------- 1 file changed, 5 insertions(+), 30 deletions(-) diff --git a/tests/std/tests/P2093R14_formatted_output/test.cpp b/tests/std/tests/P2093R14_formatted_output/test.cpp index bd3b41b231..68b9ff5d28 100644 --- a/tests/std/tests/P2093R14_formatted_output/test.cpp +++ b/tests/std/tests/P2093R14_formatted_output/test.cpp @@ -491,25 +491,13 @@ void test_stream_flush_console() { } } - println(console_file_stream); - - { - const wstring extractedStr{temp_console.get_console_line(0)}; - - if constexpr (_Is_ordinary_literal_encoding_utf8()) { - assert(extractedStr == L"Hello,\n"); - } else { - assert(extractedStr.empty()); - } - } - println(console_file_stream, " world!"); { const wstring extractedStr{temp_console.get_console_line(0)}; if constexpr (_Is_ordinary_literal_encoding_utf8()) { - assert(extractedStr == L"Hello,\n world!"); + assert(extractedStr == L"Hello, world!"); } else { assert(extractedStr.empty()); } @@ -519,7 +507,7 @@ void test_stream_flush_console() { { const wstring extractedStr{temp_console.get_console_line(0)}; - assert(extractedStr == L"Hello,\n world!"); + assert(extractedStr == L"Hello, world!"); } } @@ -531,7 +519,7 @@ void test_stream_flush_file() { { ofstream output_file_stream{temp_file_name_str}; - print(output_file_stream, "Hello,"); + print(output_file_stream, "Hello, "); { ifstream input_file_stream{temp_file_name_str}; @@ -542,18 +530,7 @@ void test_stream_flush_file() { assert(extracted_line_str.empty()); } - println(output_file_stream); - - { - ifstream input_file_stream{temp_file_name_str}; - - string extracted_line_str; - getline(input_file_stream, extracted_line_str); - - assert(extracted_line_str.empty()); - } - - println(output_file_stream, " world!"); + println(output_file_stream, "world!"); { ifstream input_file_stream{temp_file_name_str}; @@ -572,7 +549,7 @@ void test_stream_flush_file() { string extracted_line_str; getline(input_file_stream, extracted_line_str); - assert(extracted_line_str == "Hello,\n world!"); + assert(extracted_line_str == "Hello, world!"); } } @@ -590,7 +567,6 @@ void test_empty_strings_and_newlines() { print(output_file_stream, "-D\n"); print(output_file_stream, "{{}} for {}!\n", "impact"); - println(output_file_stream); println(output_file_stream, "I have {} cute {} kittens.", 1729, "fluffy"); println(output_file_stream, ""); println(output_file_stream, "What are an orthodontist's favorite characters? '{{' and '}}', of course!"); @@ -609,7 +585,6 @@ void test_empty_strings_and_newlines() { const vector expected_lines{ "NCC-1701-D", "{} for impact!", - "", "I have 1729 cute fluffy kittens.", "", "What are an orthodontist's favorite characters? '{' and '}', of course!", From 5be706a467bcfbfc59ad17d3bb23bb04dae0341d Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Thu, 25 Apr 2024 13:43:52 -0700 Subject: [PATCH 04/12] Record the new feature in ``'s `_HAS_CXX23` section. --- stl/inc/yvals_core.h | 1 + 1 file changed, 1 insertion(+) diff --git a/stl/inc/yvals_core.h b/stl/inc/yvals_core.h index ab51dea02b..70094bd44b 100644 --- a/stl/inc/yvals_core.h +++ b/stl/inc/yvals_core.h @@ -384,6 +384,7 @@ // P2713R1 Escaping Improvements In std::format // P2763R1 Fixing layout_stride's Default Constructor For Fully Static Extents // P2836R1 basic_const_iterator Should Follow Its Underlying Type's Convertibility +// P3142R0 Printing Blank Lines With println() // _HAS_CXX23 and _SILENCE_ALL_CXX23_DEPRECATION_WARNINGS control: // P1413R3 Deprecate aligned_storage And aligned_union From 53b9255526d7a3a27b1b4f8e3de8edcc1fafdf7d Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Thu, 25 Apr 2024 14:05:28 -0700 Subject: [PATCH 05/12] Qualify `_STD println`. --- stl/inc/print | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stl/inc/print b/stl/inc/print index bac2bf3903..13f12ea046 100644 --- a/stl/inc/print +++ b/stl/inc/print @@ -138,7 +138,7 @@ void println(FILE* _Stream) { _EXPORT_STD template // improves throughput, see GH-2329 void println() { - println(stdout); + _STD println(stdout); } _EXPORT_STD template From 0a9f3f9eec3fa824bca051b0e67421b7aef1dbe2 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Thu, 25 Apr 2024 14:40:35 -0700 Subject: [PATCH 06/12] Restore `println(ostream&)` coverage. --- tests/std/tests/P2093R14_formatted_output/test.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/std/tests/P2093R14_formatted_output/test.cpp b/tests/std/tests/P2093R14_formatted_output/test.cpp index 68b9ff5d28..482fedd187 100644 --- a/tests/std/tests/P2093R14_formatted_output/test.cpp +++ b/tests/std/tests/P2093R14_formatted_output/test.cpp @@ -567,6 +567,7 @@ void test_empty_strings_and_newlines() { print(output_file_stream, "-D\n"); print(output_file_stream, "{{}} for {}!\n", "impact"); + println(output_file_stream); println(output_file_stream, "I have {} cute {} kittens.", 1729, "fluffy"); println(output_file_stream, ""); println(output_file_stream, "What are an orthodontist's favorite characters? '{{' and '}}', of course!"); @@ -585,6 +586,7 @@ void test_empty_strings_and_newlines() { const vector expected_lines{ "NCC-1701-D", "{} for impact!", + "", "I have 1729 cute fluffy kittens.", "", "What are an orthodontist's favorite characters? '{' and '}', of course!", From a617a7f4cc9c56bfaea11779443894b8fae269f2 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Thu, 25 Apr 2024 15:04:35 -0700 Subject: [PATCH 07/12] Extract checked_fopen_s() for reuse. --- tests/std/tests/P2093R14_formatted_output/test.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/std/tests/P2093R14_formatted_output/test.cpp b/tests/std/tests/P2093R14_formatted_output/test.cpp index 482fedd187..0d88cd085a 100644 --- a/tests/std/tests/P2093R14_formatted_output/test.cpp +++ b/tests/std/tests/P2093R14_formatted_output/test.cpp @@ -403,17 +403,19 @@ void test_invalid_code_points_console() { test_invalid_sequence_closure("\xF0\x28\x8C\x25"); } +FILE* checked_fopen_s(const string& filename, const char* const mode) { + FILE* ret; + const errno_t fopen_result = fopen_s(&ret, filename.c_str(), mode); + assert(fopen_result == 0); + return ret; +} + void test_invalid_code_points_file() { // Unlike for the console API when the ordinary literal encoding is UTF-8, invalid code points shouldn't // be replaced when writing to a file. const string temp_file_name_str = temp_file_name(); - FILE* temp_file_stream; - - { - const errno_t fopen_result = fopen_s(&temp_file_stream, temp_file_name_str.c_str(), "w+b"); - assert(fopen_result == 0); - } + FILE* temp_file_stream = checked_fopen_s(temp_file_name_str, "w+b"); using printed_string_type = format_string<>; From 0567a4f150c92f0142457f41df409c5606d53306 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Thu, 25 Apr 2024 15:26:32 -0700 Subject: [PATCH 08/12] Add `FILE*` test coverage, including `println(FILE*)`. --- .../tests/P2093R14_formatted_output/test.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/std/tests/P2093R14_formatted_output/test.cpp b/tests/std/tests/P2093R14_formatted_output/test.cpp index 0d88cd085a..493362cf4f 100644 --- a/tests/std/tests/P2093R14_formatted_output/test.cpp +++ b/tests/std/tests/P2093R14_formatted_output/test.cpp @@ -577,6 +577,20 @@ void test_empty_strings_and_newlines() { println(output_file_stream, "THREE"); } + { + FILE* temp_file_stream = checked_fopen_s(temp_file_name_str, "a"); + + print(temp_file_stream, "space"); + print(temp_file_stream, ""); + print(temp_file_stream, "time\n"); + + println(temp_file_stream, "general"); + println(temp_file_stream); + println(temp_file_stream, "relativity"); + + fclose(temp_file_stream); + } + { ifstream input_file_stream{temp_file_name_str}; @@ -596,6 +610,10 @@ void test_empty_strings_and_newlines() { "TWO", "", "THREE", + "spacetime", + "general", + "", + "relativity", }; assert(lines == expected_lines); From 36dc91fd0d72683245796768e97de1ae81b3d201 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Thu, 25 Apr 2024 15:44:53 -0700 Subject: [PATCH 09/12] Add new console-printing tests at the end, to avoid disrupting earlier coverage. --- .../tests/P2093R14_formatted_output/test.cpp | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/std/tests/P2093R14_formatted_output/test.cpp b/tests/std/tests/P2093R14_formatted_output/test.cpp index 493362cf4f..0cf9224309 100644 --- a/tests/std/tests/P2093R14_formatted_output/test.cpp +++ b/tests/std/tests/P2093R14_formatted_output/test.cpp @@ -511,6 +511,38 @@ void test_stream_flush_console() { const wstring extractedStr{temp_console.get_console_line(0)}; assert(extractedStr == L"Hello, world!"); } + + print(console_file_stream, "kitty"); + println(console_file_stream); + println(console_file_stream, "cat"); + + { + const wstring line0{temp_console.get_console_line(0)}; + const wstring line1{temp_console.get_console_line(1)}; + const wstring line2{temp_console.get_console_line(2)}; + + assert(line0 == L"Hello, world!"); + + if constexpr (_Is_ordinary_literal_encoding_utf8()) { + assert(line1 == L"kitty"); + assert(line2 == L"cat"); + } else { + assert(line1.empty()); + assert(line2.empty()); + } + } + + maybe_flush_console_file_stream(temp_console); + + { + const wstring line0{temp_console.get_console_line(0)}; + const wstring line1{temp_console.get_console_line(1)}; + const wstring line2{temp_console.get_console_line(2)}; + + assert(line0 == L"Hello, world!"); + assert(line1 == L"kitty"); + assert(line2 == L"cat"); + } } void test_stream_flush_file() { From 5a3876d3ba799847154a8452423070a4c9b891f5 Mon Sep 17 00:00:00 2001 From: Hristo Hristov Date: Fri, 26 Apr 2024 16:24:28 +0300 Subject: [PATCH 10/12] Added tests to test blank line printing --- .../tests/P2093R14_formatted_output/test.cpp | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/tests/std/tests/P2093R14_formatted_output/test.cpp b/tests/std/tests/P2093R14_formatted_output/test.cpp index 68b9ff5d28..d0e3dfd21c 100644 --- a/tests/std/tests/P2093R14_formatted_output/test.cpp +++ b/tests/std/tests/P2093R14_formatted_output/test.cpp @@ -600,6 +600,100 @@ void test_empty_strings_and_newlines() { filesystem::remove(temp_file_name_str); } +void test_blank_line() { + // Flush console + { + // If the ordinary literal encoding is UTF-8, then the FILE stream associated with + // a console should always be flushed before writing output during a call to std::println() + // and std::println(). Otherwise, the stream should *NOT* be flushed. + test::win_console temp_console{}; + FILE* const console_file_stream = temp_console.get_file_stream(); + + println(console_file_stream); + + { + const wstring extractedStr{temp_console.get_console_line(0)}; + + if constexpr (_Is_ordinary_literal_encoding_utf8()) { + assert(extractedStr == L""); + } else { + assert(extractedStr.empty()); + } + } + + maybe_flush_console_file_stream(temp_console); + + { + const wstring extractedStr{temp_console.get_console_line(0)}; + assert(extractedStr == L""); + } + } + + // Flush file + { + // Regardless of the ordinary literal encoding, std::println()should flush file streams + // which do not refer to consoles. + const string temp_file_name_str = temp_file_name(); + + { + ofstream output_file_stream{temp_file_name_str}; + + println(output_file_stream); + + { + ifstream input_file_stream{temp_file_name_str}; + + string extracted_line_str; + getline(input_file_stream, extracted_line_str); + + assert(extracted_line_str.empty()); + } + + output_file_stream.flush(); + + { + ifstream input_file_stream{temp_file_name_str}; + + string extracted_line_str; + getline(input_file_stream, extracted_line_str); + + assert(extracted_line_str == ""); + } + } + + filesystem::remove(temp_file_name_str); + } + + { + const string temp_file_name_str = temp_file_name(); + + { + ofstream output_file_stream{temp_file_name_str}; + + println(output_file_stream); + println(output_file_stream); + } + + { + ifstream input_file_stream{temp_file_name_str}; + + vector lines; + for (string str; getline(input_file_stream, str);) { + lines.push_back(str); + } + + const vector expected_lines{ + "", + "" + }; + + assert(lines == expected_lines); + } + + filesystem::remove(temp_file_name_str); + } +} + void all_tests() { test_print_optimizations(); @@ -610,6 +704,8 @@ void all_tests() { test_stream_flush_file(); test_empty_strings_and_newlines(); + + test_blank_line(); } int main(int argc, char* argv[]) { From 2bea3fe1deece2ef0e7360361e0efed8d5036cbe Mon Sep 17 00:00:00 2001 From: Hristo Hristov Date: Fri, 26 Apr 2024 16:32:11 +0300 Subject: [PATCH 11/12] Fixed formatting --- tests/std/tests/P2093R14_formatted_output/test.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/std/tests/P2093R14_formatted_output/test.cpp b/tests/std/tests/P2093R14_formatted_output/test.cpp index e80077e2b5..0317827f89 100644 --- a/tests/std/tests/P2093R14_formatted_output/test.cpp +++ b/tests/std/tests/P2093R14_formatted_output/test.cpp @@ -736,10 +736,7 @@ void test_blank_line() { lines.push_back(str); } - const vector expected_lines{ - "", - "" - }; + const vector expected_lines{"", ""}; assert(lines == expected_lines); } From 87b20ffb8084cdb34473503ee9cd2db849d658f1 Mon Sep 17 00:00:00 2001 From: Hristo Hristov Date: Fri, 26 Apr 2024 16:42:18 +0300 Subject: [PATCH 12/12] Revert changes from previous commit --- .../tests/P2093R14_formatted_output/test.cpp | 93 ------------------- 1 file changed, 93 deletions(-) diff --git a/tests/std/tests/P2093R14_formatted_output/test.cpp b/tests/std/tests/P2093R14_formatted_output/test.cpp index 0317827f89..0cf9224309 100644 --- a/tests/std/tests/P2093R14_formatted_output/test.cpp +++ b/tests/std/tests/P2093R14_formatted_output/test.cpp @@ -654,97 +654,6 @@ void test_empty_strings_and_newlines() { filesystem::remove(temp_file_name_str); } -void test_blank_line() { - // Flush console - { - // If the ordinary literal encoding is UTF-8, then the FILE stream associated with - // a console should always be flushed before writing output during a call to std::println() - // and std::println(). Otherwise, the stream should *NOT* be flushed. - test::win_console temp_console{}; - FILE* const console_file_stream = temp_console.get_file_stream(); - - println(console_file_stream); - - { - const wstring extractedStr{temp_console.get_console_line(0)}; - - if constexpr (_Is_ordinary_literal_encoding_utf8()) { - assert(extractedStr == L""); - } else { - assert(extractedStr.empty()); - } - } - - maybe_flush_console_file_stream(temp_console); - - { - const wstring extractedStr{temp_console.get_console_line(0)}; - assert(extractedStr == L""); - } - } - - // Flush file - { - // Regardless of the ordinary literal encoding, std::println()should flush file streams - // which do not refer to consoles. - const string temp_file_name_str = temp_file_name(); - - { - ofstream output_file_stream{temp_file_name_str}; - - println(output_file_stream); - - { - ifstream input_file_stream{temp_file_name_str}; - - string extracted_line_str; - getline(input_file_stream, extracted_line_str); - - assert(extracted_line_str.empty()); - } - - output_file_stream.flush(); - - { - ifstream input_file_stream{temp_file_name_str}; - - string extracted_line_str; - getline(input_file_stream, extracted_line_str); - - assert(extracted_line_str == ""); - } - } - - filesystem::remove(temp_file_name_str); - } - - { - const string temp_file_name_str = temp_file_name(); - - { - ofstream output_file_stream{temp_file_name_str}; - - println(output_file_stream); - println(output_file_stream); - } - - { - ifstream input_file_stream{temp_file_name_str}; - - vector lines; - for (string str; getline(input_file_stream, str);) { - lines.push_back(str); - } - - const vector expected_lines{"", ""}; - - assert(lines == expected_lines); - } - - filesystem::remove(temp_file_name_str); - } -} - void all_tests() { test_print_optimizations(); @@ -755,8 +664,6 @@ void all_tests() { test_stream_flush_file(); test_empty_strings_and_newlines(); - - test_blank_line(); } int main(int argc, char* argv[]) {