File indexing completed on 2025-09-18 09:08:52
0001
0002
0003
0004
0005
0006
0007
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
0019
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
0030
0031 #define INTERNAL_CATCH_TRY
0032 #define INTERNAL_CATCH_CATCH( capturer )
0033
0034 #else
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 { \
0044 \
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__ ); \
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__) ) )
0055
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
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
0154
0155 #endif