diff --git a/src/lib/test/event-log.hpp b/src/lib/test/event-log.hpp index 671ba3e07..1d1f36b25 100644 --- a/src/lib/test/event-log.hpp +++ b/src/lib/test/event-log.hpp @@ -415,6 +415,18 @@ namespace test{ EventLog& destroy (string text); + /** Qualify the latest entry: set further attribute(s) */ + template + EventLog& + addAttrib (string const& key, X&& initialiser, ARGS&& ...args) + { + REQUIRE (not isnil (*log_)); + mutateInPlace (log_->back()) + .attrib(key,initialiser, std::forward(args)...); + return *this; + } + + /* ==== Iteration ==== */ diff --git a/tests/vault/gear/activity-detector-test.cpp b/tests/vault/gear/activity-detector-test.cpp index 82457260a..105385f49 100644 --- a/tests/vault/gear/activity-detector-test.cpp +++ b/tests/vault/gear/activity-detector-test.cpp @@ -88,7 +88,7 @@ namespace test { CHECK (55 == trap (1.23, Time{FSecs{3,2}})); CHECK (detector == "Rec(EventLogHeader| this = ActivityDetector(spectre) ), " - "Rec(call| fun = trap, this = ActivityDetector(spectre) |{1.23, 0:00:01.500})"_expect); + "Rec(call| fun = trap, this = ActivityDetector(spectre), Seq = 0 |{1.23, 0:00:01.500})"_expect); } @@ -109,14 +109,16 @@ namespace test { detector.markSequence(); fun(rnd); - CHECK (detector.verifyCall ("funny")); - CHECK (detector.verifyCall ("funny").arg(rnd)); - CHECK (detector.verifyInvocation ("funny", Seq(1))); - CHECK (detector.verifyInvocation ("funny", Seq(1), rnd)); + CHECK (detector.verifyInvocation ("funny")); + CHECK (detector.verifyInvocation ("funny").arg(rnd)); + CHECK (detector.verifyInvocation ("funny").seq(2)); + CHECK (detector.verifyInvocation ("funny").arg(rnd).seq(2)); + CHECK (detector.verifyInvocation ("funny").seq(2).arg(rnd)); CHECK (not detector.verifyInvocation ("bunny")); - CHECK (not detector.verifyInvocation ("funny", -rnd)); - CHECK (not detector.verifyInvocation ("funny", Seq(5))); - CHECK (not detector.verifyInvocation ("funny", rnd, Seq(1))); + CHECK (not detector.verifyInvocation ("funny").arg()); + CHECK (not detector.verifyInvocation ("funny").arg(-rnd)); + CHECK (not detector.verifyInvocation ("funny").seq(5)); + CHECK (not detector.verifyInvocation ("funny").arg(rnd).seq(1)); } diff --git a/tests/vault/gear/activity-detector.hpp b/tests/vault/gear/activity-detector.hpp index 9d705cc89..db2ee686d 100644 --- a/tests/vault/gear/activity-detector.hpp +++ b/tests/vault/gear/activity-detector.hpp @@ -155,12 +155,6 @@ namespace test { operator bool() const { return _Parent::operator bool(); } - template - ActivityMatch& - arg (ARGS const& ...args) - { - return delegate (&EventMatch::arg, args...); - } // EventMatch& locate (string match); // EventMatch& locateMatch (string regExp); @@ -175,7 +169,7 @@ namespace test { // EventMatch& beforeMatch (string regExp); // EventMatch& beforeEvent (string match); // EventMatch& beforeEvent (string classifier, string match); - ActivityMatch& beforeCall (string match) { return delegate (&EventMatch::beforeCall, move(match)); } + ActivityMatch& beforeInvocation (string match) { return delegate (&EventMatch::beforeCall, move(match)); } // // // /* query builders to find a match stepping backwards */ @@ -186,6 +180,22 @@ namespace test { // EventMatch& afterEvent (string classifier, string match); // EventMatch& afterCall (string match); + /** qualifier: additionally match the function arguments */ + template + ActivityMatch& + arg (ARGS const& ...args) + { + return delegate (&EventMatch::arg, args...); + } + + /** qualifier: additionally require the indicated sequence number */ + ActivityMatch& + seq (uint seqNr) + { + _Parent::attrib (MARK_SEQ, util::toString (seqNr)); + return *this; + } + private: template ActivityMatch& @@ -219,12 +229,14 @@ namespace test { string id_; EventLog* log_; + Seq const* seqNr_; RetVal retVal_; public: - DiagnosticFun (string id, EventLog& masterLog) + DiagnosticFun (string id, EventLog& masterLog, Seq const& seqNr) : id_{id} , log_{&masterLog} + , seqNr_{&seqNr} , retVal_{} { } @@ -241,7 +253,8 @@ namespace test { RET operator() (ARGS const& ...args) { - log_->call (log_->getID(), id_, args...); + log_->call (log_->getID(), id_, args...) + .addAttrib (MARK_SEQ, *seqNr_); return *retVal_; } }; @@ -305,43 +318,26 @@ namespace test { using SigTypes = typename lib::meta::Prepend::Seq; using Functor = typename RebindVariadic::Type; - return Functor{id, eventLog_}; + return Functor{id, eventLog_, invocationSeq_}; } - template - bool - verifyInvocation (string fun, Seq const& seq, ARGS const& ...args) - { - bool valid = eventLog_.verifyEvent(seq).id(MARK_INC) - .beforeCall(fun).arg(args...) - .beforeEvent(seq).id(MARK_SEQ); - if (not valid) - { - cerr << "FAIL___Function_invocation___________" - << "\nfunction:"< - bool - verifyInvocation (string fun, ARGS const& ...args) - { - return verifyInvocation (fun, invocationSeq_, args...); - } ActivityMatch - verifyCall (string fun) + verifyInvocation (string fun) { return ActivityMatch{move (eventLog_.verifyCall(fun))}; } + string + getLog() const + { + return "\n_______Event-Log_____________________\n" + + util::join (eventLog_, "\n") + + "\n───────╼━━━━━━━━╾────────────────────" + ; + } + private: }; diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index 3c28461b3..4ed5980b3 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -81743,7 +81743,8 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- + + @@ -81782,19 +81783,88 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- + + + + + + +

+ ...das war vom Design her nicht vorgesehen, und wäre auch nicht ganz einfach zu realisieren; man müßte den EventMatch per CRTP definieren (und damit müßte er Header-only sein, mit den bekannten Folgen für die Größe des Debug-Build) +

+ +
+ +
+ + + + +

+ ...denn dies hier ist ein geschlossenes Ökosystem; daher ist sichergestellt, daß *this stets ein ActivityMatch ist +

+ +
+
+ + + + + +
+ + + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -81807,7 +81877,24 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
+ + + + + + +

+ Der Ansatz, alles ein einen Prüf-Aufruf zu packen, ist insgeseamt ungeschickt; genau deshalb wurde doch für das EventLog dieser komplizierte Builder / Verfeinerungs-Ansatz gemacht: darüber kann man ganz natürlich ausdrücken, wenn man etwas über die Argumente speziell geprüft haben möchte, oder eben nicht... +

+ +
+ +
+
+
+ +