mirror of
https://github.com/catchorg/Catch2.git
synced 2025-08-01 12:55:40 +02:00
Added className to TestCaseInfo
className is passed through from class based test methods and held in the TestCaseInfo. For free-function based test cases it is set to "global". The JUnit reporter uses the className value to populate he class attribute.
This commit is contained in:
@@ -22,8 +22,9 @@ namespace Catch {
|
||||
TestCaseInfo();
|
||||
|
||||
TestCaseInfo( ITestCase* testCase,
|
||||
const char* name,
|
||||
const char* description,
|
||||
const std::string& className,
|
||||
const std::string& name,
|
||||
const std::string& description,
|
||||
const SourceLineInfo& lineInfo );
|
||||
|
||||
|
||||
@@ -31,6 +32,8 @@ namespace Catch {
|
||||
TestCaseInfo( const TestCaseInfo& other );
|
||||
|
||||
void invoke() const;
|
||||
|
||||
const std::string& getClassName() const;
|
||||
const std::string& getName() const;
|
||||
const std::string& getDescription() const;
|
||||
const SourceLineInfo& getLineInfo() const;
|
||||
@@ -46,6 +49,7 @@ namespace Catch {
|
||||
|
||||
private:
|
||||
Ptr<ITestCase> m_test;
|
||||
std::string m_className;
|
||||
std::string m_name;
|
||||
std::string m_description;
|
||||
std::set<std::string> m_tags;
|
||||
|
@@ -16,10 +16,12 @@ namespace Catch {
|
||||
|
||||
|
||||
TestCaseInfo::TestCaseInfo( ITestCase* testCase,
|
||||
const char* name,
|
||||
const char* description,
|
||||
const std::string& className,
|
||||
const std::string& name,
|
||||
const std::string& description,
|
||||
const SourceLineInfo& lineInfo )
|
||||
: m_test( testCase ),
|
||||
m_className( className ),
|
||||
m_name( name ),
|
||||
m_description( description ),
|
||||
m_lineInfo( lineInfo ),
|
||||
@@ -32,6 +34,7 @@ namespace Catch {
|
||||
|
||||
TestCaseInfo::TestCaseInfo()
|
||||
: m_test( NULL ),
|
||||
m_className(),
|
||||
m_name(),
|
||||
m_description(),
|
||||
m_isHidden( false )
|
||||
@@ -39,6 +42,7 @@ namespace Catch {
|
||||
|
||||
TestCaseInfo::TestCaseInfo( const TestCaseInfo& other, const std::string& name )
|
||||
: m_test( other.m_test ),
|
||||
m_className( other.m_className ),
|
||||
m_name( name ),
|
||||
m_description( other.m_description ),
|
||||
m_tags( other.m_tags ),
|
||||
@@ -48,6 +52,7 @@ namespace Catch {
|
||||
|
||||
TestCaseInfo::TestCaseInfo( const TestCaseInfo& other )
|
||||
: m_test( other.m_test ),
|
||||
m_className( other.m_className ),
|
||||
m_name( other.m_name ),
|
||||
m_description( other.m_description ),
|
||||
m_tags( other.m_tags ),
|
||||
@@ -59,14 +64,15 @@ namespace Catch {
|
||||
m_test->invoke();
|
||||
}
|
||||
|
||||
const std::string& TestCaseInfo::getClassName() const {
|
||||
return m_className;
|
||||
}
|
||||
const std::string& TestCaseInfo::getName() const {
|
||||
return m_name;
|
||||
}
|
||||
|
||||
const std::string& TestCaseInfo::getDescription() const {
|
||||
return m_description;
|
||||
}
|
||||
|
||||
const SourceLineInfo& TestCaseInfo::getLineInfo() const {
|
||||
return m_lineInfo;
|
||||
}
|
||||
@@ -89,13 +95,16 @@ namespace Catch {
|
||||
|
||||
void TestCaseInfo::swap( TestCaseInfo& other ) {
|
||||
m_test.swap( other.m_test );
|
||||
m_className.swap( other.m_className );
|
||||
m_name.swap( other.m_name );
|
||||
m_description.swap( other.m_description );
|
||||
m_lineInfo.swap( other.m_lineInfo );
|
||||
std::swap( m_lineInfo, other.m_lineInfo );
|
||||
}
|
||||
|
||||
bool TestCaseInfo::operator == ( const TestCaseInfo& other ) const {
|
||||
return m_test.get() == other.m_test.get() && m_name == other.m_name;
|
||||
return m_test.get() == other.m_test.get() &&
|
||||
m_name == other.m_name &&
|
||||
m_className == other.m_className;
|
||||
}
|
||||
|
||||
bool TestCaseInfo::operator < ( const TestCaseInfo& other ) const {
|
||||
|
@@ -107,23 +107,38 @@ namespace Catch {
|
||||
|
||||
TestFunction m_fun;
|
||||
};
|
||||
|
||||
|
||||
inline std::string extractClassName( const std::string& classOrQualifiedMethodName ) {
|
||||
std::string className = classOrQualifiedMethodName;
|
||||
if( className[0] == '&' )
|
||||
{
|
||||
std::size_t lastColons = className.rfind( "::" );
|
||||
std::size_t penultimateColons = className.rfind( "::", lastColons-1 );
|
||||
if( penultimateColons == std::string::npos )
|
||||
penultimateColons = 1;
|
||||
className = className.substr( penultimateColons, lastColons-penultimateColons );
|
||||
}
|
||||
return className;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
AutoReg::AutoReg( TestFunction function,
|
||||
const char* name,
|
||||
const char* description,
|
||||
const SourceLineInfo& lineInfo ) {
|
||||
registerTestCase( new FreeFunctionTestCase( function ), name, description, lineInfo );
|
||||
registerTestCase( new FreeFunctionTestCase( function ), "global", name, description, lineInfo );
|
||||
}
|
||||
|
||||
AutoReg::~AutoReg() {}
|
||||
|
||||
void AutoReg::registerTestCase( ITestCase* testCase,
|
||||
const char* name,
|
||||
void AutoReg::registerTestCase( ITestCase* testCase,
|
||||
const char* classOrQualifiedMethodName,
|
||||
const char* name,
|
||||
const char* description,
|
||||
const SourceLineInfo& lineInfo ) {
|
||||
getMutableRegistryHub().registerTest( TestCaseInfo( testCase, name, description, lineInfo ) );
|
||||
|
||||
getMutableRegistryHub().registerTest( TestCaseInfo( testCase, extractClassName( classOrQualifiedMethodName ), name, description, lineInfo ) );
|
||||
}
|
||||
|
||||
} // end namespace Catch
|
||||
|
@@ -34,21 +34,23 @@ typedef void(*TestFunction)();
|
||||
|
||||
struct AutoReg {
|
||||
|
||||
AutoReg( TestFunction function,
|
||||
AutoReg( TestFunction function,
|
||||
const char* name,
|
||||
const char* description,
|
||||
const SourceLineInfo& lineInfo );
|
||||
|
||||
template<typename C>
|
||||
AutoReg( void (C::*method)(),
|
||||
AutoReg( void (C::*method)(),
|
||||
const char* className,
|
||||
const char* name,
|
||||
const char* description,
|
||||
const SourceLineInfo& lineInfo ) {
|
||||
registerTestCase( new MethodTestCase<C>( method ), name, description, lineInfo );
|
||||
registerTestCase( new MethodTestCase<C>( method ), className, name, description, lineInfo );
|
||||
}
|
||||
|
||||
void registerTestCase( ITestCase* testCase,
|
||||
const char* name,
|
||||
const char* className,
|
||||
const char* name,
|
||||
const char* description,
|
||||
const SourceLineInfo& lineInfo );
|
||||
|
||||
@@ -75,7 +77,7 @@ private:
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#define INTERNAL_CATCH_METHOD_AS_TEST_CASE( QualifiedMethod, Name, Desc ) \
|
||||
namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &QualifiedMethod, Name, Desc, CATCH_INTERNAL_LINEINFO ); }
|
||||
namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &QualifiedMethod, "&" #QualifiedMethod, Name, Desc, CATCH_INTERNAL_LINEINFO ); }
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#define TEST_CASE_METHOD( ClassName, TestName, Desc )\
|
||||
@@ -83,7 +85,7 @@ private:
|
||||
struct INTERNAL_CATCH_UNIQUE_NAME( TestCaseMethod_catch_internal_ ) : ClassName{ \
|
||||
void test(); \
|
||||
}; \
|
||||
Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar ) ( &INTERNAL_CATCH_UNIQUE_NAME( TestCaseMethod_catch_internal_ )::test, TestName, Desc, CATCH_INTERNAL_LINEINFO ); \
|
||||
Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar ) ( &INTERNAL_CATCH_UNIQUE_NAME( TestCaseMethod_catch_internal_ )::test, #ClassName, TestName, Desc, CATCH_INTERNAL_LINEINFO ); \
|
||||
} \
|
||||
void INTERNAL_CATCH_UNIQUE_NAME( TestCaseMethod_catch_internal_ )::test()
|
||||
|
||||
|
Reference in New Issue
Block a user