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

Added SCOPED_CAPTURE

Commit
803f6b7e4b76f4002e639671fbea941e4efc518a
Author
Phil Nash ·
Parents
36d0da019435

Files · Download .tar.gz

Changes

 include/catch.hpp                  |  2 +
 projects/SelfTest/MessageTests.cpp |  5 +-
 single_include/catch.hpp           | 99 +++++++++++++++++++-------------------
 3 files changed, 55 insertions(+), 51 deletions(-)

diff --git a/include/catch.hpp b/include/catch.hpp
index 94f8c603..dc66cf00 100644
--- a/include/catch.hpp
+++ b/include/catch.hpp
@@ -73,6 +73,7 @@
 #define CATCH_SUCCEED( msg ) INTERNAL_CATCH_MSG( msg, Catch::ResultWas::Ok, false, "CATCH_SUCCEED" )
 #define CATCH_SCOPED_INFO( msg ) INTERNAL_CATCH_SCOPED_INFO( msg )
 #define CATCH_CAPTURE( msg ) INTERNAL_CATCH_MSG( #msg " := " << msg, Catch::ResultWas::Info, false, "CATCH_CAPTURE" )
+#define CATCH_SCOPED_CAPTURE( msg ) INTERNAL_CATCH_SCOPED_INFO( #msg " := " << msg )
 
 #define CATCH_SECTION( name, description ) INTERNAL_CATCH_SECTION( name, description )
 
@@ -117,6 +118,7 @@
 #define SUCCEED( msg ) INTERNAL_CATCH_MSG( msg, Catch::ResultWas::Ok, false, "SUCCEED" )
 #define SCOPED_INFO( msg ) INTERNAL_CATCH_SCOPED_INFO( msg )
 #define CAPTURE( msg ) INTERNAL_CATCH_MSG( #msg " := " << msg, Catch::ResultWas::Info, false, "CAPTURE" )
+#define SCOPED_CAPTURE( msg ) INTERNAL_CATCH_SCOPED_INFO( #msg " := " << msg )
 
 #define SECTION( name, description ) INTERNAL_CATCH_SECTION( name, description )
 
diff --git a/projects/SelfTest/MessageTests.cpp b/projects/SelfTest/MessageTests.cpp
index 36a5071a..776d7169 100644
--- a/projects/SelfTest/MessageTests.cpp
+++ b/projects/SelfTest/MessageTests.cpp
@@ -76,7 +76,8 @@ TEST_CASE( "./mixed/message/scoped", "" )
 {
     for( int i=0; i<100; i++ )
     {
-       SCOPED_INFO( "current counter " << i );
-       REQUIRE( i < 10 );
+        SCOPED_INFO( "current counter " << i );
+        SCOPED_CAPTURE( i );
+        REQUIRE( i < 10 );
     }
 }
diff --git a/single_include/catch.hpp b/single_include/catch.hpp
index 544a4ab3..26346e14 100644
--- a/single_include/catch.hpp
+++ b/single_include/catch.hpp
@@ -1,5 +1,5 @@
 /*
- *  Generated: 2012-09-29 20:53:48.580228
+ *  Generated: 2012-10-04 08:14:09.958803
  *  ----------------------------------------------------------
  *  This file has been merged from multiple headers. Please don't edit it directly
  *  Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved.
@@ -681,12 +681,6 @@ namespace Catch {
     class ResultInfo {
     public:
         ResultInfo();
-        ResultInfo( const char* expr,
-                    ResultWas::OfType result,
-                    bool isNot,
-                    const SourceLineInfo& lineInfo,
-                    const char* macroName,
-                   const char* message );
         ~ResultInfo();
 
         bool ok() const;
@@ -702,6 +696,12 @@ namespace Catch {
         std::string getTestMacroName() const;
 
     protected:
+        ResultInfo( const char* expr,
+                   ResultWas::OfType result,
+                   bool isNot,
+                   const SourceLineInfo& lineInfo,
+                   const char* macroName,
+                   const char* message );
 
         std::string getExpandedExpressionInternal() const;
         bool isNotExpression( const char* expr );
@@ -887,37 +887,31 @@ namespace Catch {
 struct STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison;
 
 class ResultInfoBuilder : public ResultInfo {
-
 public:
 
     ResultInfoBuilder();
 
-    ResultInfoBuilder(  const char* expr,
-                        bool isNot,
-                        const SourceLineInfo& lineInfo,
-                        const char* macroName,
-                        const char* message = "" );
-
-    void setResultType( ResultWas::OfType result );
-    void setMessage( const std::string& message );
-    void setLineInfo( const SourceLineInfo& lineInfo );
-    void setLhs( const std::string& lhs );
-    void setRhs( const std::string& rhs );
-    void setOp( const std::string& op );
+    ResultInfoBuilder& setResultType( ResultWas::OfType result );
+    ResultInfoBuilder& setMessage( const std::string& message );
+    ResultInfoBuilder& setLineInfo( const SourceLineInfo& lineInfo );
+    ResultInfoBuilder& setLhs( const std::string& lhs );
+    ResultInfoBuilder& setRhs( const std::string& rhs );
+    ResultInfoBuilder& setOp( const std::string& op );
+    ResultInfoBuilder& setMacroName( const std::string& macroName );
 
     template<typename RhsT>
-    STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator ||
-    (
-        const RhsT&
-    );
+    STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator || ( const RhsT& );
 
     template<typename RhsT>
-    STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator &&
-    (
-        const RhsT&
-    );
+    STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator && ( const RhsT& );
 
 private:
+
+    ResultInfoBuilder(  const char* expr,
+                      bool isNot,
+                      const SourceLineInfo& lineInfo,
+                      const char* macroName );
+
     friend class ExpressionBuilder;
     template<typename T> friend class Expression;
 
@@ -1310,7 +1304,10 @@ public:
     }
 
     ResultInfo getInfo () const {
-        return ResultInfo( "", ResultWas::Info, false, SourceLineInfo(), "SCOPED_INFO", m_oss.str().c_str() );
+        return ResultInfoBuilder()
+            .setResultType( ResultWas::Info )
+            .setMessage( m_oss.str() )
+            .setMacroName( "SCOPED_INFO" );
     }
 
 private:
@@ -1791,14 +1788,6 @@ namespace Catch {
             m_tags.insert( std::make_pair( tag.getName(), tag ) );
         }
 
-        // needed?
-        Tag find( const std::string& name ) const {
-            TagMap::const_iterator it = m_tags.find( name );
-            if( it == m_tags.end() )
-                return Tag();
-            else
-                return it->second;
-        }
         bool empty() const {
             return m_tags.empty();
         }
@@ -4911,7 +4900,7 @@ namespace Catch {
         m_isNot( isNot )
         {
             if( isNot )
-                m_expr = "!" + m_expr;
+                m_expr = "!(" + m_expr + ")";
         }
 
     ResultInfo::~ResultInfo() {}
@@ -4989,17 +4978,16 @@ namespace Catch {
 
 namespace Catch {
 
-    ResultInfoBuilder::ResultInfoBuilder() {}
-
     ResultInfoBuilder::ResultInfoBuilder(   const char* expr,
                                             bool isNot,
                                             const SourceLineInfo& lineInfo,
-                                            const char* macroName,
-                                            const char* message )
-    : ResultInfo( expr, ResultWas::Unknown, isNot, lineInfo, macroName, message )
+                                            const char* macroName )
+    : ResultInfo( expr, ResultWas::Unknown, isNot, lineInfo, macroName, "" )
     {}
 
-    void ResultInfoBuilder::setResultType( ResultWas::OfType result ) {
+    ResultInfoBuilder::ResultInfoBuilder() {}
+
+    ResultInfoBuilder& ResultInfoBuilder::setResultType( ResultWas::OfType result ) {
         // Flip bool results if isNot is set
         if( m_isNot && result == ResultWas::Ok )
             m_result = ResultWas::ExpressionFailed;
@@ -5007,26 +4995,37 @@ namespace Catch {
             m_result = ResultWas::Ok;
         else
             m_result = result;
+        return *this;
     }
 
-    void ResultInfoBuilder::setMessage( const std::string& message ) {
+    ResultInfoBuilder& ResultInfoBuilder::setMessage( const std::string& message ) {
         m_message = message;
+        return *this;
     }
 
-    void ResultInfoBuilder::setLineInfo( const SourceLineInfo& lineInfo ) {
+    ResultInfoBuilder& ResultInfoBuilder::setLineInfo( const SourceLineInfo& lineInfo ) {
         m_lineInfo = lineInfo;
+        return *this;
     }
 
-    void ResultInfoBuilder::setLhs( const std::string& lhs ) {
+    ResultInfoBuilder& ResultInfoBuilder::setLhs( const std::string& lhs ) {
         m_lhs = lhs;
+        return *this;
     }
 
-    void ResultInfoBuilder::setRhs( const std::string& rhs ) {
+    ResultInfoBuilder& ResultInfoBuilder::setRhs( const std::string& rhs ) {
         m_rhs = rhs;
+        return *this;
     }
 
-    void ResultInfoBuilder::setOp( const std::string& op ) {
+    ResultInfoBuilder& ResultInfoBuilder::setOp( const std::string& op ) {
         m_op = op;
+        return *this;
+    }
+
+    ResultInfoBuilder& ResultInfoBuilder::setMacroName( const std::string& macroName ) {
+        m_macroName = macroName;
+        return *this;
     }
 
     ResultInfoBuilder& ResultInfoBuilder::captureBoolExpression( bool result ) {
@@ -6139,6 +6138,7 @@ int main (int argc, char * const argv[]) {
 #define CATCH_SUCCEED( msg ) INTERNAL_CATCH_MSG( msg, Catch::ResultWas::Ok, false, "CATCH_SUCCEED" )
 #define CATCH_SCOPED_INFO( msg ) INTERNAL_CATCH_SCOPED_INFO( msg )
 #define CATCH_CAPTURE( msg ) INTERNAL_CATCH_MSG( #msg " := " << msg, Catch::ResultWas::Info, false, "CATCH_CAPTURE" )
+#define CATCH_SCOPED_CAPTURE( msg ) INTERNAL_CATCH_SCOPED_INFO( #msg " := " << msg )
 
 #define CATCH_SECTION( name, description ) INTERNAL_CATCH_SECTION( name, description )
 
@@ -6183,6 +6183,7 @@ int main (int argc, char * const argv[]) {
 #define SUCCEED( msg ) INTERNAL_CATCH_MSG( msg, Catch::ResultWas::Ok, false, "SUCCEED" )
 #define SCOPED_INFO( msg ) INTERNAL_CATCH_SCOPED_INFO( msg )
 #define CAPTURE( msg ) INTERNAL_CATCH_MSG( #msg " := " << msg, Catch::ResultWas::Info, false, "CAPTURE" )
+#define SCOPED_CAPTURE( msg ) INTERNAL_CATCH_SCOPED_INFO( #msg " := " << msg )
 
 #define SECTION( name, description ) INTERNAL_CATCH_SECTION( name, description )