Change how and when anonymous test cases are named

This commit is contained in:
Martin Hořeňovský 2019-11-04 13:45:39 +01:00
parent 478c324534
commit e6b9b854b5
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
3 changed files with 6 additions and 8 deletions

View File

@ -46,6 +46,11 @@ namespace Catch {
<< "Tag names starting with non alphanumeric characters are reserved\n"
<< _lineInfo );
}
std::string makeDefaultName() {
static size_t counter = 0;
return "Anonymous test case " + std::to_string(++counter);
}
}
TestCase makeTestCase( ITestInvoker* _testCase,
@ -111,7 +116,7 @@ namespace Catch {
std::string const& _className,
std::vector<std::string> const& _tags,
SourceLineInfo const& _lineInfo )
: name( _name ),
: name( _name.empty() ? makeDefaultName() : _name ),
className( _className ),
lineInfo( _lineInfo ),
properties( None )

View File

@ -73,12 +73,6 @@ namespace Catch {
}
void TestRegistry::registerTest( TestCase const& testCase ) {
std::string name = testCase.getTestCaseInfo().name;
if( name.empty() ) {
ReusableStringStream rss;
rss << "Anonymous test case " << ++m_unnamedCount;
return registerTest( testCase.withName( rss.str() ) );
}
m_functions.push_back( testCase );
}

View File

@ -45,7 +45,6 @@ namespace Catch {
std::vector<TestCase> m_functions;
mutable RunTests::InWhatOrder m_currentSortOrder = RunTests::InDeclarationOrder;
mutable std::vector<TestCase> m_sortedFunctions;
std::size_t m_unnamedCount = 0;
std::ios_base::Init m_ostreamInit; // Forces cout/ cerr to be initialised
};