Testing: count failures independently of assertion retention (X-QA-02)

This commit is contained in:
faumaray committed 2026-12-03 16:41:16 +03:00
1 parent 62c2082fb3
commit 430deab07a
4 files changed
+36 -6

No files matched your search

+3
View File
@@ -60,6 +60,9 @@ namespace Void::Testing
std::vector<std::string> 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;
};
+1
View File
@@ -34,6 +34,7 @@ void handle_assertion(AssertionResult result)
if (!passed) {
tr->state = TestState::Failed;
++tr->failed_assertions;
}
const std::size_t entry_bytes =
+8 -6
View File
@@ -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();
@@ -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;