mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 13:26:10 +01:00
capture file/ line of test case - for reporting on uncaught exceptions
This commit is contained in:
parent
77d72fb852
commit
81e42ce139
@ -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<typename RhsT>
|
||||
STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator ||
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
@ -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
|
||||
|
@ -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<C>( method ), name, description );
|
||||
registerTestCase( new MethodTestCase<C>( 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
|
||||
|
Loading…
Reference in New Issue
Block a user