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

Some code clean-up

Commit
b81e0b9e9ce060f02842f561127045e8b18a3d60
Author
Phil Nash ·
Parents
1172d26705a2

Files · Download .tar.gz

Changes

 internal/catch_capture.hpp         |  18 +++----
 internal/catch_config.hpp          |  31 +++++++++--
 internal/catch_hub.h               |  29 +++++++---
 internal/catch_interfaces_runner.h |  16 ++++--
 internal/catch_resultinfo.hpp      |  27 +++++++++-
 internal/catch_runner_impl.hpp     | 108 ++++++++++++++++++++++++++++++-------
 6 files changed, 182 insertions(+), 47 deletions(-)

diff --git a/internal/catch_capture.hpp b/internal/catch_capture.hpp
index b220a4f8..89752a20 100644
--- a/internal/catch_capture.hpp
+++ b/internal/catch_capture.hpp
@@ -82,23 +82,23 @@ std::string toString( const T& value )
 {
     return Detail::StringMaker<T, Detail::IsStreamable<T>::value>::apply( value );
 }
-
-template<>
-inline std::string toString<std::string>( const std::string& value )
+    
+// Shortcut overloads
+inline std::string toString( const std::string& value )
 {
     return value;
 }
-
-template<>
-inline std::string toString<int>( const int& value )
+inline std::string toString( const char* value )
+{
+    return value;
+}    
+inline std::string toString( int value )
 {
     std::ostringstream oss;
     oss << value;
     return oss.str();
 }
-    
-template<>
-inline std::string toString<double>( const double& value )
+inline std::string toString( const double value )
 {
     std::ostringstream oss;
     oss << value;
diff --git a/internal/catch_config.hpp b/internal/catch_config.hpp
index 672fe6d9..aba2393f 100644
--- a/internal/catch_config.hpp
+++ b/internal/catch_config.hpp
@@ -53,6 +53,7 @@ namespace Catch
         }; };
         
         
+        ///////////////////////////////////////////////////////////////////////////
         Config()
         :   m_reporter( NULL ),
             m_listSpec( List::None ),
@@ -62,6 +63,7 @@ namespace Catch
             m_includeWhat( Include::FailedOnly )
         {}
         
+        ///////////////////////////////////////////////////////////////////////////
         void setReporter( const std::string& reporterName )
         {
             if( m_reporter.get() )
@@ -69,73 +71,93 @@ namespace Catch
             setReporter( Hub::getReporterRegistry().create( reporterName, *this ) );
         }
         
+        ///////////////////////////////////////////////////////////////////////////
         void addTestSpec( const std::string& testSpec )
         {
             m_testSpecs.push_back( testSpec );
         }
+
+        ///////////////////////////////////////////////////////////////////////////
         void setListSpec( List::What listSpec )
         {
             m_listSpec = listSpec;
         }
         
+        ///////////////////////////////////////////////////////////////////////////
         void setFilename( const std::string& filename )
         {
             m_filename = filename;
         }
         
+        ///////////////////////////////////////////////////////////////////////////
         std::string getFilename()
         {
             return m_filename;
         }
         
+        ///////////////////////////////////////////////////////////////////////////
         void setError( const std::string& errorMessage )
         {
             m_message = errorMessage + "\n\n" + "Usage: ...";
         }
         
+        ///////////////////////////////////////////////////////////////////////////
         void setReporter( IReporter* reporter )
         {
             m_reporter = std::auto_ptr<IReporter>( reporter );
         }
         
+        ///////////////////////////////////////////////////////////////////////////
         IReporter* getReporter()
         {
             if( !m_reporter.get() )
                 setReporter( Hub::getReporterRegistry().create( "basic", *this ) );
             return m_reporter.get();
         }
-        
+                
+        ///////////////////////////////////////////////////////////////////////////
         IReporter* getReporter() const
         {
             return const_cast<Config*>( this )->getReporter();
-        }
+        }        
         
+        ///////////////////////////////////////////////////////////////////////////
         List::What listWhat() const
         {
             return (List::What)( m_listSpec & List::WhatMask );
-        }
+        }        
         
+        ///////////////////////////////////////////////////////////////////////////
         List::What listAs() const
         {
             return (List::What)( m_listSpec & List::AsMask );
         }        
         
+        ///////////////////////////////////////////////////////////////////////////
         void setIncludeWhat( Include::What includeWhat )
         {
             m_includeWhat = includeWhat;
         }
+        
+        ///////////////////////////////////////////////////////////////////////////
         void setShouldDebugBreak( bool shouldDebugBreak )
         {
             m_shouldDebugBreak = shouldDebugBreak;
         }
+
+        ///////////////////////////////////////////////////////////////////////////
         bool shouldDebugBreak() const
         {
             return m_shouldDebugBreak;
         }
+
+        ///////////////////////////////////////////////////////////////////////////
         void setShowHelp( bool showHelp )
         {
             m_showHelp = showHelp;
         }
+
+        ///////////////////////////////////////////////////////////////////////////
         bool showHelp() const
         {
             return m_showHelp;
@@ -159,8 +181,7 @@ namespace Catch
             return m_includeWhat == Include::SuccessfulResults;
         }
         
-        
-        
+                
         std::auto_ptr<IReporter> m_reporter;
         std::string m_filename;
         std::string m_message;
diff --git a/internal/catch_hub.h b/internal/catch_hub.h
index 71212c8e..c49a130f 100644
--- a/internal/catch_hub.h
+++ b/internal/catch_hub.h
@@ -19,7 +19,7 @@
 
 namespace Catch
 {
-    struct TestCaseInfo;
+    class TestCaseInfo;
     struct IResultCapture;
     struct ITestCaseRegistry;
     struct IRunner;
@@ -27,17 +27,30 @@ namespace Catch
     class Hub
     {
         Hub();
+        
         static Hub& me();
         
     public:
         
-        static void setRunner( IRunner* runner );
-        static void setResultCapture( IResultCapture* resultCapture );
-
-        static IResultCapture& getResultCapture();
-        static IReporterRegistry& getReporterRegistry();
-        static ITestCaseRegistry& getTestCaseRegistry();
-        static IRunner& getRunner();
+        static void setRunner
+            ( IRunner* runner 
+            );
+        
+        static void setResultCapture
+            ( IResultCapture* resultCapture 
+            );
+        
+        static IResultCapture& getResultCapture
+            ();
+        
+        static IReporterRegistry& getReporterRegistry
+            ();
+        
+        static ITestCaseRegistry& getTestCaseRegistry
+            ();
+        
+        static IRunner& getRunner
+            ();
         
     private:
         std::auto_ptr<IReporterRegistry> m_reporterRegistry;
diff --git a/internal/catch_interfaces_runner.h b/internal/catch_interfaces_runner.h
index 1037f51a..c81a52b4 100644
--- a/internal/catch_interfaces_runner.h
+++ b/internal/catch_interfaces_runner.h
@@ -18,10 +18,18 @@ namespace Catch
 {
     struct IRunner
     {
-        virtual void runAll() = 0;
-        virtual std::size_t runMatching( const std::string& rawTestSpec ) = 0;
-        virtual std::size_t getSuccessCount() const = 0;
-        virtual std:: size_t getFailureCount() const = 0;
+        virtual void runAll
+            () = 0;
+        
+        virtual std::size_t runMatching
+            ( const std::string& rawTestSpec 
+            ) = 0;
+        
+        virtual std::size_t getSuccessCount
+            () const = 0;
+        
+        virtual std:: size_t getFailureCount
+            () const = 0;
         
     };
 }
diff --git a/internal/catch_resultinfo.hpp b/internal/catch_resultinfo.hpp
index c58c6d2b..41676965 100644
--- a/internal/catch_resultinfo.hpp
+++ b/internal/catch_resultinfo.hpp
@@ -21,6 +21,7 @@ namespace Catch
     {
     public:
         
+        ///////////////////////////////////////////////////////////////////////////
         ResultInfo()
         :   m_line( 0 ),
             m_result( ResultWas::Unknown ),
@@ -28,7 +29,16 @@ namespace Catch
             m_expressionIncomplete( false )
         {}
         
-        ResultInfo( const char* expr, ResultWas::OfType result, bool isNot, const char* filename, std::size_t line, const char* macroName )
+        ///////////////////////////////////////////////////////////////////////////
+        ResultInfo
+        (
+            const char* expr, 
+            ResultWas::OfType result, 
+            bool isNot, 
+            const char* filename, 
+            std::size_t line, 
+            const char* macroName 
+        )
         :   m_macroName( macroName ),
             m_filename( filename ),
             m_line( line ),
@@ -42,28 +52,37 @@ namespace Catch
                 m_expr = "!" + m_expr;
         }
         
+        ///////////////////////////////////////////////////////////////////////////
         bool ok() const
         {
             return ( m_result & ResultWas::FailureBit ) != ResultWas::FailureBit;
         }
         
+        ///////////////////////////////////////////////////////////////////////////
         ResultWas::OfType getResultType() const
         {
             return m_result;
         }
         
+        ///////////////////////////////////////////////////////////////////////////
         bool hasExpression() const
         {
             return !m_expr.empty();
         }
+
+        ///////////////////////////////////////////////////////////////////////////
         bool hasMessage() const
         {
             return !m_message.empty();
         }
+
+        ///////////////////////////////////////////////////////////////////////////
         std::string getExpression() const
         {
             return m_expr;
         }
+
+        ///////////////////////////////////////////////////////////////////////////
         std::string getExpandedExpression() const
         {
             if( !hasExpression() )
@@ -74,27 +93,33 @@ namespace Catch
                 : getExpandedExpressionInternal();
         }
         
+        ///////////////////////////////////////////////////////////////////////////
         std::string getMessage() const
         {
             return m_message;
         }
         
+        ///////////////////////////////////////////////////////////////////////////
         std::string getFilename() const
         {
             return m_filename;
         }
         
+        ///////////////////////////////////////////////////////////////////////////
         std::size_t getLine() const
         {
             return m_line;
         }
         
+        ///////////////////////////////////////////////////////////////////////////
         std::string getTestMacroName() const
         {
             return m_macroName;
         }
 
     protected:
+
+        ///////////////////////////////////////////////////////////////////////////
         std::string getExpandedExpressionInternal() const
         {
             if( m_op == "" || m_isNot )
diff --git a/internal/catch_runner_impl.hpp b/internal/catch_runner_impl.hpp
index 8230cbc6..004757d4 100644
--- a/internal/catch_runner_impl.hpp
+++ b/internal/catch_runner_impl.hpp
@@ -71,13 +71,19 @@ namespace Catch
         std::string& m_targetString;
     };
     
+
     class Runner : public IResultCapture, public IRunner
     {
         Runner( const Runner& );
         void operator =( const Runner& );
         
     public:
-        explicit Runner( const Config& config )
+
+        ///////////////////////////////////////////////////////////////////////////
+        explicit Runner
+        (
+            const Config& config 
+        )
         :   m_config( config ),
             m_successes( 0 ),
             m_failures( 0 ),
@@ -88,14 +94,18 @@ namespace Catch
             m_reporter->StartTesting();
         }
         
-        ~Runner()
+        ///////////////////////////////////////////////////////////////////////////
+        ~Runner
+        ()
         {
             m_reporter->EndTesting( m_successes, m_failures );
             Hub::setRunner( NULL );
             Hub::setResultCapture( NULL );
         }
         
-        virtual void runAll()
+        ///////////////////////////////////////////////////////////////////////////
+        virtual void runAll
+        ()
         {
             std::vector<TestCaseInfo> allTests = Hub::getTestCaseRegistry().getAllTests();
             for( std::size_t i=0; i < allTests.size(); ++i )
@@ -104,7 +114,11 @@ namespace Catch
             }
         }
         
-        virtual std::size_t runMatching( const std::string& rawTestSpec )
+        ///////////////////////////////////////////////////////////////////////////
+        virtual std::size_t runMatching
+        (
+            const std::string& rawTestSpec
+        )
         {
             TestSpec testSpec( rawTestSpec );
             
@@ -121,7 +135,11 @@ namespace Catch
             return testsRun;
         }
         
-        void runTest( const TestCaseInfo& testInfo )
+        ///////////////////////////////////////////////////////////////////////////
+        void runTest
+        (
+            const TestCaseInfo& testInfo
+        )
         {
             m_reporter->StartTestCase( testInfo );
             
@@ -152,24 +170,38 @@ namespace Catch
             m_reporter->EndTestCase( testInfo, redirectedCout, redirectedCerr );
         }
         
-        virtual std::size_t getSuccessCount() const
+        ///////////////////////////////////////////////////////////////////////////
+        virtual std::size_t getSuccessCount
+        ()
+        const
         {
             return m_successes;
         }
         
-        virtual std:: size_t getFailureCount() const
+        ///////////////////////////////////////////////////////////////////////////
+        virtual std:: size_t getFailureCount
+        ()
+        const
         {
             return m_failures;
         }
 
     private: // IResultCapture
 
-        virtual ResultAction::Value acceptResult( bool result )
+        ///////////////////////////////////////////////////////////////////////////
+        virtual ResultAction::Value acceptResult
+        (
+            bool result
+        )
         {
             return acceptResult( result ? ResultWas::Ok : ResultWas::ExpressionFailed );
         }
 
-        virtual ResultAction::Value acceptResult( ResultWas::OfType result )
+        ///////////////////////////////////////////////////////////////////////////
+        virtual ResultAction::Value acceptResult
+        (
+            ResultWas::OfType result
+        )
         {
             m_currentResult.setResultType( result );            
             testEnded( m_currentResult );
@@ -185,19 +217,29 @@ namespace Catch
             
         }
 
-        virtual void acceptExpression( const MutableResultInfo& resultInfo )
+        ///////////////////////////////////////////////////////////////////////////
+        virtual void acceptExpression
+        (
+            const MutableResultInfo& resultInfo
+        )
         {
             m_currentResult = resultInfo;
         }
 
-        virtual void acceptMessage( const std::string& msg )
+        ///////////////////////////////////////////////////////////////////////////
+        virtual void acceptMessage
+        (
+            const std::string& msg
+        )
         {
             m_currentResult.setMessage( msg );
         }
-        
-        ///
-        
-        virtual void testEnded( const ResultInfo& result )
+                
+        ///////////////////////////////////////////////////////////////////////////
+        virtual void testEnded
+        (
+            const ResultInfo& result        
+        )
         { 
             if( result.getResultType() == ResultWas::Ok )
             {
@@ -220,7 +262,14 @@ namespace Catch
                 m_reporter->Result( result );
         }
 
-        virtual bool sectionStarted( const std::string& name, const std::string& description, std::size_t& successes, std::size_t& failures )
+        ///////////////////////////////////////////////////////////////////////////
+        virtual bool sectionStarted
+        (
+            const std::string& name, 
+            const std::string& description, 
+            std::size_t& successes, \
+            std::size_t& failures 
+        )
         {
             m_reporter->StartSection( name, description );
             successes = m_successes;
@@ -230,21 +279,40 @@ namespace Catch
             return true;
         }
         
-        virtual void sectionEnded( const std::string& name, std::size_t prevSuccesses, std::size_t prevFailures )
+        ///////////////////////////////////////////////////////////////////////////
+        virtual void sectionEnded
+        (
+            const std::string& name, 
+            std::size_t prevSuccesses, 
+            std::size_t prevFailures 
+        )
         {
             m_reporter->EndSection( name, m_successes - prevSuccesses, m_failures - prevFailures );
         }
 
-        virtual void pushScopedInfo( ScopedInfo* scopedInfo )
+        ///////////////////////////////////////////////////////////////////////////
+        virtual void pushScopedInfo
+        (
+            ScopedInfo* scopedInfo 
+        )
         {
             m_scopedInfos.push_back( scopedInfo );
         }
-        virtual void popScopedInfo( ScopedInfo* scopedInfo )
+
+        ///////////////////////////////////////////////////////////////////////////
+        virtual void popScopedInfo
+        (
+            ScopedInfo* scopedInfo
+        )
         {
             if( m_scopedInfos.back() == scopedInfo )
                 m_scopedInfos.pop_back();
         }
-        virtual bool shouldDebugBreak() const
+
+        ///////////////////////////////////////////////////////////////////////////
+        virtual bool shouldDebugBreak
+        () 
+        const
         {
             return m_config.shouldDebugBreak();
         }