mirror of
https://github.com/catchorg/Catch2.git
synced 2024-12-27 13:13:30 +01:00
Renamed ResultBuilder -> ExpressionBuilder
This commit is contained in:
parent
7a0cadc342
commit
6acb36a996
@ -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;
|
||||
|
@ -51,7 +51,7 @@
|
||||
4A6D0C43149B3E1500DB3EAA /* catch_with_main.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_with_main.hpp; path = ../../../../include/catch_with_main.hpp; sourceTree = "<group>"; };
|
||||
4A6D0C44149B3E1500DB3EAA /* catch.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch.hpp; path = ../../../../include/catch.hpp; sourceTree = "<group>"; };
|
||||
4A6D0C46149B3E3D00DB3EAA /* catch_approx.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = catch_approx.hpp; sourceTree = "<group>"; };
|
||||
4A6D0C47149B3E3D00DB3EAA /* catch_capture.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = catch_capture.hpp; sourceTree = "<group>"; };
|
||||
4A6D0C47149B3E3D00DB3EAA /* catch_capture.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; lineEnding = 0; path = catch_capture.hpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
|
||||
4A6D0C48149B3E3D00DB3EAA /* catch_commandline.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = catch_commandline.hpp; sourceTree = "<group>"; };
|
||||
4A6D0C49149B3E3D00DB3EAA /* catch_common.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = catch_common.h; sourceTree = "<group>"; };
|
||||
4A6D0C4A149B3E3D00DB3EAA /* catch_config.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = catch_config.hpp; sourceTree = "<group>"; };
|
||||
|
Loading…
Reference in New Issue
Block a user