From c7a609404f6f54900cbbd8652b1205f311c487a9 Mon Sep 17 00:00:00 2001 From: mat007 Date: Wed, 28 Nov 2012 21:57:03 +0000 Subject: [PATCH] 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 --- test/detail/test_function.cpp | 9 +++++++++ test/mock_error.hpp | 12 +++++++++--- turtle/detail/function_template.hpp | 2 +- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/test/detail/test_function.cpp b/test/detail/test_function.cpp index fa24012..3ce24f0 100644 --- a/test/detail/test_function.cpp +++ b/test/detail/test_function.cpp @@ -718,3 +718,12 @@ BOOST_FIXTURE_TEST_CASE( throwing_an_exception_disables_the_automatic_verificati 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 ); +} diff --git a/test/mock_error.hpp b/test/mock_error.hpp index a9b17b0..7f2d7a8 100644 --- a/test/mock_error.hpp +++ b/test/mock_error.hpp @@ -37,10 +37,13 @@ namespace ++call_count; } void fail( const std::string& message, - const std::string& context ) + const std::string& context, + const char* file, int line ) { last_context = context; last_message = message; + last_file = file; + last_line = line; ++error_count; } @@ -48,6 +51,8 @@ namespace int call_count; std::string last_message; std::string last_context; + std::string last_file; + int last_line; }; inline mock_error_data& data() @@ -76,9 +81,10 @@ namespace template< typename 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 ); } }; diff --git a/turtle/detail/function_template.hpp b/turtle/detail/function_template.hpp index 8bf43c1..4adc71e 100644 --- a/turtle/detail/function_template.hpp +++ b/turtle/detail/function_template.hpp @@ -61,7 +61,7 @@ namespace detail expectation_type& expect( const char* file, int line ) { error_type::pass( file, line ); - return impl_->expect(); + return impl_->expect( file, line ); } expectation_type& expect() {