Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-11-01 08:37:22

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_MATCHERS_IMPL_HPP_INCLUDED
0009 #define CATCH_MATCHERS_IMPL_HPP_INCLUDED
0010 
0011 #include <catch2/internal/catch_assertion_handler.hpp>
0012 #include <catch2/internal/catch_source_line_info.hpp>
0013 #include <catch2/internal/catch_decomposer.hpp>
0014 #include <catch2/internal/catch_preprocessor_internal_stringify.hpp>
0015 #include <catch2/internal/catch_move_and_forward.hpp>
0016 
0017 #include <string>
0018 
0019 namespace Catch {
0020 
0021 #ifdef __clang__
0022 #    pragma clang diagnostic push
0023 #    pragma clang diagnostic ignored "-Wsign-compare"
0024 #    pragma clang diagnostic ignored "-Wnon-virtual-dtor"
0025 #elif defined __GNUC__
0026 #    pragma GCC diagnostic push
0027 #    pragma GCC diagnostic ignored "-Wsign-compare"
0028 #    pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
0029 #endif
0030 
0031     template<typename ArgT, typename MatcherT>
0032     class MatchExpr : public ITransientExpression {
0033         ArgT && m_arg;
0034         MatcherT const& m_matcher;
0035     public:
0036         constexpr MatchExpr( ArgT && arg, MatcherT const& matcher )
0037         :   ITransientExpression{ true, matcher.match( arg ) }, // not forwarding arg here on purpose
0038             m_arg( CATCH_FORWARD(arg) ),
0039             m_matcher( matcher )
0040         {}
0041 
0042         void streamReconstructedExpression( std::ostream& os ) const override {
0043             os << Catch::Detail::stringify( m_arg )
0044                << ' '
0045                << m_matcher.toString();
0046         }
0047     };
0048 
0049 #ifdef __clang__
0050 #    pragma clang diagnostic pop
0051 #elif defined __GNUC__
0052 #    pragma GCC diagnostic pop
0053 #endif
0054 
0055 
0056     namespace Matchers {
0057         template <typename ArgT>
0058         class MatcherBase;
0059     }
0060 
0061     using StringMatcher = Matchers::MatcherBase<std::string>;
0062 
0063     void handleExceptionMatchExpr( AssertionHandler& handler, StringMatcher const& matcher );
0064 
0065     template<typename ArgT, typename MatcherT>
0066     constexpr MatchExpr<ArgT, MatcherT>
0067     makeMatchExpr( ArgT&& arg, MatcherT const& matcher ) {
0068         return MatchExpr<ArgT, MatcherT>( CATCH_FORWARD(arg), matcher );
0069     }
0070 
0071 } // namespace Catch
0072 
0073 
0074 ///////////////////////////////////////////////////////////////////////////////
0075 #define INTERNAL_CHECK_THAT( macroName, matcher, resultDisposition, arg ) \
0076     do { \
0077         Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(arg) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \
0078         INTERNAL_CATCH_TRY { \
0079             catchAssertionHandler.handleExpr( Catch::makeMatchExpr( arg, matcher ) ); \
0080         } INTERNAL_CATCH_CATCH( catchAssertionHandler ) \
0081         catchAssertionHandler.complete(); \
0082     } while( false )
0083 
0084 
0085 ///////////////////////////////////////////////////////////////////////////////
0086 #define INTERNAL_CATCH_THROWS_MATCHES( macroName, exceptionType, resultDisposition, matcher, ... ) \
0087     do { \
0088         Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__) ", " CATCH_INTERNAL_STRINGIFY(exceptionType) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \
0089         if( catchAssertionHandler.allowThrows() ) \
0090             try { \
0091                 CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
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( exceptionType const& ex ) { \
0098                 catchAssertionHandler.handleExpr( Catch::makeMatchExpr( ex, matcher ) ); \
0099             } \
0100             catch( ... ) { \
0101                 catchAssertionHandler.handleUnexpectedInflightException(); \
0102             } \
0103         else \
0104             catchAssertionHandler.handleThrowingCallSkipped(); \
0105         catchAssertionHandler.complete(); \
0106     } while( false )
0107 
0108 
0109 #endif // CATCH_MATCHERS_IMPL_HPP_INCLUDED