mirror of
				https://github.com/catchorg/Catch2.git
				synced 2025-10-31 20:27:11 +01:00 
			
		
		
		
	Renamed ResultBuilder -> ExpressionBuilder
This commit is contained in:
		| @@ -17,7 +17,7 @@ | ||||
|  | ||||
| namespace Catch | ||||
| { | ||||
|      | ||||
|  | ||||
| struct TestFailureException{}; | ||||
|  | ||||
| class ScopedInfo | ||||
| @@ -62,11 +62,11 @@ inline bool isTrue( bool value ){ return value; } | ||||
| /////////////////////////////////////////////////////////////////////////////// | ||||
| #define INTERNAL_CATCH_TEST( expr, isNot, stopOnFailure, macroName ) \ | ||||
|     do{ try{ \ | ||||
|         INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ResultBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr, isNot )->*expr ), stopOnFailure, expr ); \ | ||||
|         INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr, isNot )->*expr ), stopOnFailure, expr ); \ | ||||
|     }catch( Catch::TestFailureException& ){ \ | ||||
|         throw; \ | ||||
|     } catch( ... ){ \ | ||||
|         INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ResultBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr ) << Catch::Context::getExceptionTranslatorRegistry().translateActiveException() ).setResultType( Catch::ResultWas::ThrewException ), false, expr ); \ | ||||
|         INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr ) << Catch::Context::getExceptionTranslatorRegistry().translateActiveException() ).setResultType( Catch::ResultWas::ThrewException ), false, expr ); \ | ||||
|         throw; \ | ||||
|     }}while( Catch::isTrue( false ) ) | ||||
|  | ||||
| @@ -85,11 +85,11 @@ inline bool isTrue( bool value ){ return value; } | ||||
|     try \ | ||||
|     { \ | ||||
|         expr; \ | ||||
|         INTERNAL_CATCH_ACCEPT_EXPR( Catch::ResultBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr ).setResultType( Catch::ResultWas::Ok ), stopOnFailure, false ); \ | ||||
|         INTERNAL_CATCH_ACCEPT_EXPR( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr ).setResultType( Catch::ResultWas::Ok ), stopOnFailure, false ); \ | ||||
|     } \ | ||||
|     catch( ... ) \ | ||||
|     { \ | ||||
|         INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ResultBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr ) << Catch::Context::getExceptionTranslatorRegistry().translateActiveException() ).setResultType( Catch::ResultWas::ThrewException ), stopOnFailure, false ); \ | ||||
|         INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr ) << Catch::Context::getExceptionTranslatorRegistry().translateActiveException() ).setResultType( Catch::ResultWas::ThrewException ), stopOnFailure, false ); \ | ||||
|     } | ||||
|  | ||||
| /////////////////////////////////////////////////////////////////////////////// | ||||
| @@ -97,7 +97,7 @@ inline bool isTrue( bool value ){ return value; } | ||||
|     try \ | ||||
|     { \ | ||||
|         expr; \ | ||||
|         INTERNAL_CATCH_ACCEPT_EXPR( Catch::ResultBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr ).setResultType( Catch::ResultWas::DidntThrowException ), stopOnFailure, false ); \ | ||||
|         INTERNAL_CATCH_ACCEPT_EXPR( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr ).setResultType( Catch::ResultWas::DidntThrowException ), stopOnFailure, false ); \ | ||||
|     } \ | ||||
|     catch( Catch::TestFailureException& ) \ | ||||
|     { \ | ||||
| @@ -105,7 +105,7 @@ inline bool isTrue( bool value ){ return value; } | ||||
|     } \ | ||||
|     catch( exceptionType ) \ | ||||
|     { \ | ||||
|         INTERNAL_CATCH_ACCEPT_EXPR( Catch::ResultBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr ).setResultType( Catch::ResultWas::Ok ), stopOnFailure, false ); \ | ||||
|         INTERNAL_CATCH_ACCEPT_EXPR( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr ).setResultType( Catch::ResultWas::Ok ), stopOnFailure, false ); \ | ||||
|     } | ||||
|  | ||||
| /////////////////////////////////////////////////////////////////////////////// | ||||
| @@ -113,12 +113,12 @@ inline bool isTrue( bool value ){ return value; } | ||||
|     INTERNAL_CATCH_THROWS( expr, exceptionType, stopOnFailure, macroName ) \ | ||||
|     catch( ... ) \ | ||||
|     { \ | ||||
|         INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ResultBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr ) << Catch::Context::getExceptionTranslatorRegistry().translateActiveException() ).setResultType( Catch::ResultWas::ThrewException ), stopOnFailure, false ); \ | ||||
|         INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr ) << Catch::Context::getExceptionTranslatorRegistry().translateActiveException() ).setResultType( Catch::ResultWas::ThrewException ), stopOnFailure, false ); \ | ||||
|     } | ||||
|  | ||||
| /////////////////////////////////////////////////////////////////////////////// | ||||
| #define INTERNAL_CATCH_MSG( reason, resultType, stopOnFailure, macroName ) \ | ||||
|     Catch::Context::getResultCapture().acceptExpression( ( Catch::ResultBuilder( CATCH_INTERNAL_LINEINFO, macroName ) << reason ).setResultType( resultType ) ); | ||||
|     Catch::Context::getResultCapture().acceptExpression( ( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName ) << reason ).setResultType( resultType ) ); | ||||
|  | ||||
| /////////////////////////////////////////////////////////////////////////////// | ||||
| #define INTERNAL_CATCH_SCOPED_INFO( log ) \ | ||||
| @@ -128,11 +128,11 @@ inline bool isTrue( bool value ){ return value; } | ||||
| /////////////////////////////////////////////////////////////////////////////// | ||||
| #define INTERNAL_CHECK_THAT( arg, matcher, stopOnFailure, macroName ) \ | ||||
|     do{ try{ \ | ||||
|         INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ResultBuilder( CATCH_INTERNAL_LINEINFO, macroName, #arg " " #matcher, false ).acceptMatcher( matcher, arg, #matcher ) ), stopOnFailure, false ); \ | ||||
|         INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName, #arg " " #matcher, false ).acceptMatcher( matcher, arg, #matcher ) ), stopOnFailure, false ); \ | ||||
|     }catch( Catch::TestFailureException& ){ \ | ||||
|         throw; \ | ||||
|     } catch( ... ){ \ | ||||
|         INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ResultBuilder( CATCH_INTERNAL_LINEINFO, macroName, #arg " " #matcher ) << Catch::Context::getExceptionTranslatorRegistry().translateActiveException() ).setResultType( Catch::ResultWas::ThrewException ), false, false ); \ | ||||
|         INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName, #arg " " #matcher ) << Catch::Context::getExceptionTranslatorRegistry().translateActiveException() ).setResultType( Catch::ResultWas::ThrewException ), false, false ); \ | ||||
|         throw; \ | ||||
|     }}while( Catch::isTrue( false ) ) | ||||
|  | ||||
|   | ||||
| @@ -17,102 +17,57 @@ | ||||
| #include "catch_common.h" | ||||
| #include <sstream> | ||||
|  | ||||
| namespace Catch | ||||
| { | ||||
| namespace Catch { | ||||
|      | ||||
| class ResultBuilder | ||||
| { | ||||
| class ExpressionBuilder { | ||||
| public: | ||||
|  | ||||
|     /////////////////////////////////////////////////////////////////////////// | ||||
|     ResultBuilder | ||||
|     ( | ||||
|         const SourceLineInfo& lineInfo, | ||||
|         const char* macroName, | ||||
|         const char* expr = "", | ||||
|         bool isNot = false | ||||
|     ) | ||||
|     ExpressionBuilder(  const SourceLineInfo& lineInfo, | ||||
|                         const char* macroName, | ||||
|                         const char* expr = "", | ||||
|                         bool isNot = false ) | ||||
|     : m_result( expr, isNot, lineInfo, macroName ), | ||||
|       m_messageStream() | ||||
|     {} | ||||
|      | ||||
|     /////////////////////////////////////////////////////////////////////////// | ||||
|     template<typename T> | ||||
|     Expression<const T&> operator->* | ||||
|     ( | ||||
|         const T & operand | ||||
|     ) | ||||
|     { | ||||
|         Expression<const T&> expr( m_result, operand ); | ||||
|          | ||||
|     Expression<const T&> operator->* ( const T & operand ) { | ||||
|         Expression<const T&> expr( m_result, operand );         | ||||
|         return expr; | ||||
|     } | ||||
|  | ||||
|     /////////////////////////////////////////////////////////////////////////// | ||||
|     Expression<const char*> operator->* | ||||
|     ( | ||||
|         const char* const& operand | ||||
|      ) | ||||
|     { | ||||
|         Expression<const char*> expr( m_result, operand ); | ||||
|          | ||||
|     Expression<const char*> operator->* ( const char* const& operand ) { | ||||
|         Expression<const char*> expr( m_result, operand );         | ||||
|         return expr; | ||||
|     } | ||||
|      | ||||
|     /////////////////////////////////////////////////////////////////////////// | ||||
|     template<typename T> | ||||
|     PtrExpression<T> operator->* | ||||
|     ( | ||||
|         const T* operand | ||||
|     ) | ||||
|     { | ||||
|         PtrExpression<T> expr( m_result, operand ); | ||||
|          | ||||
|     PtrExpression<T> operator->* ( const T* operand ) { | ||||
|         PtrExpression<T> expr( m_result, operand );         | ||||
|         return expr; | ||||
|     } | ||||
|      | ||||
|     /////////////////////////////////////////////////////////////////////////// | ||||
|     template<typename T> | ||||
|     PtrExpression<T> operator->* | ||||
|     ( | ||||
|         T* operand | ||||
|     ) | ||||
|     { | ||||
|         PtrExpression<T> expr( m_result, operand ); | ||||
|          | ||||
|     PtrExpression<T> operator->* ( T* operand ) { | ||||
|         PtrExpression<T> expr( m_result, operand );         | ||||
|         return expr; | ||||
|     } | ||||
|      | ||||
|     /////////////////////////////////////////////////////////////////////////// | ||||
|     Expression<bool> operator->* | ||||
|     ( | ||||
|         bool value | ||||
|     ) | ||||
|     { | ||||
|     Expression<bool> operator->* ( bool value ) { | ||||
|         Expression<bool> expr( m_result, value ); | ||||
|         return expr; | ||||
|     } | ||||
|      | ||||
|     /////////////////////////////////////////////////////////////////////////// | ||||
|     template<typename T> | ||||
|     ResultBuilder& operator << | ||||
|     ( | ||||
|         const T & value | ||||
|     ) | ||||
|     { | ||||
|     ExpressionBuilder& operator << ( const T & value ) { | ||||
|         m_messageStream << Catch::toString( value );         | ||||
|         return *this; | ||||
|     } | ||||
|      | ||||
|     /////////////////////////////////////////////////////////////////////////// | ||||
|     template<typename MatcherT, typename ArgT> | ||||
|     ResultBuilder& acceptMatcher | ||||
|     ( | ||||
|         const MatcherT& matcher, | ||||
|         const ArgT& arg, | ||||
|         const std::string& matcherCallAsString | ||||
|     ) | ||||
|     { | ||||
|     ExpressionBuilder& acceptMatcher(   const MatcherT& matcher, | ||||
|                                         const ArgT& arg, | ||||
|                                         const std::string& matcherCallAsString ) { | ||||
|         std::string matcherAsString = Catch::toString( matcher ); | ||||
|         if( matcherAsString == "{?}" ) | ||||
|             matcherAsString = matcherCallAsString; | ||||
| @@ -123,15 +78,10 @@ public: | ||||
|         return *this; | ||||
|     } | ||||
|      | ||||
|     /////////////////////////////////////////////////////////////////////////// | ||||
|     template<typename MatcherT, typename ArgT> | ||||
|     ResultBuilder& acceptMatcher | ||||
|     ( | ||||
|         const MatcherT& matcher, | ||||
|         ArgT* arg, | ||||
|         const std::string& matcherCallAsString | ||||
|     ) | ||||
|     { | ||||
|     ExpressionBuilder& acceptMatcher(   const MatcherT& matcher, | ||||
|                                         ArgT* arg, | ||||
|                                         const std::string& matcherCallAsString ) { | ||||
|         std::string matcherAsString = Catch::toString( matcher ); | ||||
|         if( matcherAsString == "{?}" ) | ||||
|             matcherAsString = matcherCallAsString; | ||||
| @@ -142,20 +92,12 @@ public: | ||||
|         return *this; | ||||
|     } | ||||
|      | ||||
|     /////////////////////////////////////////////////////////////////////////// | ||||
|     ResultBuilder& setResultType | ||||
|     ( | ||||
|         ResultWas::OfType resultType | ||||
|     ) | ||||
|     { | ||||
|     ExpressionBuilder& setResultType( ResultWas::OfType resultType ) { | ||||
|         m_result.setResultType( resultType ); | ||||
|         return *this; | ||||
|     } | ||||
|      | ||||
|     /////////////////////////////////////////////////////////////////////////// | ||||
|     operator ResultInfoBuilder& | ||||
|     () | ||||
|     { | ||||
|     operator ResultInfoBuilder&() { | ||||
|         m_result.setMessage( m_messageStream.str() ); | ||||
|         return m_result; | ||||
|     } | ||||
|   | ||||
| @@ -76,7 +76,7 @@ public: | ||||
|     ); | ||||
|      | ||||
| private: | ||||
|     friend class ResultBuilder; | ||||
|     friend class ExpressionBuilder; | ||||
|     template<typename T> friend class Expression; | ||||
|  | ||||
|     template<typename T> friend class PtrExpression; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Phil Nash
					Phil Nash