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

Fix for #134

The INTERNAL_CATCH_MSG macro, which is used by INFO, WARN and FAIL places its lines in a do…while block so it can be used after an if statement with no block
Commit
ec5956f47114ff8b597be85fd7654d29da93aea0
Author
Phil Nash ·
Parents
88b70828f24b

Files · Download .tar.gz

Changes

 include/internal/catch_capture.hpp | 6 ++++--
 projects/SelfTest/MessageTests.cpp | 3 ++-
 single_include/catch.hpp           | 8 +++++---
 3 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/include/internal/catch_capture.hpp b/include/internal/catch_capture.hpp
index 602be000..cc05a845 100644
--- a/include/internal/catch_capture.hpp
+++ b/include/internal/catch_capture.hpp
@@ -167,8 +167,10 @@ inline bool isTrue( bool value ){ return value; }
 
 ///////////////////////////////////////////////////////////////////////////////
 #define INTERNAL_CATCH_MSG( reason, resultType, stopOnFailure, macroName ) \
-    INTERNAL_CATCH_ACCEPT_INFO( "", macroName, false ); \
-    INTERNAL_CATCH_ACCEPT_EXPR( Catch::ExpressionResultBuilder( resultType ) << reason, stopOnFailure, true );
+    do { \
+        INTERNAL_CATCH_ACCEPT_INFO( "", macroName, false ); \
+        INTERNAL_CATCH_ACCEPT_EXPR( Catch::ExpressionResultBuilder( resultType ) << reason, stopOnFailure, true ) \
+    } while( Catch::isTrue( false ) )
 
 ///////////////////////////////////////////////////////////////////////////////
 #define INTERNAL_CATCH_SCOPED_INFO( log, macroName ) \
diff --git a/projects/SelfTest/MessageTests.cpp b/projects/SelfTest/MessageTests.cpp
index 776d7169..fe65f753 100644
--- a/projects/SelfTest/MessageTests.cpp
+++ b/projects/SelfTest/MessageTests.cpp
@@ -43,7 +43,8 @@ TEST_CASE( "./mixed/message/info/2", "INFO gets logged on failure" )
 
 TEST_CASE( "./failing/message/fail", "FAIL aborts the test" )
 {
-    FAIL( "This is a " << "failure" );    // This should output the message and abort
+    if( true )
+        FAIL( "This is a " << "failure" );    // This should output the message and abort
 }
 
 TEST_CASE( "./failing/message/sections", "Output from all sections is reported" )
diff --git a/single_include/catch.hpp b/single_include/catch.hpp
index 7abf63db..e92dc0cb 100644
--- a/single_include/catch.hpp
+++ b/single_include/catch.hpp
@@ -1,5 +1,5 @@
 /*
- *  Generated: 2012-11-04 21:39:24.756874
+ *  Generated: 2012-11-06 07:51:06.701955
  *  ----------------------------------------------------------
  *  This file has been merged from multiple headers. Please don't edit it directly
  *  Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved.
@@ -2162,8 +2162,10 @@ inline bool isTrue( bool value ){ return value; }
 
 ///////////////////////////////////////////////////////////////////////////////
 #define INTERNAL_CATCH_MSG( reason, resultType, stopOnFailure, macroName ) \
-    INTERNAL_CATCH_ACCEPT_INFO( "", macroName, false ); \
-    INTERNAL_CATCH_ACCEPT_EXPR( Catch::ExpressionResultBuilder( resultType ) << reason, stopOnFailure, true );
+    do { \
+        INTERNAL_CATCH_ACCEPT_INFO( "", macroName, false ); \
+        INTERNAL_CATCH_ACCEPT_EXPR( Catch::ExpressionResultBuilder( resultType ) << reason, stopOnFailure, true ) \
+    } while( Catch::isTrue( false ) )
 
 ///////////////////////////////////////////////////////////////////////////////
 #define INTERNAL_CATCH_SCOPED_INFO( log, macroName ) \