diff --git a/internal/catch_capture.hpp b/internal/catch_capture.hpp index f1a9fbc1..6fcf496a 100644 --- a/internal/catch_capture.hpp +++ b/internal/catch_capture.hpp @@ -286,6 +286,17 @@ public: m_message = message; } + /////////////////////////////////////////////////////////////////////////// + void setFileAndLine + ( + const std::string& filename, + std::size_t line + ) + { + m_filename = filename; + m_line = line; + } + /////////////////////////////////////////////////////////////////////////// template STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator || diff --git a/internal/catch_runner_impl.hpp b/internal/catch_runner_impl.hpp index 38845fe1..4eb4d71d 100644 --- a/internal/catch_runner_impl.hpp +++ b/internal/catch_runner_impl.hpp @@ -553,6 +553,8 @@ namespace Catch m_runningTest->reset(); StreamRedirect coutRedir( std::cout, redirectedCout ); StreamRedirect cerrRedir( std::cerr, redirectedCerr ); + m_currentResult.setFileAndLine( m_runningTest->getTestCaseInfo().getFilename(), + m_runningTest->getTestCaseInfo().getLine() ); m_runningTest->getTestCaseInfo().invoke(); m_runningTest->ranToCompletion(); } diff --git a/internal/catch_test_case_info.hpp b/internal/catch_test_case_info.hpp index 9c796f5f..4e88bc4f 100644 --- a/internal/catch_test_case_info.hpp +++ b/internal/catch_test_case_info.hpp @@ -27,11 +27,15 @@ namespace Catch ( ITestCase* testCase, const char* name, - const char* description + const char* description, + const char* filename, + std::size_t line ) : m_test( testCase ), m_name( name ), - m_description( description ) + m_description( description ), + m_filename( filename ), + m_line( line ) { } @@ -49,7 +53,9 @@ namespace Catch ) : m_test( other.m_test->clone() ), m_name( other.m_name ), - m_description( other.m_description ) + m_description( other.m_description ), + m_filename( other.m_filename ), + m_line( other.m_line ) { } @@ -61,7 +67,9 @@ namespace Catch ) : m_test( other.m_test->clone() ), m_name( name ), - m_description( other.m_description ) + m_description( other.m_description ), + m_filename( other.m_filename ), + m_line( other.m_line ) { } @@ -107,6 +115,22 @@ namespace Catch return m_description; } + /////////////////////////////////////////////////////////////////////// + const std::string& getFilename + () + const + { + return m_filename; + } + + /////////////////////////////////////////////////////////////////////// + std::size_t getLine + () + const + { + return m_line; + } + /////////////////////////////////////////////////////////////////////// bool isHidden () @@ -155,6 +179,9 @@ namespace Catch ITestCase* m_test; std::string m_name; std::string m_description; + std::string m_filename; + std::size_t m_line; + }; /////////////////////////////////////////////////////////////////////////// diff --git a/internal/catch_test_case_registry_impl.hpp b/internal/catch_test_case_registry_impl.hpp index 2e430dde..2c368e47 100644 --- a/internal/catch_test_case_registry_impl.hpp +++ b/internal/catch_test_case_registry_impl.hpp @@ -151,10 +151,12 @@ namespace Catch ( TestFunction function, const char* name, - const char* description + const char* description, + const char* filename, + std::size_t line ) { - registerTestCase( new FreeFunctionTestCase( function ), name, description ); + registerTestCase( new FreeFunctionTestCase( function ), name, description, filename, line ); } /////////////////////////////////////////////////////////////////////////// @@ -168,10 +170,12 @@ namespace Catch ( ITestCase* testCase, const char* name, - const char* description + const char* description, + const char* filename, + std::size_t line ) { - Hub::getTestCaseRegistry().registerTest( TestCaseInfo( testCase, name, description ) ); + Hub::getTestCaseRegistry().registerTest( TestCaseInfo( testCase, name, description, filename, line ) ); } } // end namespace Catch diff --git a/internal/catch_test_registry.hpp b/internal/catch_test_registry.hpp index ab7e1670..7f090538 100644 --- a/internal/catch_test_registry.hpp +++ b/internal/catch_test_registry.hpp @@ -79,7 +79,9 @@ struct AutoReg AutoReg ( TestFunction function, const char* name, - const char* description + const char* description, + const char* filename, + std::size_t line ); /////////////////////////////////////////////////////////////////////////// @@ -88,10 +90,12 @@ struct AutoReg ( void (C::*method)(), const char* name, - const char* description + const char* description, + const char* filename, + std::size_t line ) { - registerTestCase( new MethodTestCase( method ), name, description ); + registerTestCase( new MethodTestCase( method ), name, description, filename, line ); } /////////////////////////////////////////////////////////////////////////// @@ -99,7 +103,9 @@ struct AutoReg ( ITestCase* testCase, const char* name, - const char* description + const char* description, + const char* filename, + std::size_t line ); ~AutoReg @@ -118,18 +124,18 @@ private: /////////////////////////////////////////////////////////////////////////////// #define INTERNAL_CATCH_TESTCASE( Name, Desc ) \ static void INTERNAL_CATCH_UNIQUE_NAME( catch_internal_TestFunction )(); \ - namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &INTERNAL_CATCH_UNIQUE_NAME( catch_internal_TestFunction ), Name, Desc ); }\ + namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &INTERNAL_CATCH_UNIQUE_NAME( catch_internal_TestFunction ), Name, Desc, __FILE__, __LINE__ ); }\ static void INTERNAL_CATCH_UNIQUE_NAME( catch_internal_TestFunction )() /////////////////////////////////////////////////////////////////////////////// #define INTERNAL_CATCH_TESTCASE_NORETURN( Name, Desc ) \ static void INTERNAL_CATCH_UNIQUE_NAME( catch_internal_TestFunction )() ATTRIBUTE_NORETURN; \ - namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &INTERNAL_CATCH_UNIQUE_NAME( catch_internal_TestFunction ), Name, Desc ); }\ + namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &INTERNAL_CATCH_UNIQUE_NAME( catch_internal_TestFunction ), Name, Desc, __FILE__, __LINE__ ); }\ static void INTERNAL_CATCH_UNIQUE_NAME( catch_internal_TestFunction )() /////////////////////////////////////////////////////////////////////////////// #define CATCH_METHOD_AS_TEST_CASE( QualifiedMethod, Name, Desc ) \ - namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &QualifiedMethod, Name, Desc ); } + namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &QualifiedMethod, Name, Desc, __FILE__, __LINE__ ); } /////////////////////////////////////////////////////////////////////////////// #define TEST_CASE_METHOD( ClassName, TestName, Desc )\ @@ -137,7 +143,7 @@ private: { \ void test(); \ }; \ - namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar ) ( &INTERNAL_CATCH_UNIQUE_NAME( Catch_FixtureWrapper )::test, TestName, Desc ); } \ + namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar ) ( &INTERNAL_CATCH_UNIQUE_NAME( Catch_FixtureWrapper )::test, TestName, Desc, __FILE__, __LINE__ ); } \ void INTERNAL_CATCH_UNIQUE_NAME( Catch_FixtureWrapper )::test() #endif // TWOBLUECUBES_CATCH_REGISTRY_HPP_INCLUDED