mirror of
				https://github.com/catchorg/Catch2.git
				synced 2025-10-31 20:27:11 +01:00 
			
		
		
		
	Integrated INTERNAL_CATCH_THROWS_STR_MATCHES with new AssertionHandler
This commit is contained in:
		| @@ -13,6 +13,7 @@ | ||||
| #include "catch_context.h" | ||||
| #include "catch_debugger.h" | ||||
| #include "catch_interfaces_registry_hub.h" | ||||
| #include "catch_matchers_string.h" | ||||
|  | ||||
| #include <cassert> | ||||
|  | ||||
| @@ -140,5 +141,14 @@ namespace Catch { | ||||
|         m_inExceptionGuard = false; | ||||
|     } | ||||
|  | ||||
|     using StringMatcher = Matchers::Impl::MatcherBase<std::string>; | ||||
|  | ||||
|     void handleExceptionMatchExpr( AssertionHandler& handler, StringMatcher const& matcher, StringRef matcherString  ) { | ||||
|         MatchExpr<std::string, StringMatcher const&> expr( Catch::translateActiveException(), matcher, matcherString ); | ||||
|         handler.handle( expr ); | ||||
|     } | ||||
|     void handleExceptionMatchExpr( AssertionHandler& handler, std::string const& str, StringRef matcherString  ) { | ||||
|         handleExceptionMatchExpr( handler, Matchers::Equals( str ), matcherString ); | ||||
|     } | ||||
|  | ||||
| } // namespace Catch | ||||
|   | ||||
| @@ -10,6 +10,7 @@ | ||||
|  | ||||
| #include "catch_decomposer.h" | ||||
| #include "catch_assertioninfo.h" | ||||
| #include "catch_matchers_string.h" // !TBD: for exception matchers | ||||
|  | ||||
| namespace Catch { | ||||
|  | ||||
| @@ -67,6 +68,11 @@ namespace Catch { | ||||
|         void unsetExceptionGuard(); | ||||
|     }; | ||||
|  | ||||
|     using StringMatcher = Matchers::Impl::MatcherBase<std::string>; | ||||
|  | ||||
|     void handleExceptionMatchExpr( AssertionHandler& handler, StringMatcher const& matcher, StringRef matcherString  ); | ||||
|     void handleExceptionMatchExpr( AssertionHandler& handler, std::string const& str, StringRef matcherString ); | ||||
|  | ||||
| } // namespace Catch | ||||
|  | ||||
| #endif // TWOBLUECUBES_CATCH_ASSERTIONHANDLER_H_INCLUDED | ||||
|   | ||||
| @@ -159,18 +159,18 @@ | ||||
| /////////////////////////////////////////////////////////////////////////////// | ||||
| #define INTERNAL_CATCH_THROWS_STR_MATCHES( macroName, resultDisposition, matcher, ... ) \ | ||||
|     do { \ | ||||
|         Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #__VA_ARGS__ ", " #matcher, resultDisposition); \ | ||||
|         if( __catchResult.allowThrows() ) \ | ||||
|         Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, #__VA_ARGS__ ", " #matcher, resultDisposition ); \ | ||||
|         if( catchAssertionHandler.allowThrows() ) \ | ||||
|             try { \ | ||||
|                 static_cast<void>(__VA_ARGS__); \ | ||||
|                 __catchResult.captureResult( Catch::ResultWas::DidntThrowException ); \ | ||||
|                 catchAssertionHandler.handle( Catch::ResultWas::DidntThrowException ); \ | ||||
|             } \ | ||||
|             catch( ... ) { \ | ||||
|                 __catchResult.captureExpectedException( matcher ); \ | ||||
|                 handleExceptionMatchExpr( catchAssertionHandler, matcher, #matcher ); \ | ||||
|             } \ | ||||
|         else \ | ||||
|             __catchResult.captureResult( Catch::ResultWas::Ok ); \ | ||||
|         INTERNAL_CATCH_REACT( __catchResult ) \ | ||||
|             catchAssertionHandler.handle( Catch::ResultWas::Ok ); \ | ||||
|         INTERNAL_CATCH_REACT2( catchAssertionHandler ) \ | ||||
|     } while( Catch::alwaysFalse() ) | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -12,7 +12,6 @@ | ||||
| namespace Catch { | ||||
|  | ||||
|     void formatReconstructedExpression( std::ostream &os, std::string const& lhs, std::string const& op, std::string const& rhs ) { | ||||
|  | ||||
|         if( lhs.size() + rhs.size() < 40 && | ||||
|                 lhs.find('\n') == std::string::npos && | ||||
|                 rhs.find('\n') == std::string::npos ) | ||||
| @@ -20,4 +19,4 @@ namespace Catch { | ||||
|         else | ||||
|             os << lhs << "\n" << op << "\n" << rhs; | ||||
|     } | ||||
| } | ||||
| } | ||||
|   | ||||
| @@ -10,6 +10,7 @@ | ||||
|  | ||||
| #include "catch_tostring.h" | ||||
| #include "catch_stringref.h" | ||||
| #include "catch_matchers.hpp" // !TBD: for exception matchers - move this | ||||
|  | ||||
| #include <ostream> | ||||
|  | ||||
| @@ -148,7 +149,7 @@ namespace Catch { | ||||
|     template<typename ArgT, typename MatcherT> | ||||
|     class MatchExpr : public ITransientExpression { | ||||
|         ArgT const& m_arg; | ||||
|         MatcherT const& m_matcher; | ||||
|         MatcherT m_matcher; | ||||
|         StringRef m_matcherString; | ||||
|         bool m_result; | ||||
|     public: | ||||
| @@ -171,6 +172,7 @@ namespace Catch { | ||||
|                 os << matcherAsString; | ||||
|         } | ||||
|     }; | ||||
|  | ||||
|     template<typename ArgT, typename MatcherT> | ||||
|     auto makeMatchExpr( ArgT const& arg, MatcherT const& matcher, StringRef matcherString  ) -> MatchExpr<ArgT, MatcherT> { | ||||
|         return MatchExpr<ArgT, MatcherT>( arg, matcher, matcherString ); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Phil Nash
					Phil Nash