From 167676a1c53eddd646b09a4e5a1810ee32b265d0 Mon Sep 17 00:00:00 2001 From: "Otto C." <12378062+ILer32@users.noreply.github.com> Date: Mon, 22 Dec 2025 19:06:15 +0800 Subject: [PATCH 1/4] improve the result formatting and remove the repeated messages --- include/boost/ut.hpp | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/include/boost/ut.hpp b/include/boost/ut.hpp index 0e260906..d6093da9 100644 --- a/include/boost/ut.hpp +++ b/include/boost/ut.hpp @@ -1736,10 +1736,12 @@ class reporter_junit { } auto on(events::test_end test_event) -> void { + active_scope_->report_string += ss_out_.str(); if (active_scope_->fails > 0) { - reset_printer(); + if (report_type_ == CONSOLE) { + lcout_ << ss_out_.str(); + } } else { - active_scope_->report_string = ss_out_.str(); if (report_type_ == CONSOLE) { if (detail::cfg::show_successful_tests) { if (!active_scope_->nested_tests->empty()) { @@ -1750,10 +1752,10 @@ class reporter_junit { ss_out_ << color_.pass << "PASSED" << color_.none; print_duration(ss_out_); lcout_ << ss_out_.str(); - reset_printer(); } } } + reset_printer(); active_scope_->n_tests = 1LU; if (active_scope_->fails > 0 || active_scope_->fail_tests > 0) { active_scope_->fail_tests = 1LU; @@ -1788,9 +1790,6 @@ class reporter_junit { template auto on(events::log log) -> void { ss_out_ << log.msg; - if (report_type_ == CONSOLE) { - lcout_ << log.msg; - } } auto on(events::exception exception) -> void { @@ -1828,23 +1827,27 @@ class reporter_junit { TPrinter ss{}; ss << ss_out_.str(); if (report_type_ == CONSOLE) { - ss << color_.fail << "FAILED\n" << color_.none; + ss << "\n"; + if (active_test_.size()) { + ss << std::string((2 * active_test_.size()) - 2, ' '); + } + ss << color_.fail << "FAILED " << color_.none; print_duration(ss); } ss << "in: " << assertion.location.file_name() << ':' << assertion.location.line(); ss << color_.fail << " - test condition: "; - ss << " [" << std::boolalpha << assertion.expr; + ss << '[' << std::boolalpha << assertion.expr; ss << color_.fail << ']' << color_.none; active_scope_->report_string += ss.str(); active_scope_->fails++; active_scope_->assertions++; reset_printer(); if (report_type_ == CONSOLE) { - lcout_ << active_scope_->report_string << "\n\n"; + lcout_ << ss.str(); } if (detail::cfg::abort_early || - active_scope_->fails >= detail::cfg::abort_after_n_failures) { + active_scope_->fails >= detail::cfg::abort_after_n_failures) { std::cerr << "early abort for test : " << active_test_.top() << "after "; std::cerr << active_scope_->fails << " failures total." << std::endl; std::exit(-1); @@ -1866,6 +1869,7 @@ class reporter_junit { : std::cout); return; } + lcout_ << ss_out_.str(); print_console_summary( detail::cfg::output_filename != "" ? maybe_of : std::cout, detail::cfg::output_filename != "" ? maybe_of : std::cerr); @@ -1886,12 +1890,13 @@ class reporter_junit { void print_console_summary(std::ostream& out_stream, std::ostream& err_stream) { + for (const auto& [suite_name, suite_result] : results_) { if (suite_result.fails) { err_stream << "\n========================================================" "=======================\n" - << "Suite " << suite_name << '\n' // + << "Suite " << suite_name << '\n' << "tests: " << (suite_result.n_tests) << " | " << (suite_result.fail_tests > 0 ? color_.fail : color_.none) << suite_result.fail_tests << " failed" << color_.none << '\n' @@ -1899,17 +1904,16 @@ class reporter_junit { << suite_result.passed << " passed" << " | " << color_.fail << suite_result.fails << " failed" << color_.none << '\n'; - std::cerr << std::endl; + //std::cerr << std::endl; } else { - out_stream << color_.pass << "Suite '" << suite_name + out_stream << color_.pass << "\nSuite '" << suite_name << "': all tests passed" << color_.none << " (" << suite_result.assertions << " asserts in " - << suite_result.n_tests << " tests)\n"; + << suite_result.n_tests << " tests)"; if (suite_result.skipped) { std::cout << suite_result.skipped << " tests skipped\n"; } - std::cout.flush(); } } @@ -2319,7 +2323,7 @@ struct log { struct next { template auto& operator<<(const TMsg& msg) { - on(events::log{' '}); + //on(events::log{' '}); on(events::log{msg}); return *this; } @@ -2327,7 +2331,7 @@ struct log { template auto operator<<(const TMsg& msg) -> next { - on(events::log{'\n'}); + //on(events::log{'\n'}); on(events::log{msg}); return next{}; } From a545322dfa6ad17b54b6a7807aa392d2de41f28c Mon Sep 17 00:00:00 2001 From: "Otto C." <12378062+ILer32@users.noreply.github.com> Date: Mon, 22 Dec 2025 20:06:03 +0800 Subject: [PATCH 2/4] skip empty suite_result --- include/boost/ut.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/boost/ut.hpp b/include/boost/ut.hpp index d6093da9..b1313123 100644 --- a/include/boost/ut.hpp +++ b/include/boost/ut.hpp @@ -1905,12 +1905,11 @@ class reporter_junit { << " | " << color_.fail << suite_result.fails << " failed" << color_.none << '\n'; //std::cerr << std::endl; - } else { + } else if (suite_result.assertions || suite_result.n_tests || suite_result.skipped) { out_stream << color_.pass << "\nSuite '" << suite_name << "': all tests passed" << color_.none << " (" << suite_result.assertions << " asserts in " << suite_result.n_tests << " tests)"; - if (suite_result.skipped) { std::cout << suite_result.skipped << " tests skipped\n"; } From 1d03448766c78c251f67f98388cf3f757ae919e2 Mon Sep 17 00:00:00 2001 From: "Otto C." <12378062+ILer32@users.noreply.github.com> Date: Tue, 23 Dec 2025 10:23:05 +0800 Subject: [PATCH 3/4] improve the result formatting --- include/boost/ut.hpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/include/boost/ut.hpp b/include/boost/ut.hpp index b1313123..af364595 100644 --- a/include/boost/ut.hpp +++ b/include/boost/ut.hpp @@ -1780,7 +1780,7 @@ class reporter_junit { if (report_type_ == CONSOLE) { lcout_ << '\n' << std::string((2 * active_test_.size()) - 2, ' '); lcout_ << "Running \"" << test_event.name << "\"... "; - lcout_ << color_.skip << "SKIPPED" << color_.none << '\n'; + lcout_ << color_.skip << "SKIPPED" << color_.none; } reset_printer(); pop_scope(test_event.name); @@ -1903,7 +1903,7 @@ class reporter_junit { << "asserts: " << (suite_result.assertions) << " | " << suite_result.passed << " passed" << " | " << color_.fail << suite_result.fails << " failed" - << color_.none << '\n'; + << color_.none; //std::cerr << std::endl; } else if (suite_result.assertions || suite_result.n_tests || suite_result.skipped) { out_stream << color_.pass << "\nSuite '" << suite_name @@ -1911,7 +1911,7 @@ class reporter_junit { << suite_result.assertions << " asserts in " << suite_result.n_tests << " tests)"; if (suite_result.skipped) { - std::cout << suite_result.skipped << " tests skipped\n"; + std::cout << "; " << suite_result.skipped << " tests skipped"; } std::cout.flush(); } @@ -2032,13 +2032,15 @@ class runner { }; public: - constexpr runner() = default; + constexpr runner() { + std::cout << "UT starts ========================================================" + "============="; + }; constexpr runner(TReporter reporter, std::size_t suites_size) : reporter_{std::move(reporter)}, suites_(suites_size) {} ~runner() { const auto should_run = not run_; - if (should_run) { static_cast(run()); } @@ -2046,7 +2048,8 @@ class runner { if (not dry_run_) { report_summary(); } - + std::cout << "\n========================================================" + "======================="; if (should_run and fails_) { std::exit(-1); } From f6eec1ea6fc211a6fd401fc9c8eb77739ec49a0f Mon Sep 17 00:00:00 2001 From: "Otto C." <12378062+ILer32@users.noreply.github.com> Date: Tue, 23 Dec 2025 18:30:09 +0800 Subject: [PATCH 4/4] recover log operator<< and improve the formatting --- include/boost/ut.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/boost/ut.hpp b/include/boost/ut.hpp index af364595..392ebe29 100644 --- a/include/boost/ut.hpp +++ b/include/boost/ut.hpp @@ -2048,8 +2048,8 @@ class runner { if (not dry_run_) { report_summary(); } - std::cout << "\n========================================================" - "======================="; + std::cout << "\nCompleted ==============================================" + "=======================\n"; if (should_run and fails_) { std::exit(-1); } @@ -2325,7 +2325,7 @@ struct log { struct next { template auto& operator<<(const TMsg& msg) { - //on(events::log{' '}); + on(events::log{' '}); on(events::log{msg}); return *this; } @@ -2333,7 +2333,7 @@ struct log { template auto operator<<(const TMsg& msg) -> next { - //on(events::log{'\n'}); + on(events::log{'\n'}); on(events::log{msg}); return next{}; }