3.4 KiB
3.4 KiB
Task Spec: M-TESTINGMOCK-01..04 — Deterministic Sessions, Action-Outside-Lock, Move-Only Forwarding & Matcher Combinators
- Branch:
feat/roadmap-p2-wave9(baselinemainat3e25405). - Roadmap authority:
docs/roadmap/modules/TestingMock.md(M-TESTINGMOCK-01..M-TESTINGMOCK-04),ARCHITECTURE.mdC-02..C-05. - Error domain:
Void::Result::kTestingMockErrorDomain = 27.
Scope & Deliverables
- 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 undertests/standalone/TestingMock/continue compiling and passing unchanged.
- Existing
- Matcher Combinators (
include/Void/TestingMock/Matcher.hpp):- Add
Ne,EndsWith,Not,AllOf,AnyOf,IsNull,NotNull, with bounded description/nesting depth (kMaxMatcherDepth = 32).
- Add
- 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 returnsErrorKind::invalid_argument/InvalidState),verify_and_close()(drains/joins active calls; returnsWouldDeadlockif called from inside an active action), bounded event log with truncation tracking, RAIIRegistrationTokenstopping admission and waiting for admitted calls on unregister.
- 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 inSingleThreadreports deterministic threading violation;ConcurrentActionspermits 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).
- Action-outside-lock reservation protocol: snapshot immutable candidates under short lock -> evaluate matchers outside lock (catching matcher exceptions as
- Installed Consumer (
tests/package/TestingMockOnly/):- Register
TestingMockOnlyintests/package/InstalledComponents.cmakewith_no_external_deps.
- Register
Verification
- Standalone
TestingMock;Testing(-DVOID_WARNINGS_AS_ERRORS=ON),ctestTestingMockOnly, DebugASan+UBSan, DebugTSan(concurrent action reservation & dynamic unregister races).