mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
Refactored error policy to simplify test frameworks integration
git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@536 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
parent
032e3b8a70
commit
610405b750
5 changed files with 84 additions and 151 deletions
|
|
@ -54,11 +54,11 @@ namespace detail
|
|||
it != expectations_.end(); ++it )
|
||||
{
|
||||
if( ! it->verify() )
|
||||
error_type::untriggered_expectation(
|
||||
error_type::fail( "untriggered expectation",
|
||||
boost::unit_test::lazy_ostream::instance()
|
||||
<< *this, it->file(), it->line() );
|
||||
else if( ! it->invoked() )
|
||||
error_type::expected_call(
|
||||
error_type::call(
|
||||
boost::unit_test::lazy_ostream::instance()
|
||||
<< *this, it->file(), it->line() );
|
||||
}
|
||||
|
|
@ -73,7 +73,7 @@ namespace detail
|
|||
if( !it->verify() )
|
||||
{
|
||||
valid_ = false;
|
||||
error_type::verification_failed(
|
||||
error_type::fail( "verification failed",
|
||||
boost::unit_test::lazy_ostream::instance()
|
||||
<< *this, it->file(), it->line() );
|
||||
}
|
||||
|
|
@ -112,23 +112,23 @@ namespace detail
|
|||
{
|
||||
if( ! it->invoke() )
|
||||
{
|
||||
error_type::sequence_failed(
|
||||
error_type::fail( "sequence failed",
|
||||
MOCK_CONTEXT, it->file(), it->line() );
|
||||
return error_type::abort();
|
||||
}
|
||||
if( ! it->functor() )
|
||||
{
|
||||
error_type::missing_action(
|
||||
error_type::fail( "missing action",
|
||||
MOCK_CONTEXT, it->file(), it->line() );
|
||||
return error_type::abort();
|
||||
}
|
||||
valid_ = true;
|
||||
error_type::expected_call(
|
||||
error_type::call(
|
||||
MOCK_CONTEXT, it->file(), it->line() );
|
||||
return it->functor()(
|
||||
BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, t) );
|
||||
}
|
||||
error_type::unexpected_call( MOCK_CONTEXT );
|
||||
error_type::fail( "unexpected call", MOCK_CONTEXT );
|
||||
return error_type::abort();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ namespace detail
|
|||
}
|
||||
bool verify( const char* file, int line ) const
|
||||
{
|
||||
error_type::checkpoint( file, line );
|
||||
error_type::pass( file, line );
|
||||
return impl_->verify();
|
||||
}
|
||||
void reset()
|
||||
|
|
@ -54,13 +54,13 @@ namespace detail
|
|||
}
|
||||
void reset( const char* file, int line )
|
||||
{
|
||||
error_type::checkpoint( file, line );
|
||||
error_type::pass( file, line );
|
||||
impl_->reset();
|
||||
}
|
||||
|
||||
expectation_type& expect( const char* file, int line )
|
||||
{
|
||||
error_type::checkpoint( file, line );
|
||||
error_type::pass( file, line );
|
||||
return impl_->expect();
|
||||
}
|
||||
expectation_type& expect()
|
||||
|
|
|
|||
|
|
@ -32,15 +32,14 @@ namespace mock
|
|||
throw boost::enable_current_exception( exception() );
|
||||
}
|
||||
|
||||
static void checkpoint( const char* file, int line )
|
||||
static void pass( const char* file, int line )
|
||||
{
|
||||
boost::unit_test::unit_test_log.set_checkpoint( file,
|
||||
static_cast< std::size_t >( line ) );
|
||||
}
|
||||
|
||||
template< typename Context >
|
||||
static void fail(
|
||||
const char* message, const Context& context,
|
||||
static void fail( const char* message, const Context& context,
|
||||
const char* file = "unknown location", int line = 0 )
|
||||
{
|
||||
boost::unit_test::framework::assertion_result( false );
|
||||
|
|
@ -53,7 +52,7 @@ namespace mock
|
|||
}
|
||||
|
||||
template< typename Context >
|
||||
static void expected_call( const Context& context,
|
||||
static void call( const Context& context,
|
||||
const char* file, int line )
|
||||
{
|
||||
boost::unit_test::framework::assertion_result( true );
|
||||
|
|
@ -64,36 +63,6 @@ namespace mock
|
|||
<< "mock expectation fulfilled: " << context
|
||||
<< boost::unit_test::log::end();
|
||||
}
|
||||
|
||||
template< typename Context >
|
||||
static void missing_action( const Context& context,
|
||||
const char* file, int line )
|
||||
{
|
||||
fail( "missing action", context, file, line );
|
||||
}
|
||||
template< typename Context >
|
||||
static void unexpected_call( const Context& context )
|
||||
{
|
||||
fail( "unexpected call", context );
|
||||
}
|
||||
template< typename Context >
|
||||
static void sequence_failed( const Context& context,
|
||||
const char* file, int line )
|
||||
{
|
||||
fail( "sequence failed", context, file, line );
|
||||
}
|
||||
template< typename Context >
|
||||
static void verification_failed( const Context& context,
|
||||
const char* file, int line )
|
||||
{
|
||||
fail( "verification failed", context, file, line );
|
||||
}
|
||||
template< typename Context >
|
||||
static void untriggered_expectation( const Context& context,
|
||||
const char* file, int line )
|
||||
{
|
||||
fail( "untriggered expectation", context, file, line );
|
||||
}
|
||||
};
|
||||
} // mock
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue