From 430deab07aae64e7247a581e900b7b6c302b177c Mon Sep 17 00:00:00 2001 From: "Aleksei (Faumaray) Selikhov" Date: Thu, 3 Dec 2026 16:41:16 +0300 Subject: [PATCH] Testing: count failures independently of assertion retention (X-QA-02) --- include/Void/Testing/Config.hpp | 3 +++ src/Testing/Assert.cpp | 1 + src/Testing/Runner.cpp | 14 ++++++----- .../standalone/Testing/FrameworkHardening.cpp | 24 +++++++++++++++++++ 4 files changed, 36 insertions(+), 6 deletions(-) diff --git a/include/Void/Testing/Config.hpp b/include/Void/Testing/Config.hpp index 81e3d70..3f0ce11 100644 --- a/include/Void/Testing/Config.hpp +++ b/include/Void/Testing/Config.hpp @@ -60,6 +60,9 @@ namespace Void::Testing std::vector tags; bool assertions_truncated{false}; std::size_t dropped_assertions{0}; + // Counted at record time, so failures beyond the bounded assertion + // retention still determine the test outcome. + std::size_t failed_assertions{0}; std::size_t diagnostic_bytes{0}; std::string cleanup_error; }; diff --git a/src/Testing/Assert.cpp b/src/Testing/Assert.cpp index 66d99e2..85e6313 100644 --- a/src/Testing/Assert.cpp +++ b/src/Testing/Assert.cpp @@ -34,6 +34,7 @@ void handle_assertion(AssertionResult result) if (!passed) { tr->state = TestState::Failed; + ++tr->failed_assertions; } const std::size_t entry_bytes = diff --git a/src/Testing/Runner.cpp b/src/Testing/Runner.cpp index 69ea215..102ff76 100644 --- a/src/Testing/Runner.cpp +++ b/src/Testing/Runner.cpp @@ -115,6 +115,12 @@ namespace Void::Testing return false; } } + // Failures are counted when recorded (TestResult::failed_assertions), + // independently of the bounded assertion vector kept for reporting. + [[nodiscard]] bool has_recorded_failure(const TestResult& result) noexcept + { + return result.failed_assertions > 0; + } } // namespace RunConfig Runner::parse_args(int argc, char** argv) @@ -325,9 +331,7 @@ namespace Void::Testing if (result.state != TestState::Skipped && result.state != TestState::Crashed) { - bool any = std::any_of( - result.assertions.begin(), result.assertions.end(), - [](const auto& a) { return !a.passed; }); + const bool any = has_recorded_failure(result); // An exception that escaped the body fails it too, with no failed // assertion recorded. const bool unhandled = !result.crash_info.empty() || !result.cleanup_error.empty(); @@ -376,9 +380,7 @@ namespace Void::Testing if (result.state != TestState::Skipped && result.state != TestState::Crashed) { - bool any = std::any_of( - result.assertions.begin(), result.assertions.end(), - [](const auto& a) { return !a.passed; }); + const bool any = has_recorded_failure(result); // An exception that escaped the body fails it too, with no failed // assertion recorded. const bool unhandled = !result.crash_info.empty() || !result.cleanup_error.empty(); diff --git a/tests/standalone/Testing/FrameworkHardening.cpp b/tests/standalone/Testing/FrameworkHardening.cpp index 2ba9904..6138938 100644 --- a/tests/standalone/Testing/FrameworkHardening.cpp +++ b/tests/standalone/Testing/FrameworkHardening.cpp @@ -67,6 +67,30 @@ Void::Testing::Test testing_failure_capture_and_bounded_assertions() } } +Void::Testing::Test testing_runner_counts_failure_after_retention_cap() +{ + using namespace Void::Testing; + + // A failure recorded after kMaxRetainedAssertionsPerTest is dropped from the + // bounded assertion report, but it must still fail the executed test. + TestCase tc{ + .run = + [] { + for (std::size_t i = 0; i < kMaxRetainedAssertionsPerTest; ++i) { + expect(true); + } + expect(false); + }, + .name = "failure_after_retention_cap", + .suite = "HardeningRunner", + }; + const TestResult res = Runner::instance().execute_case(tc); + expect(res.state == TestState::Failed); + expect(res.assertions_truncated); + expect_eq(res.assertions.size(), kMaxRetainedAssertionsPerTest); + expect_eq(res.dropped_assertions, std::size_t{1}); +} + Void::Testing::Test testing_fixture_single_teardown_and_cleanup_error() { using namespace Void::Testing;