mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-26 07:16:10 +01:00
Renamed ResultBuilder -> ExpressionBuilder
This commit is contained in:
parent
7a0cadc342
commit
6acb36a996
@ -62,11 +62,11 @@ inline bool isTrue( bool value ){ return value; }
|
|||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
#define INTERNAL_CATCH_TEST( expr, isNot, stopOnFailure, macroName ) \
|
#define INTERNAL_CATCH_TEST( expr, isNot, stopOnFailure, macroName ) \
|
||||||
do{ try{ \
|
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& ){ \
|
}catch( Catch::TestFailureException& ){ \
|
||||||
throw; \
|
throw; \
|
||||||
} catch( ... ){ \
|
} 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; \
|
throw; \
|
||||||
}}while( Catch::isTrue( false ) )
|
}}while( Catch::isTrue( false ) )
|
||||||
|
|
||||||
@ -85,11 +85,11 @@ inline bool isTrue( bool value ){ return value; }
|
|||||||
try \
|
try \
|
||||||
{ \
|
{ \
|
||||||
expr; \
|
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( ... ) \
|
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 \
|
try \
|
||||||
{ \
|
{ \
|
||||||
expr; \
|
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& ) \
|
catch( Catch::TestFailureException& ) \
|
||||||
{ \
|
{ \
|
||||||
@ -105,7 +105,7 @@ inline bool isTrue( bool value ){ return value; }
|
|||||||
} \
|
} \
|
||||||
catch( exceptionType ) \
|
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 ) \
|
INTERNAL_CATCH_THROWS( expr, exceptionType, stopOnFailure, macroName ) \
|
||||||
catch( ... ) \
|
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 ) \
|
#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 ) \
|
#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 ) \
|
#define INTERNAL_CHECK_THAT( arg, matcher, stopOnFailure, macroName ) \
|
||||||
do{ try{ \
|
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& ){ \
|
}catch( Catch::TestFailureException& ){ \
|
||||||
throw; \
|
throw; \
|
||||||
} catch( ... ){ \
|
} 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; \
|
throw; \
|
||||||
}}while( Catch::isTrue( false ) )
|
}}while( Catch::isTrue( false ) )
|
||||||
|
|
||||||
|
@ -17,102 +17,57 @@
|
|||||||
#include "catch_common.h"
|
#include "catch_common.h"
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
namespace Catch
|
namespace Catch {
|
||||||
{
|
|
||||||
|
|
||||||
class ResultBuilder
|
class ExpressionBuilder {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
ExpressionBuilder( const SourceLineInfo& lineInfo,
|
||||||
ResultBuilder
|
|
||||||
(
|
|
||||||
const SourceLineInfo& lineInfo,
|
|
||||||
const char* macroName,
|
const char* macroName,
|
||||||
const char* expr = "",
|
const char* expr = "",
|
||||||
bool isNot = false
|
bool isNot = false )
|
||||||
)
|
|
||||||
: m_result( expr, isNot, lineInfo, macroName ),
|
: m_result( expr, isNot, lineInfo, macroName ),
|
||||||
m_messageStream()
|
m_messageStream()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
Expression<const T&> operator->*
|
Expression<const T&> operator->* ( const T & operand ) {
|
||||||
(
|
|
||||||
const T & operand
|
|
||||||
)
|
|
||||||
{
|
|
||||||
Expression<const T&> expr( m_result, operand );
|
Expression<const T&> expr( m_result, operand );
|
||||||
|
|
||||||
return expr;
|
return expr;
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
Expression<const char*> operator->* ( const char* const& operand ) {
|
||||||
Expression<const char*> operator->*
|
|
||||||
(
|
|
||||||
const char* const& operand
|
|
||||||
)
|
|
||||||
{
|
|
||||||
Expression<const char*> expr( m_result, operand );
|
Expression<const char*> expr( m_result, operand );
|
||||||
|
|
||||||
return expr;
|
return expr;
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
PtrExpression<T> operator->*
|
PtrExpression<T> operator->* ( const T* operand ) {
|
||||||
(
|
|
||||||
const T* operand
|
|
||||||
)
|
|
||||||
{
|
|
||||||
PtrExpression<T> expr( m_result, operand );
|
PtrExpression<T> expr( m_result, operand );
|
||||||
|
|
||||||
return expr;
|
return expr;
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
PtrExpression<T> operator->*
|
PtrExpression<T> operator->* ( T* operand ) {
|
||||||
(
|
|
||||||
T* operand
|
|
||||||
)
|
|
||||||
{
|
|
||||||
PtrExpression<T> expr( m_result, operand );
|
PtrExpression<T> expr( m_result, operand );
|
||||||
|
|
||||||
return expr;
|
return expr;
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
Expression<bool> operator->* ( bool value ) {
|
||||||
Expression<bool> operator->*
|
|
||||||
(
|
|
||||||
bool value
|
|
||||||
)
|
|
||||||
{
|
|
||||||
Expression<bool> expr( m_result, value );
|
Expression<bool> expr( m_result, value );
|
||||||
return expr;
|
return expr;
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
ResultBuilder& operator <<
|
ExpressionBuilder& operator << ( const T & value ) {
|
||||||
(
|
|
||||||
const T & value
|
|
||||||
)
|
|
||||||
{
|
|
||||||
m_messageStream << Catch::toString( value );
|
m_messageStream << Catch::toString( value );
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
|
||||||
template<typename MatcherT, typename ArgT>
|
template<typename MatcherT, typename ArgT>
|
||||||
ResultBuilder& acceptMatcher
|
ExpressionBuilder& acceptMatcher( const MatcherT& matcher,
|
||||||
(
|
|
||||||
const MatcherT& matcher,
|
|
||||||
const ArgT& arg,
|
const ArgT& arg,
|
||||||
const std::string& matcherCallAsString
|
const std::string& matcherCallAsString ) {
|
||||||
)
|
|
||||||
{
|
|
||||||
std::string matcherAsString = Catch::toString( matcher );
|
std::string matcherAsString = Catch::toString( matcher );
|
||||||
if( matcherAsString == "{?}" )
|
if( matcherAsString == "{?}" )
|
||||||
matcherAsString = matcherCallAsString;
|
matcherAsString = matcherCallAsString;
|
||||||
@ -123,15 +78,10 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
|
||||||
template<typename MatcherT, typename ArgT>
|
template<typename MatcherT, typename ArgT>
|
||||||
ResultBuilder& acceptMatcher
|
ExpressionBuilder& acceptMatcher( const MatcherT& matcher,
|
||||||
(
|
|
||||||
const MatcherT& matcher,
|
|
||||||
ArgT* arg,
|
ArgT* arg,
|
||||||
const std::string& matcherCallAsString
|
const std::string& matcherCallAsString ) {
|
||||||
)
|
|
||||||
{
|
|
||||||
std::string matcherAsString = Catch::toString( matcher );
|
std::string matcherAsString = Catch::toString( matcher );
|
||||||
if( matcherAsString == "{?}" )
|
if( matcherAsString == "{?}" )
|
||||||
matcherAsString = matcherCallAsString;
|
matcherAsString = matcherCallAsString;
|
||||||
@ -142,20 +92,12 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
ExpressionBuilder& setResultType( ResultWas::OfType resultType ) {
|
||||||
ResultBuilder& setResultType
|
|
||||||
(
|
|
||||||
ResultWas::OfType resultType
|
|
||||||
)
|
|
||||||
{
|
|
||||||
m_result.setResultType( resultType );
|
m_result.setResultType( resultType );
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
operator ResultInfoBuilder&() {
|
||||||
operator ResultInfoBuilder&
|
|
||||||
()
|
|
||||||
{
|
|
||||||
m_result.setMessage( m_messageStream.str() );
|
m_result.setMessage( m_messageStream.str() );
|
||||||
return m_result;
|
return m_result;
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@ public:
|
|||||||
);
|
);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class ResultBuilder;
|
friend class ExpressionBuilder;
|
||||||
template<typename T> friend class Expression;
|
template<typename T> friend class Expression;
|
||||||
|
|
||||||
template<typename T> friend class PtrExpression;
|
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>"; };
|
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>"; };
|
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>"; };
|
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>"; };
|
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>"; };
|
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>"; };
|
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