55 using Filter = decltype( buildSearchFilter (std::declval<Log const&>()) );
58 using RExSeq = std::vector<std::regex>;
64 return [=](Entry
const&
entry)
66 return contains (
string(
entry), match);
71 findRegExp (
string regExpDef)
73 std::regex regExp(regExpDef);
74 return [=](Entry
const&
entry)
76 return std::regex_search(
string(
entry), regExp);
81 findEvent (
string match)
83 return [=](Entry
const&
entry)
85 return (
entry.getType() ==
"event" 86 or
entry.getType() ==
"error" 87 or
entry.getType() ==
"create" 88 or
entry.getType() ==
"destroy" 89 or
entry.getType() ==
"logJoin" 91 and not isnil(
entry.scope())
92 and contains (*
entry.scope(), match);
97 findEvent (
string classifier,
string match)
99 return [=](Entry
const&
entry)
101 return (
entry.getType() == classifier
102 or (
entry.hasAttribute(
"ID") and contains (
entry.get(
"ID"), classifier))
104 and not isnil(
entry.scope())
105 and contains (*
entry.scope(), match);
110 findCall (
string match)
112 return [=](Entry
const&
entry)
114 return entry.getType() ==
"call" 115 and contains (
entry.get(
"fun"), match);
131 return [=](Entry
const&
entry)
133 auto scope =
entry.scope();
134 for (
auto const& match : argSeq)
135 if (isnil (scope) or not contains(*scope, match))
148 return [=](Entry
const&
entry)
150 return idx <
entry.childSize()
151 and contains (
entry.child(idx), match);
168 return [=](Entry
const&
entry)
170 auto scope =
entry.scope();
171 for (
auto const& rex : regExpSeq)
173 if (isnil (scope))
return false;
174 while (scope and std::regex_search(*scope, rex))
187 return [=](Entry
const&
entry)
189 return contains (
entry.getType(), typeID);
198 return [=](Entry
const&
entry)
200 return entry.hasAttribute(key);
209 return [=](Entry
const&
entry)
211 return entry.hasAttribute(key)
212 and contains (
entry.get(key), valueMatch);
221 FORWARD, BACKWARD, CURRENT
224 template<
typename COND>
226 attachNextSerchStep (Filter& solution, COND&& searchCond, Direction direction)
228 if (CURRENT == direction)
229 solution.search (forward<COND> (searchCond));
231 solution.addStep ([predicate{forward<COND> (searchCond)}, direction]
234 filter.reverse (BACKWARD == direction);
237 filter.setNewFilter (predicate);
241 template<
typename COND>
243 refineSerach (Filter& solution, COND&& additionalCond)
245 solution.addStep ([predicate{forward<COND> (additionalCond)}]
248 filter.andFilter (predicate);
259 : solution_{buildSearchFilter (srcSeq)}
323 attachNextSerchStep (
solution_, find(match), CURRENT);
334 attachNextSerchStep (
solution_, findRegExp(regExp), CURRENT);
347 attachNextSerchStep (
solution_, findEvent(match), CURRENT);
355 attachNextSerchStep (
solution_, findEvent(classifier,match), CURRENT);
356 evaluateQuery (
"match-event(ID=\""+classifier+
"\", \""+match+
"\")");
367 attachNextSerchStep (
solution_, findCall(match), CURRENT);
386 attachNextSerchStep (
solution_, find(match), FORWARD);
397 attachNextSerchStep (
solution_, findRegExp(regExp), FORWARD);
419 attachNextSerchStep (
solution_, findEvent(match), FORWARD);
427 attachNextSerchStep (
solution_, findEvent(classifier,match), FORWARD);
428 evaluateQuery (
"match-event(ID=\""+classifier+
"\", \""+match+
"\")");
440 attachNextSerchStep (
solution_, findCall(match), FORWARD);
456 attachNextSerchStep (
solution_, find(match), BACKWARD);
462 EventMatch::afterMatch (
string regExp)
464 attachNextSerchStep (
solution_, findRegExp(regExp), BACKWARD);
470 EventMatch::afterEvent (
string match)
472 attachNextSerchStep (
solution_, findEvent(match), BACKWARD);
478 EventMatch::afterEvent (
string classifier,
string match)
480 attachNextSerchStep (
solution_, findEvent(classifier,match), BACKWARD);
481 evaluateQuery (
"match-event(ID=\""+classifier+
"\", \""+match+
"\")",
"before");
491 attachNextSerchStep (
solution_, findCall(match), BACKWARD);
505 evaluateQuery (
"match-argument(["+util::toString(idx)+
"]="+match+
")");
514 string argList(util::join(argSeq));
564 evaluateQuery (
"match-attribute("+key+
"=\""+valueMatch+
"\")");
604 EventLog::EventLog (
string logID)
607 log({
"type=EventLogHeader",
"this="+logID});
627 Log& target = *otherLog.log_;
628 target.reserve (target.size() + log_->size() + 1);
629 target.emplace_back (log_->front());
630 auto p = log_->begin();
631 while (++p != log_->end())
632 target.emplace_back (std::move(*p));
633 this->log_->resize(1);
634 this->log({
"type=joined", otherLog.
getID()});
635 otherLog.log({
"type=logJoin", this->getID()});
636 this->log_ = otherLog.log_;
645 string originalLogID = this->getID();
646 return this->clear (originalLogID);
660 log_.reset (
new Log);
661 log({
"type=EventLogHeader",
"this="+alteredLogID});
668 return clear (
string{alteredLogID});
678 log (
"event", ArgSeq{}, ArgSeq{text});
685 log (
"event", ArgSeq{
"ID="+classifier}, ArgSeq{text});
692 return call(target,
function, ArgSeq());
698 log (
"call", ArgSeq{
"fun="+
function,
"this="+target}, std::forward<ArgSeq>(args));
703 EventLog::call (
const char* target,
const char*
function, ArgSeq&& args)
705 return call (
string(target),
string(
function), std::forward<ArgSeq>(args));
712 log({
"type=warn", text});
719 log({
"type=error", text});
726 log({
"type=fatal", text});
735 log({
"type=create", text});
742 log({
"type=destroy", text});
void refineSerach_matchArgument(size_t idx, string match)
EventMatch & type(string typeID)
refine filter to additionally require a matching log entry type
EventLog & event(string text)
log some text as event
EventMatch & locateCall(string match)
basic search for some specific function invocation
auto ensureAttribute(string key)
refinement filter to ensure a specific attribute is present on the log entry
string violation_
record when the underlying query has failed
Filter solution_
match predicate evaluator
EventLog & warn(string text)
Log a warning entry.
Support for verifying the occurrence of events from unit tests.
bool filter(Placement< DummyMO > const &candidate)
a filter predicate to pick some objects from a resultset.
AnyPair entry(Query< TY > const &query, typename WrapReturn< TY >::Wrapper &obj)
helper to simplify creating mock table entries, wrapped correctly
EventMatch & beforeCall(string match)
find a match for some function invocation after the current point of reference
inline string literal This is a marker type to indicate that
Helper to log and verify the occurrence of events.
EventMatch & beforeMatch(string regExp)
find a match with the given regular expression
EventLog & create(string text)
Log the creation of an object.
EventMatch & after(string match)
find a match (substring match) of the given text in an EventLog entry before the current position...
EventMatch & locateMatch(string regExp)
basic search like locate() but with the given regular expression
EventMatch verifyEvent(string match) const
start a query to match for some event.
EventMatch & afterCall(string match)
find a function invocation backwards, before the current point of reference
Implementation namespace for support and library code.
auto matchArgsRegExp(RExSeq &®ExpSeq)
refinement filter, to cover all arguments by regular expression(s)
void evaluateQuery(string matchSpec, Literal rel="after")
this is actually called after each refinement of the filter and matching conditions.
EventMatch & attrib(string key, string valueMatch)
refine filter to additionally match on a specific attribute
EventMatch(Log const &srcSeq)
auto matchArgument(size_t idx, string match)
refinement filter to match a specific positional argument
Token or Atom with distinct identity.
EventMatch verifyCall(string match) const
start a query to match especially a function call
EventMatch ensureNot(string match) const
start a query to ensure the given expression does not match.
auto matchAttribute(string key, string valueMatch)
refinement filter to ensure a specific attribute is present on the log entry
bool foundSolution()
core of the evaluation machinery: apply a filter predicate and then pull through the log to find a ac...
EventMatch & beforeEvent(string match)
find a match for an "event" after the current point of reference
EventLog & clear()
purge log contents while retaining just the original Header-ID
auto matchArguments(ArgSeq &&argSeq)
this filter functor is for refinement of an existing filter
EventLog & call(string target, string function)
Log occurrence of a function call with no arguments.
EventLog & joinInto(EventLog &otherLog)
Merge this log into another log, forming a combined log.
bool look_for_match_
support for positive and negative queries.
EventMatch & id(string classifier)
refine filter to additionally match on the ID attribute
void refineSerach_matchArguments(ArgSeq &&argSeq)
Lumiera error handling (C++ interface).
EventMatch & locate(string match)
basic search function: continue linear lookup over the elements of the EventLog to find a match (subs...
EventLog & fatal(string text)
Log a fatal failure.
EventMatch verify(string match) const
start a query to match for some substring.
void refineSerach_matchArgsRegExp(RExSeq &®ExpSeq, string rendered_regExps)
EventLog & destroy(string text)
Log the destruction of an object.
EventMatch verifyMatch(string regExp) const
start a query to match with a regular expression
EventMatch & on(string targetID)
refine filter to additionally match the 'this' attribute
auto matchType(string typeID)
refinement filter to match on the given typeID
EventMatch & key(string key)
refine filter to additionally require the presence an attribute
string lastMatch_
record last match for diagnostics
EventMatch & before(string match)
find a match (substring match) of the given text in an EventLog entry after the current position ...
bool contains(SEQ const &cont, typename SEQ::const_reference val)
shortcut for brute-force containment test in any sequential container
EventMatch & locateEvent(string match)
basic search for a matching "event"
EventLog & error(string text)
Log an error note.