Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 09:08:52

0001 
0002 //              Copyright Catch2 Authors
0003 // Distributed under the Boost Software License, Version 1.0.
0004 //   (See accompanying file LICENSE.txt or copy at
0005 //        https://www.boost.org/LICENSE_1_0.txt)
0006 
0007 // SPDX-License-Identifier: BSL-1.0
0008 #ifndef CATCH_TEST_MACRO_IMPL_HPP_INCLUDED
0009 #define CATCH_TEST_MACRO_IMPL_HPP_INCLUDED
0010 
0011 #include <catch2/catch_user_config.hpp>
0012 #include <catch2/internal/catch_assertion_handler.hpp>
0013 #include <catch2/internal/catch_preprocessor_internal_stringify.hpp>
0014 #include <catch2/interfaces/catch_interfaces_capture.hpp>
0015 #include <catch2/internal/catch_stringref.hpp>
0016 #include <catch2/internal/catch_source_line_info.hpp>
0017 
0018 // We need this suppression to leak, because it took until GCC 10
0019 // for the front end to handle local suppression via _Pragma properly
0020 #if defined(__GNUC__) && !defined(__clang__) && !defined(__ICC) && __GNUC__ <= 9
0021   #pragma GCC diagnostic ignored "-Wparentheses"
0022 #endif
0023 
0024 #if !defined(CATCH_CONFIG_DISABLE)
0025 
0026 #if defined(CATCH_CONFIG_FAST_COMPILE) || defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
0027 
0028 ///////////////////////////////////////////////////////////////////////////////
0029 // Another way to speed-up compilation is to omit local try-catch for REQUIRE*
0030 // macros.
0031 #define INTERNAL_CATCH_TRY
0032 #define INTERNAL_CATCH_CATCH( capturer )
0033 
0034 #else // CATCH_CONFIG_FAST_COMPILE
0035 
0036 #define INTERNAL_CATCH_TRY try
0037 #define INTERNAL_CATCH_CATCH( handler ) catch(...) { (handler).handleUnexpectedInflightException(); }
0038 
0039 #endif
0040 
0041 ///////////////////////////////////////////////////////////////////////////////
0042 #define INTERNAL_CATCH_TEST( macroName, resultDisposition, ... ) \
0043     do { /* NOLINT(bugprone-infinite-loop) */ \
0044         /* The expression should not be evaluated, but warnings should hopefully be checked */ \
0045         CATCH_INTERNAL_IGNORE_BUT_WARN(__VA_ARGS__); \
0046         Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition ); \
0047         INTERNAL_CATCH_TRY { \
0048             CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
0049             CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \
0050             catchAssertionHandler.handleExpr( Catch::Decomposer() <= __VA_ARGS__ ); /* NOLINT(bugprone-chained-comparison) */ \
0051             CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
0052         } INTERNAL_CATCH_CATCH( catchAssertionHandler ) \
0053         catchAssertionHandler.complete(); \
0054     } while( (void)0, (false) && static_cast<const bool&>( !!(__VA_ARGS__) ) ) // the expression here is never evaluated at runtime but it forces the compiler to give it a look
0055     // The double negation silences MSVC's C4800 warning, the static_cast forces short-circuit evaluation if the type has overloaded &&.
0056 
0057 ///////////////////////////////////////////////////////////////////////////////
0058 #define INTERNAL_CATCH_IF( macroName, resultDisposition, ... ) \
0059     INTERNAL_CATCH_TEST( macroName, resultDisposition, __VA_ARGS__ ); \
0060     if( Catch::getResultCapture().lastAssertionPassed() )
0061 
0062 ///////////////////////////////////////////////////////////////////////////////
0063 #define INTERNAL_CATCH_ELSE( macroName, resultDisposition, ... ) \
0064     INTERNAL_CATCH_TEST( macroName, resultDisposition, __VA_ARGS__ ); \
0065     if( !Catch::getResultCapture().lastAssertionPassed() )
0066 
0067 ///////////////////////////////////////////////////////////////////////////////
0068 #define INTERNAL_CATCH_NO_THROW( macroName, resultDisposition, ... ) \
0069     do { \
0070         Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition ); \
0071         try { \
0072             CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
0073             CATCH_INTERNAL_SUPPRESS_USELESS_CAST_WARNINGS \
0074             static_cast<void>(__VA_ARGS__); \
0075             CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
0076             catchAssertionHandler.handleExceptionNotThrownAsExpected(); \
0077         } \
0078         catch( ... ) { \
0079             catchAssertionHandler.handleUnexpectedInflightException(); \
0080         } \
0081         catchAssertionHandler.complete(); \
0082     } while( false )
0083 
0084 ///////////////////////////////////////////////////////////////////////////////
0085 #define INTERNAL_CATCH_THROWS( macroName, resultDisposition, ... ) \
0086     do { \
0087         Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition); \
0088         if( catchAssertionHandler.allowThrows() ) \
0089             try { \
0090                 CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
0091                 CATCH_INTERNAL_SUPPRESS_UNUSED_RESULT \
0092                 CATCH_INTERNAL_SUPPRESS_USELESS_CAST_WARNINGS \
0093                 static_cast<void>(__VA_ARGS__); \
0094                 CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
0095                 catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \
0096             } \
0097             catch( ... ) { \
0098                 catchAssertionHandler.handleExceptionThrownAsExpected(); \
0099             } \
0100         else \
0101             catchAssertionHandler.handleThrowingCallSkipped(); \
0102         catchAssertionHandler.complete(); \
0103     } while( false )
0104 
0105 ///////////////////////////////////////////////////////////////////////////////
0106 #define INTERNAL_CATCH_THROWS_AS( macroName, exceptionType, resultDisposition, expr ) \
0107     do { \
0108         Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(expr) ", " CATCH_INTERNAL_STRINGIFY(exceptionType), resultDisposition ); \
0109         if( catchAssertionHandler.allowThrows() ) \
0110             try { \
0111                 CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
0112                 CATCH_INTERNAL_SUPPRESS_UNUSED_RESULT \
0113                 CATCH_INTERNAL_SUPPRESS_USELESS_CAST_WARNINGS \
0114                 static_cast<void>(expr); \
0115                 CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
0116                 catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \
0117             } \
0118             catch( exceptionType const& ) { \
0119                 catchAssertionHandler.handleExceptionThrownAsExpected(); \
0120             } \
0121             catch( ... ) { \
0122                 catchAssertionHandler.handleUnexpectedInflightException(); \
0123             } \
0124         else \
0125             catchAssertionHandler.handleThrowingCallSkipped(); \
0126         catchAssertionHandler.complete(); \
0127     } while( false )
0128 
0129 
0130 
0131 ///////////////////////////////////////////////////////////////////////////////
0132 // Although this is matcher-based, it can be used with just a string
0133 #define INTERNAL_CATCH_THROWS_STR_MATCHES( macroName, resultDisposition, matcher, ... ) \
0134     do { \
0135         Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \
0136         if( catchAssertionHandler.allowThrows() ) \
0137             try { \
0138                 CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
0139                 CATCH_INTERNAL_SUPPRESS_UNUSED_RESULT \
0140                 CATCH_INTERNAL_SUPPRESS_USELESS_CAST_WARNINGS \
0141                 static_cast<void>(__VA_ARGS__); \
0142                 CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
0143                 catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \
0144             } \
0145             catch( ... ) { \
0146                 Catch::handleExceptionMatchExpr( catchAssertionHandler, matcher ); \
0147             } \
0148         else \
0149             catchAssertionHandler.handleThrowingCallSkipped(); \
0150         catchAssertionHandler.complete(); \
0151     } while( false )
0152 
0153 #endif // CATCH_CONFIG_DISABLE
0154 
0155 #endif // CATCH_TEST_MACRO_IMPL_HPP_INCLUDED