diff --git a/include/boost/ut.hpp b/include/boost/ut.hpp index 0e260906..392ebe29 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; @@ -1778,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); @@ -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,30 +1890,29 @@ 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' << "asserts: " << (suite_result.assertions) << " | " << suite_result.passed << " passed" << " | " << color_.fail << suite_result.fails << " failed" - << color_.none << '\n'; - std::cerr << std::endl; - } else { - out_stream << color_.pass << "Suite '" << suite_name + << 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 << "': 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 << "; " << suite_result.skipped << " tests skipped"; } - std::cout.flush(); } } @@ -2029,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()); } @@ -2043,7 +2048,8 @@ class runner { if (not dry_run_) { report_summary(); } - + std::cout << "\nCompleted ==============================================" + "=======================\n"; if (should_run and fails_) { std::exit(-1); }