Files

3.4 KiB

Task Spec: M-TESTINGMOCK-01..04 — Deterministic Sessions, Action-Outside-Lock, Move-Only Forwarding & Matcher Combinators

  • Branch: feat/roadmap-p2-wave9 (baseline main at 3e25405).
  • Roadmap authority: docs/roadmap/modules/TestingMock.md (M-TESTINGMOCK-01..M-TESTINGMOCK-04), ARCHITECTURE.md C-02..C-05.
  • Error domain: Void::Result::kTestingMockErrorDomain = 27.

Scope & Deliverables

  1. Preserve 1.x API & Existing Tests:
    • Existing Mock<Derived>, MockBase, MockFunction<R(Args...)>, Matcher<T>, Eq, _, Lt, Le, Gt, Ge, Range, Pred, StartsWith, Contains, and all existing tests under tests/standalone/TestingMock/ continue compiling and passing unchanged.
  2. Matcher Combinators (include/Void/TestingMock/Matcher.hpp):
    • Add Ne, EndsWith, Not, AllOf, AnyOf, IsNull, NotNull, with bounded description/nesting depth (kMaxMatcherDepth = 32).
  3. Explicit Session, Sequences, Limits & Tokens (include/Void/TestingMock/Session.hpp):
    • Concurrency::{SingleThread, ConcurrentActions}.
    • MockLimits{max_expectations = 1024, max_matchers = 64, max_events = 4096, max_diagnostic_bytes = 4 MiB, max_arg_render_bytes = 4 KiB} (zero means zero capacity, never unlimited).
    • Sequence: explicit per-group call ordering independent of global registration order.
    • Verification: structured report (ok(), unmet, excess, unmatched, prohibited, matcher_errors, threading_errors, events_truncated, total_events, format()), idempotent across repeated calls.
    • MockSession: freeze(Concurrency) (mutating a frozen session returns ErrorKind::invalid_argument / InvalidState), verify_and_close() (drains/joins active calls; returns WouldDeadlock if called from inside an active action), bounded event log with truncation tracking, RAII RegistrationToken stopping admission and waiting for admitted calls on unregister.
  4. Hardened Expectation & SessionMockFunction (include/Void/TestingMock/Expectation.hpp, include/Void/TestingMock/MockFunction.hpp):
    • Action-outside-lock reservation protocol: snapshot immutable candidates under short lock -> evaluate matchers outside lock (catching matcher exceptions as MatcherFailure) -> reacquire lock to reserve matching unsaturated expectation & sequence slot -> release lock -> execute action -> decrement in-flight counter & record completion.
    • Same-thread reentrant calls succeed in SingleThread; cross-thread concurrent entry in SingleThread reports deterministic threading violation; ConcurrentActions permits concurrent action execution safely.
    • Perfect argument forwarding (Args&&...) to actions; returns_once(U&&) for move-only return types (std::unique_ptr), invokes_once(F&&) for one-shot move-only callables, at_least(n), at_most(n), between(min, max), never() (checked before ordinary candidates), in_sequence(Sequence&).
    • Non-default-constructible return type on unmatched call records failure and throws TestingMock's invocation-abort exception (never R{} fallback).
  5. Installed Consumer (tests/package/TestingMockOnly/):
    • Register TestingMockOnly in tests/package/InstalledComponents.cmake with _no_external_deps.

Verification

  • Standalone TestingMock;Testing (-DVOID_WARNINGS_AS_ERRORS=ON), ctest TestingMockOnly, Debug ASan+UBSan, Debug TSan (concurrent action reservation & dynamic unregister races).