-
Notifications
You must be signed in to change notification settings - Fork 20
Description
I was previously using Turtle Mock with Boost.Test and was pretty happy, but now we decided to switch to Catch C++ and Turtle Mock does not work any more :(
I had a look at different C++ Mock frameworks and still convinced no other framework is that good as Turtle Mock for various reasons.
I read this documentation Link on how to integrate Turtle Mock with other Frameworks but still can't understand all the details.
Documentation example
By default the library expects to be used in conjunction with Boost.Test e.g. :
- logs using the logger from Boost.Test
- throws mock::exception deriving from boost::execution_aborted via boost::enable_current_exception
- adds Boost.Test checkpoints whenever possible
- verifies and resets all remaining (static or leaked objects) with a global fixture
However integrating with any given unit test framework can be done by defining a custom error policy implementing the following concept:
template< typename Result >
struct custom_policy
{
static Result abort()
{
// ...
}
template< typename Context >
static void fail( const char* message, const Context& context, const char* file = "unknown location", int line = 0 )
{
// ...
}
template< typename Context >
static void call( const Context& context, const char* file, int line )
{
// ...
}
static void pass( const char* file, int line )
{
// ...
}
};
The context, which stands for "something serializable to an std::ostream", is actually built only if an attempt to serialize it is made, thus enabling lazy serialization of all elements (e.g. constraints and parameters). File and line show were the expectation has been configured.
The policy can then be activated by defining MOCK_ERROR_POLICY prior to including the library:
#define MOCK_ERROR_POLICY custom_policy
#include <turtle/mock.hpp>
My Questions
- If the above
custom_policyis going to be provided will there be any kind of dependency to Boost.Test? - What exactly does
custom_policy::abortdo and what kind ofResultinstance should it return? Especially if Result type is used by Turtle Mock in template instantiation. passseems to be easily mappable to CatchINFOcallandfailintroduce a context in addition to thepassdata being used. I think the context can be mapped to CatchCAPTUREcall as it is also lazy:
The message is logged to a buffer, but only reported with the next assertion that is logged. This allows you to log contextual information in case of failures which is not shown during a successful test run (for the console reporter, without -s). Messages are removed from the buffer at the end of their scope, so may be used, for example, in loops.
Many thanks in advance for answering these questions!