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 use of compiler specific techniques for denoting non-returning functions

- use if( Catch::isTrue( true) ) to guard throws instead
Commit
bf37e6879a37d74bde7eedb688506ee642229ff1
Author
Phil Nash ·
Parents
2a9d8d9e368a

Files · Download .tar.gz

Changes

 include/catch.hpp                        |  4 ---
 include/internal/catch_capture.hpp       |  4 ---
 include/internal/catch_commandline.hpp   |  4 +--
 include/internal/catch_common.h          | 15 +++++----
 include/internal/catch_test_registry.hpp | 12 --------
 projects/SelfTest/ExceptionTests.cpp     | 52 ++++++++++++++++----------------
 6 files changed, 35 insertions(+), 56 deletions(-)

diff --git a/include/catch.hpp b/include/catch.hpp
index 6e57a9da..a9fbfdba 100644
--- a/include/catch.hpp
+++ b/include/catch.hpp
@@ -80,12 +80,10 @@
 
 #ifdef CATCH_CONFIG_VARIADIC_MACROS
     #define CATCH_TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ )
-    #define CATCH_TEST_CASE_NORETURN( ... ) INTERNAL_CATCH_TESTCASE_NORETURN( __VA_ARGS__ )
     #define CATCH_METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ )
     #define CATCH_SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ )
 #else
     #define CATCH_TEST_CASE( name, description ) INTERNAL_CATCH_TESTCASE( name, description )
-    #define CATCH_TEST_CASE_NORETURN( name, description ) INTERNAL_CATCH_TESTCASE_NORETURN( name, description )
     #define CATCH_METHOD_AS_TEST_CASE( method, name, description ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, name, description )
     #define CATCH_SECTION( name, description ) INTERNAL_CATCH_SECTION( name, description )
 #endif
@@ -141,12 +139,10 @@
 
 #ifdef CATCH_CONFIG_VARIADIC_MACROS
     #define TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ )
-    #define TEST_CASE_NORETURN( ... ) INTERNAL_CATCH_TESTCASE_NORETURN( __VA_ARGS__ )
     #define METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ )
     #define SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ )
 #else
     #define TEST_CASE( name, description ) INTERNAL_CATCH_TESTCASE( name, description )
-    #define TEST_CASE_NORETURN( name, description ) INTERNAL_CATCH_TESTCASE_NORETURN( name, description )
     #define METHOD_AS_TEST_CASE( method, name, description ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, name, description )
     #define SECTION( name, description ) INTERNAL_CATCH_SECTION( name, description )
 #endif
diff --git a/include/internal/catch_capture.hpp b/include/internal/catch_capture.hpp
index a8aa98b1..cf143244 100644
--- a/include/internal/catch_capture.hpp
+++ b/include/internal/catch_capture.hpp
@@ -57,10 +57,6 @@ namespace Catch {
     
 struct TestFailureException{};
 
-
-// This is just here to avoid compiler warnings with macro constants and boolean literals
-inline bool isTrue( bool value ){ return value; }
-
 } // end namespace Catch
 
 ///////////////////////////////////////////////////////////////////////////////
diff --git a/include/internal/catch_commandline.hpp b/include/internal/catch_commandline.hpp
index 7657da6b..6c050f55 100644
--- a/include/internal/catch_commandline.hpp
+++ b/include/internal/catch_commandline.hpp
@@ -44,7 +44,6 @@ namespace Catch {
         std::string operator[]( std::size_t i ) const { return m_args[i]; }
         std::size_t argsCount() const { return m_args.size(); }
 
-        CATCH_ATTRIBUTE_NORETURN
         void raiseError( std::string const& message ) const {
             std::ostringstream oss;
             if( m_name.empty() )
@@ -56,7 +55,8 @@ namespace Catch {
                 oss << " Arguments were:";
             for( std::size_t i = 0; i < m_args.size(); ++i )
                 oss << " " << m_args[i];
-            throw std::domain_error( oss.str() );
+            if( isTrue( true ) )
+                throw std::domain_error( oss.str() );
         }
         
     private:
diff --git a/include/internal/catch_common.h b/include/internal/catch_common.h
index 954f6170..7e74965a 100644
--- a/include/internal/catch_common.h
+++ b/include/internal/catch_common.h
@@ -15,16 +15,12 @@
 #define INTERNAL_CATCH_STRINGIFY2( expr ) #expr
 #define INTERNAL_CATCH_STRINGIFY( expr ) INTERNAL_CATCH_STRINGIFY2( expr )
 
-#ifdef __GNUC__
-#define CATCH_ATTRIBUTE_NORETURN __attribute__ ((noreturn))
-#else
-#define CATCH_ATTRIBUTE_NORETURN
-#endif
-
 #include <sstream>
 #include <stdexcept>
 #include <algorithm>
 
+#include "catch_compiler_capabilities.h"
+
 namespace Catch {
 
     class NonCopyable {
@@ -134,11 +130,14 @@ namespace Catch {
         return os;
     }
     
-    CATCH_ATTRIBUTE_NORETURN
+    // This is just here to avoid compiler warnings with macro constants and boolean literals
+    inline bool isTrue( bool value ){ return value; }
+    
     inline void throwLogicError( std::string const& message, SourceLineInfo const& locationInfo ) {
         std::ostringstream oss;
         oss << locationInfo << ": Internal Catch error: '" << message << "'";
-        throw std::logic_error( oss.str() );
+        if( isTrue( true ))
+            throw std::logic_error( oss.str() );
     }
 }
 
diff --git a/include/internal/catch_test_registry.hpp b/include/internal/catch_test_registry.hpp
index 65fe760f..fde21d35 100644
--- a/include/internal/catch_test_registry.hpp
+++ b/include/internal/catch_test_registry.hpp
@@ -80,12 +80,6 @@ private:
         namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &INTERNAL_CATCH_UNIQUE_NAME(  TestCaseFunction_catch_internal_ ), CATCH_INTERNAL_LINEINFO, Catch::NameAndDesc( __VA_ARGS__ ) ); }\
         static void INTERNAL_CATCH_UNIQUE_NAME(  TestCaseFunction_catch_internal_ )()
 
-    ///////////////////////////////////////////////////////////////////////////////
-    #define INTERNAL_CATCH_TESTCASE_NORETURN( ... ) \
-        static void INTERNAL_CATCH_UNIQUE_NAME( TestCaseFunction_catch_internal_ )() CATCH_ATTRIBUTE_NORETURN; \
-        namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &INTERNAL_CATCH_UNIQUE_NAME(  TestCaseFunction_catch_internal_ ), CATCH_INTERNAL_LINEINFO, Catch::NameAndDesc( __VA_ARGS__ ) ); }\
-        static void INTERNAL_CATCH_UNIQUE_NAME(  TestCaseFunction_catch_internal_ )()
-
     ///////////////////////////////////////////////////////////////////////////////
     #define INTERNAL_CATCH_METHOD_AS_TEST_CASE( QualifiedMethod, ... ) \
         namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &QualifiedMethod, "&" #QualifiedMethod, Catch::NameAndDesc( __VA_ARGS__ ), CATCH_INTERNAL_LINEINFO ); }
@@ -107,12 +101,6 @@ private:
         namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &INTERNAL_CATCH_UNIQUE_NAME(  TestCaseFunction_catch_internal_ ), CATCH_INTERNAL_LINEINFO, Catch::NameAndDesc( Name, Desc ) ); }\
         static void INTERNAL_CATCH_UNIQUE_NAME(  TestCaseFunction_catch_internal_ )()
 
-    ///////////////////////////////////////////////////////////////////////////////
-    #define INTERNAL_CATCH_TESTCASE_NORETURN( Name, Desc ) \
-        static void INTERNAL_CATCH_UNIQUE_NAME( TestCaseFunction_catch_internal_ )() CATCH_ATTRIBUTE_NORETURN; \
-        namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &INTERNAL_CATCH_UNIQUE_NAME(  TestCaseFunction_catch_internal_ ), CATCH_INTERNAL_LINEINFO, Catch::NameAndDesc( Name, Desc ) ); }\
-        static void INTERNAL_CATCH_UNIQUE_NAME(  TestCaseFunction_catch_internal_ )()
-
     ///////////////////////////////////////////////////////////////////////////////
     #define INTERNAL_CATCH_METHOD_AS_TEST_CASE( QualifiedMethod, Name, Desc ) \
         namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &QualifiedMethod, "&" #QualifiedMethod, Catch::NameAndDesc( Name, Desc ), CATCH_INTERNAL_LINEINFO ); }
diff --git a/projects/SelfTest/ExceptionTests.cpp b/projects/SelfTest/ExceptionTests.cpp
index bf951222..123e8cef 100644
--- a/projects/SelfTest/ExceptionTests.cpp
+++ b/projects/SelfTest/ExceptionTests.cpp
@@ -15,13 +15,11 @@
 
 namespace
 {
-    CATCH_ATTRIBUTE_NORETURN
-    int thisThrows();
-    
-    int thisThrows()
+    inline int thisThrows()
     {
-        throw std::domain_error( "expected exception" );
-        /*NOTREACHED*/    
+		if( Catch::isTrue( true ) )
+		    throw std::domain_error( "expected exception" );
+		return 1;
     }
 
     int thisDoesntThrow()
@@ -37,7 +35,6 @@ TEST_CASE( "./succeeding/exceptions/explicit", "When checked exceptions are thro
     REQUIRE_THROWS( thisThrows() );
 }
 
-CATCH_ATTRIBUTE_NORETURN
 TEST_CASE( "./failing/exceptions/explicit", "When checked exceptions are thrown they can be expected or unexpected" )
 {
     CHECK_THROWS_AS( thisThrows(), std::string );
@@ -45,31 +42,30 @@ TEST_CASE( "./failing/exceptions/explicit", "When checked exceptions are thrown
     CHECK_NOTHROW( thisThrows() );
 }
 
-TEST_CASE_NORETURN( "./failing/exceptions/implicit", "When unchecked exceptions are thrown they are always failures" )
+TEST_CASE( "./failing/exceptions/implicit", "When unchecked exceptions are thrown they are always failures" )
 {
-    throw std::domain_error( "unexpected exception" );
-    /*NOTREACHED*/    
+	if( Catch::isTrue( true ) )
+	    throw std::domain_error( "unexpected exception" );
 }
 
-TEST_CASE_NORETURN( "./failing/exceptions/implicit/2", "An unchecked exception reports the line of the last assertion" )
+TEST_CASE( "./failing/exceptions/implicit/2", "An unchecked exception reports the line of the last assertion" )
 {
     CHECK( 1 == 1 );
-    throw std::domain_error( "unexpected exception" );
-    /*NOTREACHED*/
+	if( Catch::isTrue( true ) )
+	    throw std::domain_error( "unexpected exception" );
 }
 TEST_CASE( "./failing/exceptions/implicit/3", "When unchecked exceptions are thrown they are always failures" )
 {
     SECTION( "section name", "" )
     {
-        throw std::domain_error( "unexpected exception" );
-        /*NOTREACHED*/
+		if( Catch::isTrue( true ) )
+			throw std::domain_error( "unexpected exception" );
     }
 }
 
-TEST_CASE_NORETURN( "./failing/exceptions/implicit/4", "When unchecked exceptions are thrown they are always failures" )
+TEST_CASE( "./failing/exceptions/implicit/4", "When unchecked exceptions are thrown they are always failures" )
 {
     CHECK( thisThrows() == 0 );
-    /*NOTREACHED*/    
 }
 
 TEST_CASE( "./succeeding/exceptions/implicit", "When unchecked exceptions are thrown, but caught, they do not affect the test" )
@@ -109,28 +105,32 @@ CATCH_TRANSLATE_EXCEPTION( double& ex )
     return Catch::toString( ex );
 }
 
-TEST_CASE_NORETURN( "./failing/exceptions/custom", "Unexpected custom exceptions can be translated" )
+TEST_CASE( "./failing/exceptions/custom", "Unexpected custom exceptions can be translated" )
 {
-    throw CustomException( "custom exception" );
+	if( Catch::isTrue( true ) )
+	    throw CustomException( "custom exception" );
+}
+
+inline void throwCustom() {
+	if( Catch::isTrue( true ) )
+		throw CustomException( "custom exception - not std" );
 }
-#ifdef _MSC_VER
-#pragma warning(disable:4702) // unreachable code
-#endif
 
 TEST_CASE( "./failing/exceptions/custom/nothrow", "Custom exceptions can be translated when testing for nothrow" )
 {
-    REQUIRE_NOTHROW( throw CustomException( "unexpected custom exception" ) );
+    REQUIRE_NOTHROW( throwCustom() );
 }
 
 TEST_CASE( "./failing/exceptions/custom/throw", "Custom exceptions can be translated when testing for throwing as something else" )
 {
-    REQUIRE_THROWS_AS( throw CustomException( "custom exception - not std" ), std::exception );
+    REQUIRE_THROWS_AS( throwCustom(), std::exception );
 }
 
 
-TEST_CASE_NORETURN( "./failing/exceptions/custom/double", "Unexpected custom exceptions can be translated"  )
+TEST_CASE( "./failing/exceptions/custom/double", "Unexpected custom exceptions can be translated"  )
 {
-    throw double( 3.14 );
+	if( Catch::isTrue( true ) )
+	    throw double( 3.14 );
 }
 
 inline int thisFunctionNotImplemented( int ) {