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:
Phil Nash 2012-11-04 21:11:59 +00:00
parent 81cb69ef18
commit 78fba28c4b
7 changed files with 64 additions and 31 deletions

View file

@ -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