diff options
| author | Martin Hořeňovský | 2019-11-04 13:45:39 +0100 |
|---|---|---|
| committer | Martin Hořeňovský | 2019-11-04 13:45:39 +0100 |
| commit | e6b9b854b57580e8a500c0b1c5ab4914ada5a570 (patch) | |
| tree | 8e18acdcc9eba13e6f4be2d684c6bdcf68e21651 | |
| parent | 478c32453466fd4cbc7a51db48650f22507302ba (diff) | |
| download | catch3-e6b9b854b57580e8a500c0b1c5ab4914ada5a570.tar.gz | |
Change how and when anonymous test cases are named
| -rw-r--r-- | include/internal/catch_test_case_info.cpp | 7 | ||||
| -rw-r--r-- | include/internal/catch_test_case_registry_impl.cpp | 6 | ||||
| -rw-r--r-- | include/internal/catch_test_case_registry_impl.h | 1 |
3 files changed, 6 insertions, 8 deletions
diff --git a/include/internal/catch_test_case_info.cpp b/include/internal/catch_test_case_info.cpp index f9c22c81..a2069051 100644 --- a/include/internal/catch_test_case_info.cpp +++ b/include/internal/catch_test_case_info.cpp @@ -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 ) diff --git a/include/internal/catch_test_case_registry_impl.cpp b/include/internal/catch_test_case_registry_impl.cpp index b254ca08..19cc00fa 100644 --- a/include/internal/catch_test_case_registry_impl.cpp +++ b/include/internal/catch_test_case_registry_impl.cpp @@ -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 ); } diff --git a/include/internal/catch_test_case_registry_impl.h b/include/internal/catch_test_case_registry_impl.h index 359ac3e3..0b5144c9 100644 --- a/include/internal/catch_test_case_registry_impl.h +++ b/include/internal/catch_test_case_registry_impl.h @@ -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 }; |