From 894ef68a8f55c90dd9f34b94feaa44fa72433d12 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sat, 12 Dec 2015 01:01:46 +0100 Subject: [PATCH] EventLog: implement logging of function invocations --- src/lib/test/event-log.hpp | 71 ++++++++++++++++++---- tests/library/test/test-event-log-test.cpp | 4 +- 2 files changed, 61 insertions(+), 14 deletions(-) diff --git a/src/lib/test/event-log.hpp b/src/lib/test/event-log.hpp index 2a664ddf2..9f61ebe51 100644 --- a/src/lib/test/event-log.hpp +++ b/src/lib/test/event-log.hpp @@ -51,6 +51,7 @@ #include "lib/format-string.hpp" #include "lib/format-util.hpp" #include "lib/diff/record.hpp" +#include "lib/symbol.hpp" #include "lib/util.hpp" //#include @@ -70,8 +71,28 @@ namespace test{ using util::contains; using util::isnil; using util::_Fmt; + using lib::Symbol; // using std::rand; + namespace { + + template + inline void + stringify(CON&) + { + /* NOP */ + } + + template + inline void + stringify(CON& container, X const& elm, ARGS const& ...args) + { + container.emplace_back (util::str(elm)); + stringify (container, args...); + } + } + + /** * @internal ongoing evaluation and match within an [EventLog]. * @throws error::Fatal when the expected match fails (error::LUMIERA_ERROR_ASSERTION) @@ -334,6 +355,14 @@ namespace test{ log_->emplace_back(ili); } + template + void + log (Symbol typeID, ATTR&& attribs, ARGS&& args) + { + log_->emplace_back(typeID, std::forward(attribs) + , std::forward(args)); + } + string getID() const { @@ -414,30 +443,48 @@ namespace test{ UNIMPLEMENTED ("Log event with additional classifier"); } + /** Log occurrence of a function call with no arguments. + * @param target the object or scope on which the function is invoked + * @param function name of the function being invoked + */ EventLog& call (string target, string function) { - UNIMPLEMENTED ("Log function call with no arguments"); + return call(target, function, ArgSeq()); } + /** Log a function call with a sequence of stringified arguments */ EventLog& - call (string target, string function, ArgSeq&& argSeq) + call (string target, string function, ArgSeq&& args) { - UNIMPLEMENTED ("Log function call with a sequence of stringified arguments"); + log ("call", ArgSeq{"fun="+function, "this="+target}, std::forward(args)); + return *this; + } + + /** Log a function call with arbitrary arguments */ + template + EventLog& + call (string target, string function, ARGS const& ...args) + { + ArgSeq argSeq; + argSeq.reserve(sizeof...(ARGS)); + stringify(argSeq, args...); + return call (target, function, std::move(argSeq)); + } + + /** Log a function call on given object ("`this`")... */ + template + EventLog& + call (const X *const targetObj, string function, ARGS const& ...args) + { + return call (idi::instanceTypeID (targetObj), function, args...); } template EventLog& - call (string target, string function, ARGS&& ...args) + call (const char* target, string function, ARGS const& ...args) { - UNIMPLEMENTED ("Log function call with arbitrary arguments"); - } - - template - EventLog& - call (const X *const targetObj, string function, ARGS&& ...args) - { - UNIMPLEMENTED ("Log function call on given object with arguments"); + return call (string(target), function, args...); } template diff --git a/tests/library/test/test-event-log-test.cpp b/tests/library/test/test-event-log-test.cpp index f992c4df5..be02c37d9 100644 --- a/tests/library/test/test-event-log-test.cpp +++ b/tests/library/test/test-event-log-test.cpp @@ -201,8 +201,8 @@ namespace test{ CHECK (join(log) == string( "Rec(EventLogHeader| ID = funCall ), " - "Rec(call| fun = fun1, this = "+idi::instanceTypeID(this)+" |{}), " - "Rec(call| fun = fun2, this = some |{}), " + "Rec(call| fun = fun1, this = "+idi::instanceTypeID(this)+" ), " + "Rec(call| fun = fun2, this = some ), " "Rec(call| fun = fun3, this = more |{facts, 3.2, 1})")); CHECK (log.verifyCall("fun1"));