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

Resolve reporter outside of Config

config now only only holds reporter name
Commit
5d73c5a008cf5511dc7d39c4df80b946a6ed3879
Author
Phil Nash ·
Parents
8fbd8e0f9eb7

Files · Download .tar.gz

Changes

 include/catch_runner.hpp              | 27 +++++++-------
 include/internal/catch_config.hpp     | 17 ---------
 include/internal/catch_list.hpp       |  4 --
 projects/SelfTest/ConditionTests.cpp  | 41 ++++++++++++++++++++-
 projects/SelfTest/TestMain.cpp        |  2 +-
 projects/SelfTest/catch_self_test.cpp |  5 +--
 single_include/catch.hpp              | 69 +++++++++++++----------------------
 7 files changed, 80 insertions(+), 85 deletions(-)

diff --git a/include/catch_runner.hpp b/include/catch_runner.hpp
index 2c66e179..3c8025b3 100644
--- a/include/catch_runner.hpp
+++ b/include/catch_runner.hpp
@@ -28,6 +28,18 @@ namespace Catch {
 
     inline int Main( Config& config ) {
     
+        std::string reporterName = config.data().reporter.empty()
+            ? "basic"
+            : config.data().reporter;
+        Ptr<IReporter> reporter = getCurrentContext().getReporterRegistry().create( reporterName, config );
+
+        if( !config.data().stream.empty() ) {
+            if( config.data().stream[0] == '%' )
+                config.useStream( config.data().stream.substr( 1 ) );
+            else
+                config.setFilename( config.data().stream );
+        }
+
         // Handle list request
         if( config.listWhat() != List::None )
             return List( config );
@@ -47,7 +59,7 @@ namespace Catch {
         
         // Scope here for the Runner so it can use the context before it is cleaned-up
         {
-            Runner runner( config, config.getReporter() );
+            Runner runner( config, reporter );
 
             // Run test specs specified on the command line - or default to all
             if( !config.testsSpecified() ) {
@@ -107,18 +119,7 @@ namespace Catch {
                 return 0;
             }
         
-            parseIntoConfig( parser, config.data() );
-            
-            // !TBD: wire up (do this lazily?)
-            if( !config.data().reporter.empty() )
-                config.setReporter( config.data().reporter );
-
-            if( !config.data().stream.empty() ) {
-                if( config.data().stream[0] == '%' )
-                    config.useStream( config.data().stream.substr( 1 ) );
-                else
-                    config.setFilename( config.data().stream );
-            }
+            parseIntoConfig( parser, config.data() );            
         }
         catch( std::exception& ex ) {
             std::cerr << ex.what() <<  + "\n\nUsage: ...\n\n";
diff --git a/include/internal/catch_config.hpp b/include/internal/catch_config.hpp
index 15abcd70..ee56c1f4 100644
--- a/include/internal/catch_config.hpp
+++ b/include/internal/catch_config.hpp
@@ -82,12 +82,6 @@ namespace Catch {
             delete m_streambuf;
         }
         
-        void setReporter( const std::string& reporterName ) {
-            if( m_reporter.get() )
-                throw std::domain_error( "Only one reporter may be specified" );
-            setReporter( getCurrentContext().getReporterRegistry().create( reporterName, *this ) );
-        }
-
         void setFilename( const std::string& filename ) {
             m_data.outputFilename = filename;
         }
@@ -108,16 +102,6 @@ namespace Catch {
             return m_data.outputFilename ;
         }
         
-        void setReporter( IReporter* reporter ) {
-            m_reporter = reporter;
-        }
-        
-        Ptr<IReporter> getReporter() {
-            if( !m_reporter.get() )
-                const_cast<Config*>( this )->setReporter( getCurrentContext().getReporterRegistry().create( "basic", *this ) );
-            return m_reporter;
-        }
-                
         List::What listWhat() const {
             return static_cast<List::What>( m_data.listSpec & List::WhatMask );
         }        
@@ -169,7 +153,6 @@ namespace Catch {
         ConfigData m_data;
         
         // !TBD Move these out of here
-        Ptr<IReporter> m_reporter;
         std::streambuf* m_streambuf;
         mutable std::ostream m_os;
     };
diff --git a/include/internal/catch_list.hpp b/include/internal/catch_list.hpp
index c7b19cc5..b68fd6a2 100644
--- a/include/internal/catch_list.hpp
+++ b/include/internal/catch_list.hpp
@@ -42,10 +42,6 @@ namespace Catch {
             return (std::numeric_limits<int>::max)();
         }
         
-        if( config.getReporter().get() )
-            std::cerr << "Reporters ignored when listing" << std::endl;
-        if( !config.testsSpecified() )
-            std::cerr << "Test specs ignored when listing" << std::endl;
         return 0;
     }
     
diff --git a/projects/SelfTest/ConditionTests.cpp b/projects/SelfTest/ConditionTests.cpp
index 4d2fb945..db70611b 100644
--- a/projects/SelfTest/ConditionTests.cpp
+++ b/projects/SelfTest/ConditionTests.cpp
@@ -15,8 +15,7 @@
 #include <string>
 #include <limits>
 
-struct TestData
-{
+struct TestData {
     TestData()
     :   int_seven( 7 ),
         str_hello( "hello" ),
@@ -30,6 +29,25 @@ struct TestData
     double double_pi;
 };
 
+
+struct TestDef {
+    TestDef& operator + ( const std::string& ) {
+        return *this;
+    }
+    TestDef& operator[]( const std::string& ) {
+        return *this;
+    }
+    
+};
+
+//TEST( "./succeeding/conditions/equality"  + Description("nyaya") )
+//{
+//    TEST_CASE( [Name("inner")] )
+//    {
+//        
+//    }
+//}
+
 // The "failing" tests all use the CHECK macro, which continues if the specific test fails.
 // This allows us to see all results, even if an earlier check fails
 
@@ -37,6 +55,10 @@ struct TestData
 TEST_CASE(  "./succeeding/conditions/equality", 
             "Equality checks that should succeed" )
 {
+
+    TestDef td;
+    td + "hello" + "hello";
+    
     TestData data;
     
     REQUIRE( data.int_seven == 7 );
@@ -225,6 +247,21 @@ TEST_CASE(  "./succeeding/conditions/negative ints",
     CHECK( minInt > 2u );
 }
 
+template<typename T>
+struct Ex
+{
+    Ex( T ){}
+    
+    bool operator == ( const T& ) const { return true; }
+    T operator * ( const T& ) const { return T(); }
+};
+
+TEST_CASE(  "./succeeding/conditions/computed ints",
+            "Comparisons between ints where one side is computed" )
+{
+     CHECK( 54 == 6*9 );
+}
+
 #pragma GCC diagnostic pop
 
 
diff --git a/projects/SelfTest/TestMain.cpp b/projects/SelfTest/TestMain.cpp
index 65bcdab3..599edf4f 100644
--- a/projects/SelfTest/TestMain.cpp
+++ b/projects/SelfTest/TestMain.cpp
@@ -33,7 +33,7 @@ TEST_CASE( "selftest/main", "Runs all Catch self tests and checks their results"
         SECTION(    "selftest/test counts/succeeding tests", 
                     "Number of 'succeeding' tests is fixed" ) {
             runner.runMatching( "./succeeding/*" );
-            CHECK( runner.getTotals().assertions.passed == 284 );
+            CHECK( runner.getTotals().assertions.passed == 285 );
             CHECK( runner.getTotals().assertions.failed == 0 );
         }
 
diff --git a/projects/SelfTest/catch_self_test.cpp b/projects/SelfTest/catch_self_test.cpp
index 8910f13a..96ffdbd4 100644
--- a/projects/SelfTest/catch_self_test.cpp
+++ b/projects/SelfTest/catch_self_test.cpp
@@ -20,14 +20,11 @@ namespace Catch{
         Config config;
         config.setStreamBuf( oss.rdbuf() );
         
-        //if( reporter == "mock" ) // !TBD
-            config.setReporter( m_reporter.get() );
-        
         std::size_t result;
         
         // Scoped because Runner doesn't report EndTesting until its destructor
         {
-            Runner runner( config, config.getReporter() );
+            Runner runner( config, m_reporter.get() );
             result = runner.runMatching( rawTestSpec );
             m_totals = runner.getTotals();
         }
diff --git a/single_include/catch.hpp b/single_include/catch.hpp
index e4267200..62741f8f 100644
--- a/single_include/catch.hpp
+++ b/single_include/catch.hpp
@@ -1,5 +1,5 @@
 /*
- *  Generated: 2012-07-05 18:47:13.729198
+ *  Generated: 2012-07-17 08:02:44.293339
  *  ----------------------------------------------------------
  *  This file has been merged from multiple headers. Please don't edit it directly
  *  Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved.
@@ -2500,12 +2500,6 @@ namespace Catch {
             delete m_streambuf;
         }
 
-        void setReporter( const std::string& reporterName ) {
-            if( m_reporter.get() )
-                throw std::domain_error( "Only one reporter may be specified" );
-            setReporter( getCurrentContext().getReporterRegistry().create( reporterName, *this ) );
-        }
-
         void setFilename( const std::string& filename ) {
             m_data.outputFilename = filename;
         }
@@ -2526,16 +2520,6 @@ namespace Catch {
             return m_data.outputFilename ;
         }
 
-        void setReporter( IReporter* reporter ) {
-            m_reporter = reporter;
-        }
-
-        Ptr<IReporter> getReporter() {
-            if( !m_reporter.get() )
-                const_cast<Config*>( this )->setReporter( getCurrentContext().getReporterRegistry().create( "basic", *this ) );
-            return m_reporter;
-        }
-
         List::What listWhat() const {
             return static_cast<List::What>( m_data.listSpec & List::WhatMask );
         }
@@ -2587,7 +2571,6 @@ namespace Catch {
         ConfigData m_data;
 
         // !TBD Move these out of here
-        Ptr<IReporter> m_reporter;
         std::streambuf* m_streambuf;
         mutable std::ostream m_os;
     };
@@ -2814,11 +2797,11 @@ namespace Catch {
 
     public:
 
-        explicit Runner( Config& config )
+        explicit Runner( Config& config, const Ptr<IReporter>& reporter )
         :   m_context( getCurrentMutableContext() ),
             m_runningTest( NULL ),
             m_config( config ),
-            m_reporter( config.getReporter() ),
+            m_reporter( reporter ),
             m_prevRunner( &m_context.getRunner() ),
             m_prevResultCapture( &m_context.getResultCapture() ),
             m_prevConfig( m_context.getConfig() )
@@ -2838,6 +2821,7 @@ namespace Catch {
         }
 
         virtual void runAll( bool runHiddenTests = false ) {
+            m_reporter->StartGroup( "" );
             const std::vector<TestCaseInfo>& allTests = getCurrentContext().getTestCaseRegistry().getAllTests();
             for( std::size_t i=0; i < allTests.size(); ++i ) {
                 if( runHiddenTests || !allTests[i].isHidden() ) {
@@ -2848,9 +2832,14 @@ namespace Catch {
                     runTest( allTests[i] );
                 }
             }
+            m_reporter->EndGroup( "", getTotals() );
         }
 
         virtual std::size_t runMatching( const std::string& rawTestSpec ) {
+
+            Totals prevTotals = getTotals();
+            m_reporter->StartGroup( rawTestSpec );
+
             TestSpec testSpec( rawTestSpec );
 
             const std::vector<TestCaseInfo>& allTests = getCurrentContext().getTestCaseRegistry().getAllTests();
@@ -2865,6 +2854,7 @@ namespace Catch {
                     testsRun++;
                 }
             }
+            m_reporter->EndGroup( rawTestSpec, getTotals() - prevTotals );
             return testsRun;
         }
 
@@ -3701,10 +3691,6 @@ namespace Catch {
             return (std::numeric_limits<int>::max)();
         }
 
-        if( config.getReporter().get() )
-            std::cerr << "Reporters ignored when listing" << std::endl;
-        if( !config.testsSpecified() )
-            std::cerr << "Test specs ignored when listing" << std::endl;
         return 0;
     }
 
@@ -4612,6 +4598,18 @@ namespace Catch {
 
     inline int Main( Config& config ) {
 
+        std::string reporterName = config.data().reporter.empty()
+            ? "basic"
+            : config.data().reporter;
+        Ptr<IReporter> reporter = getCurrentContext().getReporterRegistry().create( reporterName, config );
+
+        if( !config.data().stream.empty() ) {
+            if( config.data().stream[0] == '%' )
+                config.useStream( config.data().stream.substr( 1 ) );
+            else
+                config.setFilename( config.data().stream );
+        }
+
         // Handle list request
         if( config.listWhat() != List::None )
             return List( config );
@@ -4631,13 +4629,11 @@ namespace Catch {
 
         // Scope here for the Runner so it can use the context before it is cleaned-up
         {
-            Runner runner( config );
+            Runner runner( config, reporter );
 
             // Run test specs specified on the command line - or default to all
             if( !config.testsSpecified() ) {
-                config.getReporter()->StartGroup( "" );
                 runner.runAll();
-                config.getReporter()->EndGroup( "", runner.getTotals() );
             }
             else {
                 // !TBD We should get all the testcases upfront, report any missing,
@@ -4645,13 +4641,9 @@ namespace Catch {
                 std::vector<std::string>::const_iterator it = config.getTestSpecs().begin();
                 std::vector<std::string>::const_iterator itEnd = config.getTestSpecs().end();
                 for(; it != itEnd; ++it ) {
-                    Totals prevTotals = runner.getTotals();
-                    config.getReporter()->StartGroup( *it );
                     if( runner.runMatching( *it ) == 0 ) {
-                        // Use reporter?
-    //                    std::cerr << "\n[Unable to match any test cases with: " << *it << "]" << std::endl;
+                        std::cerr << "\n[No test cases matched with: " << *it << "]" << std::endl;
                     }
-                    config.getReporter()->EndGroup( *it, runner.getTotals() - prevTotals );
                 }
             }
             result = static_cast<int>( runner.getTotals().assertions.failed );
@@ -4669,7 +4661,7 @@ namespace Catch {
             << "\t-s, --success\n"
             << "\t-b, --break\n"
             << "\t-n, --name <name>\n"
-            << "\t-a, --abort [#]\n\n"
+            << "\t-a, --abort [#]\n"
             << "\t-nt, --nothrow\n\n"
             << "For more detail usage please see: https://github.com/philsquared/Catch/wiki/Command-line" << std::endl;
     }
@@ -4698,17 +4690,6 @@ namespace Catch {
             }
 
             parseIntoConfig( parser, config.data() );
-
-            // !TBD: wire up (do this lazily?)
-            if( !config.data().reporter.empty() )
-                config.setReporter( config.data().reporter );
-
-            if( !config.data().stream.empty() ) {
-                if( config.data().stream[0] == '%' )
-                    config.useStream( config.data().stream.substr( 1 ) );
-                else
-                    config.setFilename( config.data().stream );
-            }
         }
         catch( std::exception& ex ) {
             std::cerr << ex.what() <<  + "\n\nUsage: ...\n\n";