Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:54:06

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 #define INTERNAL_CATCH_REACT( handler ) handler.complete();
0042 
0043 ///////////////////////////////////////////////////////////////////////////////
0044 #define INTERNAL_CATCH_TEST( macroName, resultDisposition, ... ) \
0045     do { /* NOLINT(bugprone-infinite-loop) */ \
0046         /* The expression should not be evaluated, but warnings should hopefully be checked */ \
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__) ) ) // the expression here is never evaluated at runtime but it forces the compiler to give it a look
0057     // The double negation silences MSVC's C4800 warning, the static_cast forces short-circuit evaluation if the type has overloaded &&.
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 // Although this is matcher-based, it can be used with just a string
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 // CATCH_CONFIG_DISABLE
0156 
0157 #endif // CATCH_TEST_MACRO_IMPL_HPP_INCLUDED