From a97584f73196c109dbc87c91c59f58494c6eae99 Mon Sep 17 00:00:00 2001 From: "Otto C." <12378062+ILer32@users.noreply.github.com> Date: Fri, 19 Dec 2025 20:47:37 +0800 Subject: [PATCH 1/5] correct the passed number --- include/boost/ut.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/ut.hpp b/include/boost/ut.hpp index b39e964d..cf588f83 100644 --- a/include/boost/ut.hpp +++ b/include/boost/ut.hpp @@ -1741,7 +1741,6 @@ class reporter_junit { reset_printer(); } else { active_scope_->report_string = ss_out_.str(); - active_scope_->passed += 1LU; if (report_type_ == CONSOLE) { if (detail::cfg::show_successful_tests) { if (!active_scope_->nested_tests->empty()) { @@ -1819,6 +1818,7 @@ class reporter_junit { template auto on(events::assertion_pass) -> void { active_scope_->assertions++; + active_scope_->passed++; } template From 7b1101b517c2dae2f402cd1fdead9091e3e0164a Mon Sep 17 00:00:00 2001 From: "Otto C." <12378062+ILer32@users.noreply.github.com> Date: Fri, 19 Dec 2025 20:49:29 +0800 Subject: [PATCH 2/5] correct the asserts number --- include/boost/ut.hpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/include/boost/ut.hpp b/include/boost/ut.hpp index cf588f83..6e3c88b2 100644 --- a/include/boost/ut.hpp +++ b/include/boost/ut.hpp @@ -1652,9 +1652,6 @@ class reporter_junit { } else { active_scope_->status = active_scope_->fails > 0 ? "FAILED" : "PASSED"; } - active_scope_->assertions = - active_scope_->assertions + active_scope_->fails; - if (active_test_.top() == test_name) { active_test_.pop(); auto old_scope = active_scope_; @@ -1836,6 +1833,7 @@ class reporter_junit { 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"; From c38c2c589c5ffe6c83fb817ce668c307c151d10e Mon Sep 17 00:00:00 2001 From: "Otto C." <12378062+ILer32@users.noreply.github.com> Date: Fri, 19 Dec 2025 20:54:26 +0800 Subject: [PATCH 3/5] Disable fail++ to prevent counting fatal fail 2 times --- include/boost/ut.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/ut.hpp b/include/boost/ut.hpp index 6e3c88b2..7ac2d7fa 100644 --- a/include/boost/ut.hpp +++ b/include/boost/ut.hpp @@ -1846,7 +1846,7 @@ class reporter_junit { } } - auto on(const events::fatal_assertion&) -> void { active_scope_->fails++; } + auto on(const events::fatal_assertion&) -> void { /*active_scope_->fails++;*/ } auto on(events::summary) -> void { std::cout.flush(); From 079d48801d501e40a5b5610c975cb53b7776595c Mon Sep 17 00:00:00 2001 From: "Otto C." <12378062+ILer32@users.noreply.github.com> Date: Fri, 19 Dec 2025 21:00:51 +0800 Subject: [PATCH 4/5] correct total and failed n_tests number --- include/boost/ut.hpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/include/boost/ut.hpp b/include/boost/ut.hpp index 7ac2d7fa..0e260906 100644 --- a/include/boost/ut.hpp +++ b/include/boost/ut.hpp @@ -1603,6 +1603,7 @@ class reporter_junit { timePoint run_start = clock_ref::now(); timePoint run_stop = clock_ref::now(); std::size_t n_tests = 0LU; + std::size_t fail_tests = 0LU; std::size_t assertions = 0LU; std::size_t passed = 0LU; std::size_t skipped = 0LU; @@ -1660,7 +1661,8 @@ class reporter_junit { } else { active_scope_ = &results_[std::string{"global"}]; } - active_scope_->n_tests += old_scope->n_tests + 1LU; + active_scope_->n_tests += old_scope->n_tests; + active_scope_->fail_tests += old_scope->fail_tests; active_scope_->assertions += old_scope->assertions; active_scope_->passed += old_scope->passed; active_scope_->skipped += old_scope->skipped; @@ -1752,7 +1754,10 @@ class reporter_junit { } } } - + active_scope_->n_tests = 1LU; + if (active_scope_->fails > 0 || active_scope_->fail_tests > 0) { + active_scope_->fail_tests = 1LU; + } pop_scope(test_event.name); } @@ -1887,8 +1892,9 @@ class reporter_junit { << "\n========================================================" "=======================\n" << "Suite " << suite_name << '\n' // - << "tests: " << (suite_result.n_tests) << " | " << color_.fail - << suite_result.fails << " failed" << color_.none << '\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" From b9c2d794e01424297952719704478fcb1cdfbb59 Mon Sep 17 00:00:00 2001 From: "Otto C." <12378062+ILer32@users.noreply.github.com> Date: Fri, 19 Dec 2025 21:21:04 +0800 Subject: [PATCH 5/5] correct sample codes and results --- README.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index fb1c5936..6231392b 100644 --- a/README.md +++ b/README.md @@ -312,8 +312,8 @@ expect(1_i == 2); // not executed ``` main.cpp:6:FAILED [1 == 2] =============================================================================== -tests: 1 | 1 failed -asserts: 2 | 0 passed | 2 failed +tests: 0 | 0 failed +asserts: 1 | 0 passed | 1 failed ``` > https://godbolt.org/z/WMe8Y1 @@ -364,8 +364,8 @@ in: main.cpp:6 - test condition: [1 == 2] fatal assertion =============================================================================== -tests: 0 | 2 failed -asserts: 0 | 0 passed | 2 failed +tests: 0 | 0 failed +asserts: 1 | 0 passed | 1 failed ``` > I use `std::expected`, can I stream its `error()` upon failure? @@ -387,8 +387,8 @@ in: main.cpp:12 - test condition: [false] lazy evaluated =============================================================================== -tests: 1 | 2 failed -asserts: 0 | 0 passed | 2 failed +tests: 1 | 1 failed +asserts: 1 | 0 passed | 1 failed ``` > https://godbolt.org/z/v2PDuU @@ -463,7 +463,7 @@ int main() { v.resize(0); expect(0_ul == std::size(v)); }; - } + }; } ``` @@ -1041,9 +1041,9 @@ All tests passed (2 asserts in 2 tests) ```cpp "logging"_test = [] { - log << "pre"; + boost::ut::log << "pre"; expect(42_i == 43) << "message on failure"; - log << "post"; + boost::ut::log << "post"; }; ``` @@ -1071,9 +1071,9 @@ This requires using C++20 with a standard library with std::format support. ```cpp "logging"_test = [] { - log("\npre {} == {}\n", 42, 43); + boost::ut::log("\npre {} == {}\n", 42, 43); expect(42_i == 43) << "message on failure"; - log("\npost {} == {} -> {}\n", 42, 43, 42 == 43); + boost::ut::log("\npost {} == {} -> {}\n", 42, 43, 42 == 43); }; ```