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

split test registry code out

Commit
95627c40cf1c3afa2f4b14abcb78406683b2a4e5
Author
Phil Nash ·
Parents
430733c918fd

Files · Download .tar.gz

Changes

 Test/ExceptionTests.cpp                    |   1 +
 Test/MiscTests.cpp                         |   1 +
 Test/Test.xcodeproj/project.pbxproj        |   2 +
 catch_runner.hpp                           |   3 +-
 internal/catch_hub_impl.hpp                |  32 ++++-----
 internal/catch_test_case_registry_impl.hpp | 111 +++++++++++++++++++++++++++++
 internal/catch_test_registry.hpp           |  66 +----------------
 7 files changed, 133 insertions(+), 83 deletions(-)

diff --git a/Test/ExceptionTests.cpp b/Test/ExceptionTests.cpp
index 327b6d0b..4be5a193 100644
--- a/Test/ExceptionTests.cpp
+++ b/Test/ExceptionTests.cpp
@@ -13,6 +13,7 @@
 #include "../catch.hpp"
 
 #include <string>
+#include <stdexcept>
 
 namespace
 {
diff --git a/Test/MiscTests.cpp b/Test/MiscTests.cpp
index 35d680a3..138596bb 100644
--- a/Test/MiscTests.cpp
+++ b/Test/MiscTests.cpp
@@ -11,6 +11,7 @@
  */
 
 #include "../catch.hpp"
+#include <iostream>
 
 TEST_CASE( "succeeding/Misc/Sections", "random SECTION tests" )
 {
diff --git a/Test/Test.xcodeproj/project.pbxproj b/Test/Test.xcodeproj/project.pbxproj
index 88be5b00..619a6b1d 100644
--- a/Test/Test.xcodeproj/project.pbxproj
+++ b/Test/Test.xcodeproj/project.pbxproj
@@ -42,6 +42,7 @@
 		4A992A6512B2156C002B7B66 /* catch_xmlwriter.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_xmlwriter.hpp; path = ../internal/catch_xmlwriter.hpp; sourceTree = SOURCE_ROOT; };
 		4A992A6612B21582002B7B66 /* catch_reporter_junit.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_reporter_junit.hpp; path = ../catch_reporter_junit.hpp; sourceTree = SOURCE_ROOT; };
 		4AA7EA9112A438C7005A0B97 /* MiscTests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MiscTests.cpp; sourceTree = "<group>"; };
+		4AD6775912D71DA0005AAF59 /* catch_test_case_registry_impl.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_test_case_registry_impl.hpp; path = ../internal/catch_test_case_registry_impl.hpp; sourceTree = SOURCE_ROOT; };
 		4AFC341512809A36003A0C29 /* catch_capture.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_capture.hpp; path = ../internal/catch_capture.hpp; sourceTree = SOURCE_ROOT; };
 		4AFC341612809A36003A0C29 /* catch_common.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = catch_common.h; path = ../internal/catch_common.h; sourceTree = SOURCE_ROOT; };
 		4AFC341712809A36003A0C29 /* catch_test_registry.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_test_registry.hpp; path = ../internal/catch_test_registry.hpp; sourceTree = SOURCE_ROOT; };
@@ -128,6 +129,7 @@
 		4A302E3912D5160400C84B67 /* Hub */ = {
 			isa = PBXGroup;
 			children = (
+				4AD6775912D71DA0005AAF59 /* catch_test_case_registry_impl.hpp */,
 				4A33BCE512CE7F500052A211 /* catch_hub.h */,
 				4A33BF0D12CEAC0C0052A211 /* catch_hub_impl.hpp */,
 			);
diff --git a/catch_runner.hpp b/catch_runner.hpp
index 20195b32..4e4947fa 100644
--- a/catch_runner.hpp
+++ b/catch_runner.hpp
@@ -13,9 +13,10 @@
 #ifndef TWOBLUECUBES_CATCH_RUNNER_HPP_INCLUDED
 #define TWOBLUECUBES_CATCH_RUNNER_HPP_INCLUDED
 
+#include "internal/catch_hub_impl.hpp"
+
 #include "internal/catch_commandline.hpp"
 #include "internal/catch_list.hpp"
-#include "internal/catch_hub_impl.hpp"
 #include "catch_reporter_basic.hpp"
 #include "catch_reporter_xml.hpp"
 #include "catch_reporter_junit.hpp"
diff --git a/internal/catch_hub_impl.hpp b/internal/catch_hub_impl.hpp
index 7eb7f6de..3888a14c 100644
--- a/internal/catch_hub_impl.hpp
+++ b/internal/catch_hub_impl.hpp
@@ -9,45 +9,39 @@
  *  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  *
  */
-#ifndef TWOBLUECUBES_CATCH_HUB_IMPL_HPP_INCLUDED
-#define TWOBLUECUBES_CATCH_HUB_IMPL_HPP_INCLUDED
-
 #include "catch_hub.h"
-#include "catch_reporter_registry.hpp"a
+#include "catch_reporter_registry.hpp"
+#include "catch_test_case_registry_impl.hpp"
 
 namespace Catch
 {
     ///////////////////////////////////////////////////////////////////////////
-    Hub::Hub()
+    Hub::Hub
+    ()
     :   m_reporterRegistry( new ReporterRegistry ),
         m_testCaseRegistry( new TestRegistry )
     {
     }
     
-    Hub& Hub::me()
+    ///////////////////////////////////////////////////////////////////////////
+    Hub& Hub::me
+    ()
     {
         static Hub hub;
         return hub;
     }
 
-    IReporterRegistry& Hub::getReporterRegistry()
+    ///////////////////////////////////////////////////////////////////////////
+    IReporterRegistry& Hub::getReporterRegistry
+    ()
     {
         return *me().m_reporterRegistry.get();
     }
 
-    ITestCaseRegistry& Hub::getTestCaseRegistry()
-    {
-        return *me().m_testCaseRegistry.get();
-    }
-    
     ///////////////////////////////////////////////////////////////////////////
-    AutoReg::AutoReg( TestFunction function, const char* name, const char* description )
-    {
-        Hub::getTestCaseRegistry().registerTest( TestCaseInfo( new FreeFunctionTestCase( function ), name, description ) );
-    }    
-    AutoReg::~AutoReg()
+    ITestCaseRegistry& Hub::getTestCaseRegistry
+    ()
     {
+        return *me().m_testCaseRegistry.get();
     }
 }
-
-#endif // TWOBLUECUBES_CATCH_HUB_IMPL_HPP_INCLUDED
\ No newline at end of file
diff --git a/internal/catch_test_case_registry_impl.hpp b/internal/catch_test_case_registry_impl.hpp
new file mode 100644
index 00000000..d46bed4e
--- /dev/null
+++ b/internal/catch_test_case_registry_impl.hpp
@@ -0,0 +1,111 @@
+/*
+ *  catch_test_case_registry_impl.hpp
+ *  Catch
+ *
+ *  Created by Phil on 7/1/2011
+ *  Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
+ *
+ *  Distributed under the Boost Software License, Version 1.0. (See accompanying
+ *  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ *
+ */
+
+#include "catch_test_registry.hpp"
+#include "catch_hub.h"
+
+#include <vector>
+#include <set>
+
+namespace Catch
+{
+    class TestRegistry : public ITestCaseRegistry
+    {
+    public:
+        
+        virtual void registerTest( const TestCaseInfo& testInfo )
+        {
+            if( m_functions.find( testInfo ) == m_functions.end() )
+            {
+                m_functions.insert( testInfo );
+                m_functionsInOrder.push_back( testInfo );
+            }
+        }
+        
+        virtual const std::vector<TestCaseInfo>& getAllTests() const
+        {
+            return m_functionsInOrder;
+        }
+        
+    private:
+        
+        std::set<TestCaseInfo> m_functions;
+        std::vector<TestCaseInfo> m_functionsInOrder;
+    };
+    
+    typedef void(*TestFunction)();
+    
+    struct FreeFunctionTestCase : ITestCase
+    {
+        FreeFunctionTestCase( TestFunction fun )
+        : fun( fun )
+        {}
+        
+        virtual void invoke() const
+        {
+            fun();
+        }
+        
+        virtual ITestCase* clone() const
+        {
+            return new FreeFunctionTestCase( fun );
+        }
+        
+        virtual bool operator == ( const ITestCase& other ) const
+        {
+            const FreeFunctionTestCase* ffOther = dynamic_cast<const FreeFunctionTestCase*> ( &other );
+            return ffOther && fun == ffOther->fun;
+        }
+        
+        virtual bool operator < ( const ITestCase& other ) const
+        {
+            const FreeFunctionTestCase* ffOther = dynamic_cast<const FreeFunctionTestCase*> ( &other );
+            return ffOther && fun < ffOther->fun;
+        }
+        
+    private:
+        TestFunction fun;
+    };
+        
+    ///////////////////////////////////////////////////////////////////////////
+    ///////////////////////////////////////////////////////////////////////////
+    
+    ///////////////////////////////////////////////////////////////////////////
+    AutoReg::AutoReg
+    (
+     TestFunction function, 
+     const char* name,
+     const char* description
+     )
+    {
+        registerTestCase( new FreeFunctionTestCase( function ), name, description );
+    }    
+    
+    ///////////////////////////////////////////////////////////////////////////
+    AutoReg::~AutoReg
+    ()
+    {
+    }
+    
+    ///////////////////////////////////////////////////////////////////////////
+    void AutoReg::registerTestCase
+    (
+     ITestCase* testCase, 
+     const char* name, 
+     const char* description 
+     )
+    {
+        Hub::getTestCaseRegistry().registerTest( TestCaseInfo( testCase, name, description ) );
+    }
+    
+} // end namespace Catch
+
diff --git a/internal/catch_test_registry.hpp b/internal/catch_test_registry.hpp
index 15954fe5..f0577df5 100644
--- a/internal/catch_test_registry.hpp
+++ b/internal/catch_test_registry.hpp
@@ -15,72 +15,10 @@
 #include "catch_testcase.hpp"
 #include "catch_common.h"
 
-#include <vector>
-#include <set>
-#include <stdexcept>
-
-#include <iostream>
-
 namespace Catch
 {
-    class TestRegistry : public ITestCaseRegistry
-{
-public:
-    
-    virtual void registerTest( const TestCaseInfo& testInfo )
-    {
-        if( m_functions.find( testInfo ) == m_functions.end() )
-        {
-            m_functions.insert( testInfo );
-            m_functionsInOrder.push_back( testInfo );
-        }
-    }
-        
-    virtual const std::vector<TestCaseInfo>& getAllTests() const
-    {
-        return m_functionsInOrder;
-    }
-        
-private:
-        
-    std::set<TestCaseInfo> m_functions;
-    std::vector<TestCaseInfo> m_functionsInOrder;
-};
-
 typedef void(*TestFunction)();
     
-struct FreeFunctionTestCase : ITestCase
-{
-    FreeFunctionTestCase( TestFunction fun )
-    : fun( fun )
-    {}
-    
-    virtual void invoke() const
-    {
-        fun();
-    }
-    
-    virtual ITestCase* clone() const
-    {
-        return new FreeFunctionTestCase( fun );
-    }
-
-    virtual bool operator == ( const ITestCase& other ) const
-    {
-        const FreeFunctionTestCase* ffOther = dynamic_cast<const FreeFunctionTestCase*> ( &other );
-        return ffOther && fun == ffOther->fun;
-    }
-    
-    virtual bool operator < ( const ITestCase& other ) const
-    {
-        const FreeFunctionTestCase* ffOther = dynamic_cast<const FreeFunctionTestCase*> ( &other );
-        return ffOther && fun < ffOther->fun;
-    }
-    
-private:
-    TestFunction fun;
-};
-
 template<typename C>
 struct MethodTestCase : ITestCase
 {
@@ -122,9 +60,11 @@ struct AutoReg
     template<typename C>
     AutoReg( void (C::*method)(), const char* name, const char* description )
     {
-        Hub::getTestCaseRegistry().registerTest( TestCaseInfo( new MethodTestCase<C>( method ), name, description ) );
+        registerTestCase( new MethodTestCase<C>( method ), name, description );
     }
     
+    void registerTestCase( ITestCase* testCase, const char* name, const char* description );
+    
     ~AutoReg();
     
 private: