File indexing completed on 2025-01-18 09:54:06
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 #define INTERNAL_CATCH_REACT( handler ) handler.complete();
0042
0043
0044 #define INTERNAL_CATCH_TEST( macroName, resultDisposition, ... ) \
0045 do { \
0046 \
0047 CATCH_INTERNAL_IGNORE_BUT_WARN(__VA_ARGS__); \
0048 Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition ); \
0049 INTERNAL_CATCH_TRY { \
0050 CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
0051 CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \
0052 catchAssertionHandler.handleExpr( Catch::Decomposer() <= __VA_ARGS__ ); \
0053 CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
0054 } INTERNAL_CATCH_CATCH( catchAssertionHandler ) \
0055 INTERNAL_CATCH_REACT( catchAssertionHandler ) \
0056 } while( (void)0, (false) && static_cast<const bool&>( !!(__VA_ARGS__) ) )
0057
0058
0059
0060 #define INTERNAL_CATCH_IF( macroName, resultDisposition, ... ) \
0061 INTERNAL_CATCH_TEST( macroName, resultDisposition, __VA_ARGS__ ); \
0062 if( Catch::getResultCapture().lastAssertionPassed() )
0063
0064
0065 #define INTERNAL_CATCH_ELSE( macroName, resultDisposition, ... ) \
0066 INTERNAL_CATCH_TEST( macroName, resultDisposition, __VA_ARGS__ ); \
0067 if( !Catch::getResultCapture().lastAssertionPassed() )
0068
0069
0070 #define INTERNAL_CATCH_NO_THROW( macroName, resultDisposition, ... ) \
0071 do { \
0072 Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition ); \
0073 try { \
0074 CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
0075 CATCH_INTERNAL_SUPPRESS_USELESS_CAST_WARNINGS \
0076 static_cast<void>(__VA_ARGS__); \
0077 CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
0078 catchAssertionHandler.handleExceptionNotThrownAsExpected(); \
0079 } \
0080 catch( ... ) { \
0081 catchAssertionHandler.handleUnexpectedInflightException(); \
0082 } \
0083 INTERNAL_CATCH_REACT( catchAssertionHandler ) \
0084 } while( false )
0085
0086
0087 #define INTERNAL_CATCH_THROWS( macroName, resultDisposition, ... ) \
0088 do { \
0089 Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition); \
0090 if( catchAssertionHandler.allowThrows() ) \
0091 try { \
0092 CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
0093 CATCH_INTERNAL_SUPPRESS_UNUSED_RESULT \
0094 CATCH_INTERNAL_SUPPRESS_USELESS_CAST_WARNINGS \
0095 static_cast<void>(__VA_ARGS__); \
0096 CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
0097 catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \
0098 } \
0099 catch( ... ) { \
0100 catchAssertionHandler.handleExceptionThrownAsExpected(); \
0101 } \
0102 else \
0103 catchAssertionHandler.handleThrowingCallSkipped(); \
0104 INTERNAL_CATCH_REACT( catchAssertionHandler ) \
0105 } while( false )
0106
0107
0108 #define INTERNAL_CATCH_THROWS_AS( macroName, exceptionType, resultDisposition, expr ) \
0109 do { \
0110 Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(expr) ", " CATCH_INTERNAL_STRINGIFY(exceptionType), resultDisposition ); \
0111 if( catchAssertionHandler.allowThrows() ) \
0112 try { \
0113 CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
0114 CATCH_INTERNAL_SUPPRESS_UNUSED_RESULT \
0115 CATCH_INTERNAL_SUPPRESS_USELESS_CAST_WARNINGS \
0116 static_cast<void>(expr); \
0117 CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
0118 catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \
0119 } \
0120 catch( exceptionType const& ) { \
0121 catchAssertionHandler.handleExceptionThrownAsExpected(); \
0122 } \
0123 catch( ... ) { \
0124 catchAssertionHandler.handleUnexpectedInflightException(); \
0125 } \
0126 else \
0127 catchAssertionHandler.handleThrowingCallSkipped(); \
0128 INTERNAL_CATCH_REACT( catchAssertionHandler ) \
0129 } while( false )
0130
0131
0132
0133
0134
0135 #define INTERNAL_CATCH_THROWS_STR_MATCHES( macroName, resultDisposition, matcher, ... ) \
0136 do { \
0137 Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \
0138 if( catchAssertionHandler.allowThrows() ) \
0139 try { \
0140 CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
0141 CATCH_INTERNAL_SUPPRESS_UNUSED_RESULT \
0142 CATCH_INTERNAL_SUPPRESS_USELESS_CAST_WARNINGS \
0143 static_cast<void>(__VA_ARGS__); \
0144 CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
0145 catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \
0146 } \
0147 catch( ... ) { \
0148 Catch::handleExceptionMatchExpr( catchAssertionHandler, matcher ); \
0149 } \
0150 else \
0151 catchAssertionHandler.handleThrowingCallSkipped(); \
0152 INTERNAL_CATCH_REACT( catchAssertionHandler ) \
0153 } while( false )
0154
0155 #endif
0156
0157 #endif