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

Removed Runner class

- it served no purpose - split into functions instead
Commit
34fa25ed2f50c1a6d235ab6fc684cc14cda6c834
Author
Phil Nash ·
Parents
85c807478466

Files · Download .tar.gz

Changes

 include/catch_runner.hpp       | 131 ++++++++++++++++++-----------------------
 include/internal/catch_ptr.hpp |   3 +-
 2 files changed, 59 insertions(+), 75 deletions(-)

diff --git a/include/catch_runner.hpp b/include/catch_runner.hpp
index ab6cad3c..3e08884d 100644
--- a/include/catch_runner.hpp
+++ b/include/catch_runner.hpp
@@ -21,89 +21,76 @@
 
 namespace Catch {
 
-    class Runner {
-
-    public:
-        Runner( Ptr<Config> const& config )
-        :   m_config( config )
-        {
-            openStream();
-            makeReporter();
+    Ptr<IStreamingReporter> makeReporter( Ptr<Config> const& config ) {
+        std::string reporterName = config->getReporterName().empty()
+            ? "console"
+            : config->getReporterName();
+        
+        Ptr<IStreamingReporter> reporter = getRegistryHub().getReporterRegistry().create( reporterName, config.get() );
+        if( !reporter ) {
+            std::ostringstream oss;
+            oss << "No reporter registered with name: '" << reporterName << "'";
+            throw std::domain_error( oss.str() );
+        }
+        return reporter;
+    }
+    
+    void openStreamInto( Ptr<Config> const& config, std::ofstream& ofs ) {
+        // Open output file, if specified
+        if( !config->getFilename().empty() ) {
+            ofs.open( config->getFilename().c_str() );
+            if( ofs.fail() ) {
+                std::ostringstream oss;
+                oss << "Unable to open file: '" << config->getFilename() << "'";
+                throw std::domain_error( oss.str() );
+            }
+            config->setStreamBuf( ofs.rdbuf() );
         }
+    }
+    
+    Totals runTests( Ptr<Config> const& config ) {
 
-        Totals runTests() {
+        std::ofstream ofs;
+        openStreamInto( config, ofs );
+        Ptr<IStreamingReporter> reporter = makeReporter( config );
 
-            RunContext context( m_config.get(), m_reporter );
+        RunContext context( config.get(), reporter );
 
-            Totals totals;
+        Totals totals;
 
-            context.testGroupStarting( context.config()->name(), 1, 1 );
+        context.testGroupStarting( config->name(), 1, 1 );
 
-            TestSpec testSpec = m_config->testSpec();
-            if( !testSpec.hasFilters() )
-                testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "~[.]" ).testSpec(); // All not hidden tests
+        TestSpec testSpec = config->testSpec();
+        if( !testSpec.hasFilters() )
+            testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "~[.]" ).testSpec(); // All not hidden tests
 
-            std::vector<TestCase> testCases;
-            getRegistryHub().getTestCaseRegistry().getFilteredTests( testSpec, *m_config, testCases );
+        std::vector<TestCase> testCases;
+        getRegistryHub().getTestCaseRegistry().getFilteredTests( testSpec, *config, testCases );
 
-            int testsRunForGroup = 0;
-            for( std::vector<TestCase>::const_iterator it = testCases.begin(), itEnd = testCases.end();
-                    it != itEnd;
-                    ++it ) {
-                testsRunForGroup++;
-                if( m_testsAlreadyRun.find( *it ) == m_testsAlreadyRun.end() ) {
+        std::set<TestCase> testsAlreadyRun;
+        for( std::vector<TestCase>::const_iterator it = testCases.begin(), itEnd = testCases.end();
+                it != itEnd;
+                ++it ) {
+            if( testsAlreadyRun.find( *it ) == testsAlreadyRun.end() ) {
 
-                    if( context.aborting() )
-                        break;
+                if( context.aborting() )
+                    break;
 
-                    totals += context.runTest( *it );
-                    m_testsAlreadyRun.insert( *it );
-                }
+                totals += context.runTest( *it );
+                testsAlreadyRun.insert( *it );
             }
-            std::vector<TestCase> skippedTestCases;
-            getRegistryHub().getTestCaseRegistry().getFilteredTests( testSpec, *m_config, skippedTestCases, true );
-            
-            for( std::vector<TestCase>::const_iterator it = skippedTestCases.begin(), itEnd = skippedTestCases.end();
-                    it != itEnd;
-                    ++it )
-                m_reporter->skipTest( *it );
-
-            context.testGroupEnded( context.config()->name(), totals, 1, 1 );
-            return totals;
         }
+        std::vector<TestCase> skippedTestCases;
+        getRegistryHub().getTestCaseRegistry().getFilteredTests( testSpec, *config, skippedTestCases, true );
+        
+        for( std::vector<TestCase>::const_iterator it = skippedTestCases.begin(), itEnd = skippedTestCases.end();
+                it != itEnd;
+                ++it )
+            reporter->skipTest( *it );
 
-    private:
-        void openStream() {
-            // Open output file, if specified
-            if( !m_config->getFilename().empty() ) {
-                m_ofs.open( m_config->getFilename().c_str() );
-                if( m_ofs.fail() ) {
-                    std::ostringstream oss;
-                    oss << "Unable to open file: '" << m_config->getFilename() << "'";
-                    throw std::domain_error( oss.str() );
-                }
-                m_config->setStreamBuf( m_ofs.rdbuf() );
-            }
-        }
-        void makeReporter() {
-            std::string reporterName = m_config->getReporterName().empty()
-                ? "console"
-                : m_config->getReporterName();
-
-            m_reporter = getRegistryHub().getReporterRegistry().create( reporterName, m_config.get() );
-            if( !m_reporter ) {
-                std::ostringstream oss;
-                oss << "No reporter registered with name: '" << reporterName << "'";
-                throw std::domain_error( oss.str() );
-            }
-        }
-
-    private:
-        Ptr<Config> m_config;
-        std::ofstream m_ofs;
-        Ptr<IStreamingReporter> m_reporter;
-        std::set<TestCase> m_testsAlreadyRun;
-    };
+        context.testGroupEnded( config->name(), totals, 1, 1 );
+        return totals;
+    }
     
     void applyFilenamesAsTags() {
         std::vector<TestCase> const& tests = getRegistryHub().getTestCaseRegistry().getAllTests();
@@ -200,13 +187,11 @@ namespace Catch {
                 
                 seedRng( *m_config );
 
-                Runner runner( m_config );
-
                 // Handle list request
                 if( Option<std::size_t> listed = list( config() ) )
                     return static_cast<int>( *listed );
 
-                return static_cast<int>( runner.runTests().assertions.failed );
+                return static_cast<int>( runTests( m_config ).assertions.failed );
             }
             catch( std::exception& ex ) {
                 Catch::cerr() << ex.what() << std::endl;
diff --git a/include/internal/catch_ptr.hpp b/include/internal/catch_ptr.hpp
index e37da385..940e5d19 100644
--- a/include/internal/catch_ptr.hpp
+++ b/include/internal/catch_ptr.hpp
@@ -52,8 +52,7 @@ namespace Catch {
             return *this;
         }
         void swap( Ptr& other ) { std::swap( m_p, other.m_p ); }
-        T* get() { return m_p; }
-        const T* get() const{ return m_p; }
+        T* get() const{ return m_p; }
         T& operator*() const { return *m_p; }
         T* operator->() const { return m_p; }
         bool operator !() const { return m_p == CATCH_NULL; }