mirror of
https://github.com/catchorg/Catch2.git
synced 2025-05-25 22:19:25 +00:00
Simplified test case registration and started using StringRefs
This commit is contained in:
parent
79627cdcdb
commit
720fdf1d02
4 changed files with 44 additions and 80 deletions
|
@ -134,6 +134,10 @@ namespace Catch {
|
|||
m_testAsFunction();
|
||||
}
|
||||
};
|
||||
auto makeTestInvoker( void(*testAsFunction)() ) -> ITestInvoker* {
|
||||
return new TestInvokerAsFunction( testAsFunction );
|
||||
}
|
||||
|
||||
|
||||
inline std::string extractClassName( std::string const& classOrQualifiedMethodName ) {
|
||||
std::string className = classOrQualifiedMethodName;
|
||||
|
@ -148,40 +152,24 @@ namespace Catch {
|
|||
return className;
|
||||
}
|
||||
|
||||
void registerTestCase
|
||||
( ITestInvoker* testCase,
|
||||
char const* classOrQualifiedMethodName,
|
||||
NameAndDesc const& nameAndDesc,
|
||||
SourceLineInfo const& lineInfo ) {
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
AutoReg::AutoReg( ITestInvoker* invoker, SourceLineInfo const& lineInfo, StringRef classOrMethod, NameAndTags const& nameAndTags )
|
||||
{
|
||||
try {
|
||||
getMutableRegistryHub().registerTest
|
||||
(makeTestCase
|
||||
(testCase,
|
||||
extractClassName(classOrQualifiedMethodName),
|
||||
nameAndDesc.name,
|
||||
nameAndDesc.description,
|
||||
lineInfo));
|
||||
getMutableRegistryHub()
|
||||
.registerTest(
|
||||
makeTestCase(
|
||||
invoker,
|
||||
extractClassName( classOrMethod.c_str() ),
|
||||
nameAndTags.name.c_str(),
|
||||
nameAndTags.tags.c_str(),
|
||||
lineInfo));
|
||||
} catch (...) {
|
||||
// Do not throw when constructing global objects, instead register the exception to be processed later
|
||||
getMutableRegistryHub().registerStartupException( std::current_exception() );
|
||||
}
|
||||
}
|
||||
void registerTestCaseFunction
|
||||
( TestFunction function,
|
||||
SourceLineInfo const& lineInfo,
|
||||
NameAndDesc const& nameAndDesc ) {
|
||||
registerTestCase( new TestInvokerAsFunction( function ), "", nameAndDesc, lineInfo );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
AutoReg::AutoReg
|
||||
( TestFunction function,
|
||||
SourceLineInfo const& lineInfo,
|
||||
NameAndDesc const& nameAndDesc ) {
|
||||
registerTestCaseFunction( function, lineInfo, nameAndDesc );
|
||||
}
|
||||
|
||||
AutoReg::~AutoReg() {}
|
||||
|
||||
} // end namespace Catch
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue