Fixed missing file name and line number in logs

git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@576 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
mat007 2012-11-28 21:57:03 +00:00
parent 2b0ef7328c
commit c7a609404f
3 changed files with 19 additions and 4 deletions

View file

@ -718,3 +718,12 @@ BOOST_FIXTURE_TEST_CASE( throwing_an_exception_disables_the_automatic_verificati
catch( std::exception& ) catch( std::exception& )
{} {}
} }
BOOST_FIXTURE_TEST_CASE( adding_file_and_line_number_information, error_fixture )
{
mock::detail::function< void() > f;
f.expect( "file name", 42 ).once();
CHECK_ERROR( f.verify(), "verification failed", 0, "?\n. once()" );
BOOST_CHECK_EQUAL( "file name", data().last_file );
BOOST_CHECK_EQUAL( 42, data().last_line );
}

View file

@ -37,10 +37,13 @@ namespace
++call_count; ++call_count;
} }
void fail( const std::string& message, void fail( const std::string& message,
const std::string& context ) const std::string& context,
const char* file, int line )
{ {
last_context = context; last_context = context;
last_message = message; last_message = message;
last_file = file;
last_line = line;
++error_count; ++error_count;
} }
@ -48,6 +51,8 @@ namespace
int call_count; int call_count;
std::string last_message; std::string last_message;
std::string last_context; std::string last_context;
std::string last_file;
int last_line;
}; };
inline mock_error_data& data() inline mock_error_data& data()
@ -76,9 +81,10 @@ namespace
template< typename Context > template< typename Context >
static void fail( const std::string& message, const Context& context, static void fail( const std::string& message, const Context& context,
const char* /*file*/ = "", int /*line*/ = 0 ) const char* file = "", int line = 0 )
{ {
data().fail( message, boost::lexical_cast< std::string >( context ) ); data().fail( message,
boost::lexical_cast< std::string >( context ), file, line );
} }
}; };

View file

@ -61,7 +61,7 @@ namespace detail
expectation_type& expect( const char* file, int line ) expectation_type& expect( const char* file, int line )
{ {
error_type::pass( file, line ); error_type::pass( file, line );
return impl_->expect(); return impl_->expect( file, line );
} }
expectation_type& expect() expectation_type& expect()
{ {