mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-30 01:03:30 +01: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:
parent
81cb69ef18
commit
78fba28c4b
@ -22,8 +22,9 @@ namespace Catch {
|
|||||||
TestCaseInfo();
|
TestCaseInfo();
|
||||||
|
|
||||||
TestCaseInfo( ITestCase* testCase,
|
TestCaseInfo( ITestCase* testCase,
|
||||||
const char* name,
|
const std::string& className,
|
||||||
const char* description,
|
const std::string& name,
|
||||||
|
const std::string& description,
|
||||||
const SourceLineInfo& lineInfo );
|
const SourceLineInfo& lineInfo );
|
||||||
|
|
||||||
|
|
||||||
@ -31,6 +32,8 @@ namespace Catch {
|
|||||||
TestCaseInfo( const TestCaseInfo& other );
|
TestCaseInfo( const TestCaseInfo& other );
|
||||||
|
|
||||||
void invoke() const;
|
void invoke() const;
|
||||||
|
|
||||||
|
const std::string& getClassName() const;
|
||||||
const std::string& getName() const;
|
const std::string& getName() const;
|
||||||
const std::string& getDescription() const;
|
const std::string& getDescription() const;
|
||||||
const SourceLineInfo& getLineInfo() const;
|
const SourceLineInfo& getLineInfo() const;
|
||||||
@ -46,6 +49,7 @@ namespace Catch {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Ptr<ITestCase> m_test;
|
Ptr<ITestCase> m_test;
|
||||||
|
std::string m_className;
|
||||||
std::string m_name;
|
std::string m_name;
|
||||||
std::string m_description;
|
std::string m_description;
|
||||||
std::set<std::string> m_tags;
|
std::set<std::string> m_tags;
|
||||||
|
@ -16,10 +16,12 @@ namespace Catch {
|
|||||||
|
|
||||||
|
|
||||||
TestCaseInfo::TestCaseInfo( ITestCase* testCase,
|
TestCaseInfo::TestCaseInfo( ITestCase* testCase,
|
||||||
const char* name,
|
const std::string& className,
|
||||||
const char* description,
|
const std::string& name,
|
||||||
|
const std::string& description,
|
||||||
const SourceLineInfo& lineInfo )
|
const SourceLineInfo& lineInfo )
|
||||||
: m_test( testCase ),
|
: m_test( testCase ),
|
||||||
|
m_className( className ),
|
||||||
m_name( name ),
|
m_name( name ),
|
||||||
m_description( description ),
|
m_description( description ),
|
||||||
m_lineInfo( lineInfo ),
|
m_lineInfo( lineInfo ),
|
||||||
@ -32,6 +34,7 @@ namespace Catch {
|
|||||||
|
|
||||||
TestCaseInfo::TestCaseInfo()
|
TestCaseInfo::TestCaseInfo()
|
||||||
: m_test( NULL ),
|
: m_test( NULL ),
|
||||||
|
m_className(),
|
||||||
m_name(),
|
m_name(),
|
||||||
m_description(),
|
m_description(),
|
||||||
m_isHidden( false )
|
m_isHidden( false )
|
||||||
@ -39,6 +42,7 @@ namespace Catch {
|
|||||||
|
|
||||||
TestCaseInfo::TestCaseInfo( const TestCaseInfo& other, const std::string& name )
|
TestCaseInfo::TestCaseInfo( const TestCaseInfo& other, const std::string& name )
|
||||||
: m_test( other.m_test ),
|
: m_test( other.m_test ),
|
||||||
|
m_className( other.m_className ),
|
||||||
m_name( name ),
|
m_name( name ),
|
||||||
m_description( other.m_description ),
|
m_description( other.m_description ),
|
||||||
m_tags( other.m_tags ),
|
m_tags( other.m_tags ),
|
||||||
@ -48,6 +52,7 @@ namespace Catch {
|
|||||||
|
|
||||||
TestCaseInfo::TestCaseInfo( const TestCaseInfo& other )
|
TestCaseInfo::TestCaseInfo( const TestCaseInfo& other )
|
||||||
: m_test( other.m_test ),
|
: m_test( other.m_test ),
|
||||||
|
m_className( other.m_className ),
|
||||||
m_name( other.m_name ),
|
m_name( other.m_name ),
|
||||||
m_description( other.m_description ),
|
m_description( other.m_description ),
|
||||||
m_tags( other.m_tags ),
|
m_tags( other.m_tags ),
|
||||||
@ -59,14 +64,15 @@ namespace Catch {
|
|||||||
m_test->invoke();
|
m_test->invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::string& TestCaseInfo::getClassName() const {
|
||||||
|
return m_className;
|
||||||
|
}
|
||||||
const std::string& TestCaseInfo::getName() const {
|
const std::string& TestCaseInfo::getName() const {
|
||||||
return m_name;
|
return m_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& TestCaseInfo::getDescription() const {
|
const std::string& TestCaseInfo::getDescription() const {
|
||||||
return m_description;
|
return m_description;
|
||||||
}
|
}
|
||||||
|
|
||||||
const SourceLineInfo& TestCaseInfo::getLineInfo() const {
|
const SourceLineInfo& TestCaseInfo::getLineInfo() const {
|
||||||
return m_lineInfo;
|
return m_lineInfo;
|
||||||
}
|
}
|
||||||
@ -89,13 +95,16 @@ namespace Catch {
|
|||||||
|
|
||||||
void TestCaseInfo::swap( TestCaseInfo& other ) {
|
void TestCaseInfo::swap( TestCaseInfo& other ) {
|
||||||
m_test.swap( other.m_test );
|
m_test.swap( other.m_test );
|
||||||
|
m_className.swap( other.m_className );
|
||||||
m_name.swap( other.m_name );
|
m_name.swap( other.m_name );
|
||||||
m_description.swap( other.m_description );
|
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 {
|
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 {
|
bool TestCaseInfo::operator < ( const TestCaseInfo& other ) const {
|
||||||
|
@ -108,22 +108,37 @@ namespace Catch {
|
|||||||
TestFunction m_fun;
|
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,
|
AutoReg::AutoReg( TestFunction function,
|
||||||
const char* name,
|
const char* name,
|
||||||
const char* description,
|
const char* description,
|
||||||
const SourceLineInfo& lineInfo ) {
|
const SourceLineInfo& lineInfo ) {
|
||||||
registerTestCase( new FreeFunctionTestCase( function ), name, description, lineInfo );
|
registerTestCase( new FreeFunctionTestCase( function ), "global", name, description, lineInfo );
|
||||||
}
|
}
|
||||||
|
|
||||||
AutoReg::~AutoReg() {}
|
AutoReg::~AutoReg() {}
|
||||||
|
|
||||||
void AutoReg::registerTestCase( ITestCase* testCase,
|
void AutoReg::registerTestCase( ITestCase* testCase,
|
||||||
|
const char* classOrQualifiedMethodName,
|
||||||
const char* name,
|
const char* name,
|
||||||
const char* description,
|
const char* description,
|
||||||
const SourceLineInfo& lineInfo ) {
|
const SourceLineInfo& lineInfo ) {
|
||||||
getMutableRegistryHub().registerTest( TestCaseInfo( testCase, name, description, lineInfo ) );
|
|
||||||
|
getMutableRegistryHub().registerTest( TestCaseInfo( testCase, extractClassName( classOrQualifiedMethodName ), name, description, lineInfo ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end namespace Catch
|
} // end namespace Catch
|
||||||
|
@ -41,13 +41,15 @@ struct AutoReg {
|
|||||||
|
|
||||||
template<typename C>
|
template<typename C>
|
||||||
AutoReg( void (C::*method)(),
|
AutoReg( void (C::*method)(),
|
||||||
|
const char* className,
|
||||||
const char* name,
|
const char* name,
|
||||||
const char* description,
|
const char* description,
|
||||||
const SourceLineInfo& lineInfo ) {
|
const SourceLineInfo& lineInfo ) {
|
||||||
registerTestCase( new MethodTestCase<C>( method ), name, description, lineInfo );
|
registerTestCase( new MethodTestCase<C>( method ), className, name, description, lineInfo );
|
||||||
}
|
}
|
||||||
|
|
||||||
void registerTestCase( ITestCase* testCase,
|
void registerTestCase( ITestCase* testCase,
|
||||||
|
const char* className,
|
||||||
const char* name,
|
const char* name,
|
||||||
const char* description,
|
const char* description,
|
||||||
const SourceLineInfo& lineInfo );
|
const SourceLineInfo& lineInfo );
|
||||||
@ -75,7 +77,7 @@ private:
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
#define INTERNAL_CATCH_METHOD_AS_TEST_CASE( QualifiedMethod, Name, Desc ) \
|
#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 )\
|
#define TEST_CASE_METHOD( ClassName, TestName, Desc )\
|
||||||
@ -83,7 +85,7 @@ private:
|
|||||||
struct INTERNAL_CATCH_UNIQUE_NAME( TestCaseMethod_catch_internal_ ) : ClassName{ \
|
struct INTERNAL_CATCH_UNIQUE_NAME( TestCaseMethod_catch_internal_ ) : ClassName{ \
|
||||||
void test(); \
|
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()
|
void INTERNAL_CATCH_UNIQUE_NAME( TestCaseMethod_catch_internal_ )::test()
|
||||||
|
|
||||||
|
@ -26,7 +26,10 @@ namespace Catch {
|
|||||||
|
|
||||||
struct TestCaseStats {
|
struct TestCaseStats {
|
||||||
|
|
||||||
TestCaseStats( const std::string& name = std::string() ) :m_name( name ){}
|
TestCaseStats( const std::string& className, const std::string& name )
|
||||||
|
: m_className( className ),
|
||||||
|
m_name( name )
|
||||||
|
{}
|
||||||
|
|
||||||
double m_timeInSeconds;
|
double m_timeInSeconds;
|
||||||
std::string m_status;
|
std::string m_status;
|
||||||
@ -94,7 +97,7 @@ namespace Catch {
|
|||||||
virtual void EndSection( const std::string&, const Counts& ) {}
|
virtual void EndSection( const std::string&, const Counts& ) {}
|
||||||
|
|
||||||
virtual void StartTestCase( const Catch::TestCaseInfo& testInfo ) {
|
virtual void StartTestCase( const Catch::TestCaseInfo& testInfo ) {
|
||||||
m_currentStats->m_testCaseStats.push_back( TestCaseStats( testInfo.getName() ) );
|
m_currentStats->m_testCaseStats.push_back( TestCaseStats( testInfo.getClassName(), testInfo.getName() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void Result( const Catch::AssertionResult& assertionResult ) {
|
virtual void Result( const Catch::AssertionResult& assertionResult ) {
|
||||||
|
@ -31,8 +31,8 @@ namespace
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
METHOD_AS_TEST_CASE( TestClass::succeedingCase, "./succeeding/TestClass/succeedingCase", "A method based test run that succeeds" )
|
METHOD_AS_TEST_CASE( TestClass::succeedingCase, "./succeeding/TestClass/succeedingCase", "A method based test run that succeeds [class]" )
|
||||||
METHOD_AS_TEST_CASE( TestClass::failingCase, "./failing/TestClass/failingCase", "A method based test run that fails" )
|
METHOD_AS_TEST_CASE( TestClass::failingCase, "./failing/TestClass/failingCase", "A method based test run that fails [class]" )
|
||||||
|
|
||||||
|
|
||||||
struct Fixture
|
struct Fixture
|
||||||
@ -42,7 +42,7 @@ struct Fixture
|
|||||||
int m_a;
|
int m_a;
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_CASE_METHOD( Fixture, "./succeeding/Fixture/succeedingCase", "A method based test run that succeeds" )
|
TEST_CASE_METHOD( Fixture, "./succeeding/Fixture/succeedingCase", "A method based test run that succeeds [class]" )
|
||||||
{
|
{
|
||||||
REQUIRE( m_a == 1 );
|
REQUIRE( m_a == 1 );
|
||||||
}
|
}
|
||||||
@ -50,7 +50,7 @@ TEST_CASE_METHOD( Fixture, "./succeeding/Fixture/succeedingCase", "A method base
|
|||||||
// We should be able to write our tests within a different namespace
|
// We should be able to write our tests within a different namespace
|
||||||
namespace Inner
|
namespace Inner
|
||||||
{
|
{
|
||||||
TEST_CASE_METHOD( Fixture, "./failing/Fixture/failingCase", "A method based test run that fails" )
|
TEST_CASE_METHOD( Fixture, "./failing/Fixture/failingCase", "A method based test run that fails [class]" )
|
||||||
{
|
{
|
||||||
REQUIRE( m_a == 2 );
|
REQUIRE( m_a == 2 );
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,7 @@ std::string parseIntoConfigAndReturnError( const char * (&argv)[size], Catch::Co
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Catch::TestCaseInfo makeTestCase( const char* name ){ return Catch::TestCaseInfo( NULL, name, "", CATCH_INTERNAL_LINEINFO ); }
|
inline Catch::TestCaseInfo makeTestCase( const char* name ){ return Catch::TestCaseInfo( NULL, "", name, "", CATCH_INTERNAL_LINEINFO ); }
|
||||||
|
|
||||||
TEST_CASE( "selftest/parser/2", "ConfigData" ) {
|
TEST_CASE( "selftest/parser/2", "ConfigData" ) {
|
||||||
|
|
||||||
@ -364,7 +364,7 @@ TEST_CASE( "selftest/tags", "" ) {
|
|||||||
std::string p5 = "[one][two]~[hide],[three]";
|
std::string p5 = "[one][two]~[hide],[three]";
|
||||||
|
|
||||||
SECTION( "one tag", "" ) {
|
SECTION( "one tag", "" ) {
|
||||||
Catch::TestCaseInfo oneTag( NULL, "test", "[one]", CATCH_INTERNAL_LINEINFO );
|
Catch::TestCaseInfo oneTag( NULL, "", "test", "[one]", CATCH_INTERNAL_LINEINFO );
|
||||||
|
|
||||||
CHECK( oneTag.getDescription() == "" );
|
CHECK( oneTag.getDescription() == "" );
|
||||||
CHECK( oneTag.hasTag( "one" ) );
|
CHECK( oneTag.hasTag( "one" ) );
|
||||||
@ -378,7 +378,7 @@ TEST_CASE( "selftest/tags", "" ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SECTION( "two tags", "" ) {
|
SECTION( "two tags", "" ) {
|
||||||
Catch::TestCaseInfo twoTags( NULL, "test", "[one][two]", CATCH_INTERNAL_LINEINFO );
|
Catch::TestCaseInfo twoTags( NULL, "", "test", "[one][two]", CATCH_INTERNAL_LINEINFO );
|
||||||
|
|
||||||
CHECK( twoTags.getDescription() == "" );
|
CHECK( twoTags.getDescription() == "" );
|
||||||
CHECK( twoTags.hasTag( "one" ) );
|
CHECK( twoTags.hasTag( "one" ) );
|
||||||
@ -395,7 +395,7 @@ TEST_CASE( "selftest/tags", "" ) {
|
|||||||
|
|
||||||
SECTION( "one tag with characters either side", "" ) {
|
SECTION( "one tag with characters either side", "" ) {
|
||||||
|
|
||||||
Catch::TestCaseInfo oneTagWithExtras( NULL, "test", "12[one]34", CATCH_INTERNAL_LINEINFO );
|
Catch::TestCaseInfo oneTagWithExtras( NULL, "", "test", "12[one]34", CATCH_INTERNAL_LINEINFO );
|
||||||
CHECK( oneTagWithExtras.getDescription() == "1234" );
|
CHECK( oneTagWithExtras.getDescription() == "1234" );
|
||||||
CHECK( oneTagWithExtras.hasTag( "one" ) );
|
CHECK( oneTagWithExtras.hasTag( "one" ) );
|
||||||
CHECK( oneTagWithExtras.hasTag( "two" ) == false );
|
CHECK( oneTagWithExtras.hasTag( "two" ) == false );
|
||||||
@ -404,7 +404,7 @@ TEST_CASE( "selftest/tags", "" ) {
|
|||||||
|
|
||||||
SECTION( "start of a tag, but not closed", "" ) {
|
SECTION( "start of a tag, but not closed", "" ) {
|
||||||
|
|
||||||
Catch::TestCaseInfo oneTagOpen( NULL, "test", "[one", CATCH_INTERNAL_LINEINFO );
|
Catch::TestCaseInfo oneTagOpen( NULL, "", "test", "[one", CATCH_INTERNAL_LINEINFO );
|
||||||
|
|
||||||
CHECK( oneTagOpen.getDescription() == "[one" );
|
CHECK( oneTagOpen.getDescription() == "[one" );
|
||||||
CHECK( oneTagOpen.hasTag( "one" ) == false );
|
CHECK( oneTagOpen.hasTag( "one" ) == false );
|
||||||
@ -412,7 +412,7 @@ TEST_CASE( "selftest/tags", "" ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SECTION( "hidden", "" ) {
|
SECTION( "hidden", "" ) {
|
||||||
Catch::TestCaseInfo oneTag( NULL, "test", "[hide]", CATCH_INTERNAL_LINEINFO );
|
Catch::TestCaseInfo oneTag( NULL, "", "test", "[hide]", CATCH_INTERNAL_LINEINFO );
|
||||||
|
|
||||||
CHECK( oneTag.getDescription() == "" );
|
CHECK( oneTag.getDescription() == "" );
|
||||||
CHECK( oneTag.hasTag( "hide" ) );
|
CHECK( oneTag.hasTag( "hide" ) );
|
||||||
|
Loading…
Reference in New Issue
Block a user