Progmasoft Git

catch3

Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.

Clonegit clone https://git.progmasoft.com/catch3

Change how and when anonymous test cases are named

Commit
e6b9b854b57580e8a500c0b1c5ab4914ada5a570
Author
Martin Hořeňovský ·
Parents
478c32453466

Files · Download .tar.gz

Changes

 include/internal/catch_test_case_info.cpp          | 7 ++++++-
 include/internal/catch_test_case_registry_impl.cpp | 6 ------
 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
     };