feat(Testing): add per-run owned reporters, strict config validation, FailureCapture, subprocess isolation, and deterministic property/schedule harness (M-TESTING-02, M-TESTING-03)
This commit is contained in:
1 parent
1b3331e3a8
commit
de8a981893
11 files changed
+1712
-55
No files matched your search
+55
-13
@@ -1,17 +1,59 @@
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
namespace Void::Testing::Detail {
|
||||
void handle_assertion(AssertionResult result) {
|
||||
|
||||
#include <atomic>
|
||||
|
||||
namespace Void::Testing::Detail
|
||||
{
|
||||
namespace
|
||||
{
|
||||
std::atomic<std::size_t> g_stray_assertions{0};
|
||||
} // namespace
|
||||
|
||||
std::size_t stray_assertion_count() noexcept
|
||||
{
|
||||
return g_stray_assertions.load(std::memory_order_acquire);
|
||||
}
|
||||
|
||||
void reset_stray_assertion_count() noexcept
|
||||
{
|
||||
g_stray_assertions.store(0, std::memory_order_release);
|
||||
}
|
||||
|
||||
void handle_assertion(AssertionResult result)
|
||||
{
|
||||
auto& ctx = TestContext::current();
|
||||
if (ctx.current_result) {
|
||||
ctx.current_result->assertions.push_back(std::move(result));
|
||||
const auto& last = ctx.current_result->assertions.back();
|
||||
if (!last.passed) {
|
||||
ctx.current_result->state = TestState::Failed;
|
||||
if (last.kind == AssertKind::Require || last.kind == AssertKind::Assert) {
|
||||
ctx.should_abort = true;
|
||||
throw RequireFailure{last.message};
|
||||
}
|
||||
}
|
||||
if (!ctx.current_result) {
|
||||
g_stray_assertions.fetch_add(1, std::memory_order_acq_rel);
|
||||
return;
|
||||
}
|
||||
|
||||
TestResult* tr = ctx.current_result;
|
||||
const bool passed = result.passed;
|
||||
const AssertKind kind = result.kind;
|
||||
std::string abort_msg = result.message;
|
||||
|
||||
if (!passed) {
|
||||
tr->state = TestState::Failed;
|
||||
}
|
||||
|
||||
const std::size_t entry_bytes =
|
||||
result.expression.size() +
|
||||
result.expected_repr.size() +
|
||||
result.actual_repr.size() +
|
||||
result.message.size() + 64;
|
||||
|
||||
if (tr->assertions.size() < kMaxRetainedAssertionsPerTest &&
|
||||
tr->diagnostic_bytes + entry_bytes <= kMaxDiagnosticBytesPerTest) {
|
||||
tr->diagnostic_bytes += entry_bytes;
|
||||
tr->assertions.push_back(std::move(result));
|
||||
} else {
|
||||
tr->assertions_truncated = true;
|
||||
tr->dropped_assertions += 1;
|
||||
}
|
||||
|
||||
if (!passed && (kind == AssertKind::Require || kind == AssertKind::Assert)) {
|
||||
ctx.should_abort = true;
|
||||
throw RequireFailure{abort_msg};
|
||||
}
|
||||
}
|
||||
} // namespace Void::Testing::Detail
|
||||
} // namespace Void::Testing::Detail
|
||||
Reference in new issue
Block a user