From 36d0da019435ab5feb85f8e817c84567c15949e8 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Thu, 4 Oct 2012 08:09:09 +0100 Subject: [PATCH] Started refactoring ResultInfo/Builder --- include/internal/catch_capture.hpp | 7 ++-- include/internal/catch_resultinfo.h | 12 +++---- include/internal/catch_resultinfo_builder.h | 28 ++++++++-------- include/internal/catch_resultinfo_builder.hpp | 32 ++++++++++++------- 4 files changed, 46 insertions(+), 33 deletions(-) diff --git a/include/internal/catch_capture.hpp b/include/internal/catch_capture.hpp index 379cc24..cf2f422 100644 --- a/include/internal/catch_capture.hpp +++ b/include/internal/catch_capture.hpp @@ -34,9 +34,12 @@ public: m_oss << value; return *this; } - + ResultInfo getInfo () const { - return ResultInfo( "", ResultWas::Info, false, SourceLineInfo(), "SCOPED_INFO", m_oss.str().c_str() ); + return ResultInfoBuilder() + .setResultType( ResultWas::Info ) + .setMessage( m_oss.str() ) + .setMacroName( "SCOPED_INFO" ); } private: diff --git a/include/internal/catch_resultinfo.h b/include/internal/catch_resultinfo.h index 9badb4d..8bcc8c0 100644 --- a/include/internal/catch_resultinfo.h +++ b/include/internal/catch_resultinfo.h @@ -16,12 +16,6 @@ namespace Catch { class ResultInfo { public: ResultInfo(); - ResultInfo( const char* expr, - ResultWas::OfType result, - bool isNot, - const SourceLineInfo& lineInfo, - const char* macroName, - const char* message ); ~ResultInfo(); bool ok() const; @@ -37,6 +31,12 @@ namespace Catch { std::string getTestMacroName() const; protected: + ResultInfo( const char* expr, + ResultWas::OfType result, + bool isNot, + const SourceLineInfo& lineInfo, + const char* macroName, + const char* message ); std::string getExpandedExpressionInternal() const; bool isNotExpression( const char* expr ); diff --git a/include/internal/catch_resultinfo_builder.h b/include/internal/catch_resultinfo_builder.h index 37daf3c..70082ae 100644 --- a/include/internal/catch_resultinfo_builder.h +++ b/include/internal/catch_resultinfo_builder.h @@ -19,23 +19,17 @@ namespace Catch { struct STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison; class ResultInfoBuilder : public ResultInfo { - public: - ResultInfoBuilder(); - - ResultInfoBuilder( const char* expr, - bool isNot, - const SourceLineInfo& lineInfo, - const char* macroName, - const char* message = "" ); + ResultInfoBuilder(); - void setResultType( ResultWas::OfType result ); - void setMessage( const std::string& message ); - void setLineInfo( const SourceLineInfo& lineInfo ); - void setLhs( const std::string& lhs ); - void setRhs( const std::string& rhs ); - void setOp( const std::string& op ); + ResultInfoBuilder& setResultType( ResultWas::OfType result ); + ResultInfoBuilder& setMessage( const std::string& message ); + ResultInfoBuilder& setLineInfo( const SourceLineInfo& lineInfo ); + ResultInfoBuilder& setLhs( const std::string& lhs ); + ResultInfoBuilder& setRhs( const std::string& rhs ); + ResultInfoBuilder& setOp( const std::string& op ); + ResultInfoBuilder& setMacroName( const std::string& macroName ); template STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator || ( const RhsT& ); @@ -44,6 +38,12 @@ public: STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator && ( const RhsT& ); private: + + ResultInfoBuilder( const char* expr, + bool isNot, + const SourceLineInfo& lineInfo, + const char* macroName ); + friend class ExpressionBuilder; template friend class Expression; diff --git a/include/internal/catch_resultinfo_builder.hpp b/include/internal/catch_resultinfo_builder.hpp index 0dd8730..1421f52 100644 --- a/include/internal/catch_resultinfo_builder.hpp +++ b/include/internal/catch_resultinfo_builder.hpp @@ -12,17 +12,16 @@ namespace Catch { - ResultInfoBuilder::ResultInfoBuilder() {} - ResultInfoBuilder::ResultInfoBuilder( const char* expr, bool isNot, const SourceLineInfo& lineInfo, - const char* macroName, - const char* message ) - : ResultInfo( expr, ResultWas::Unknown, isNot, lineInfo, macroName, message ) + const char* macroName ) + : ResultInfo( expr, ResultWas::Unknown, isNot, lineInfo, macroName, "" ) {} - void ResultInfoBuilder::setResultType( ResultWas::OfType result ) { + ResultInfoBuilder::ResultInfoBuilder() {} + + ResultInfoBuilder& ResultInfoBuilder::setResultType( ResultWas::OfType result ) { // Flip bool results if isNot is set if( m_isNot && result == ResultWas::Ok ) m_result = ResultWas::ExpressionFailed; @@ -30,26 +29,37 @@ namespace Catch { m_result = ResultWas::Ok; else m_result = result; + return *this; } - void ResultInfoBuilder::setMessage( const std::string& message ) { + ResultInfoBuilder& ResultInfoBuilder::setMessage( const std::string& message ) { m_message = message; + return *this; } - void ResultInfoBuilder::setLineInfo( const SourceLineInfo& lineInfo ) { + ResultInfoBuilder& ResultInfoBuilder::setLineInfo( const SourceLineInfo& lineInfo ) { m_lineInfo = lineInfo; + return *this; } - void ResultInfoBuilder::setLhs( const std::string& lhs ) { + ResultInfoBuilder& ResultInfoBuilder::setLhs( const std::string& lhs ) { m_lhs = lhs; + return *this; } - void ResultInfoBuilder::setRhs( const std::string& rhs ) { + ResultInfoBuilder& ResultInfoBuilder::setRhs( const std::string& rhs ) { m_rhs = rhs; + return *this; } - void ResultInfoBuilder::setOp( const std::string& op ) { + ResultInfoBuilder& ResultInfoBuilder::setOp( const std::string& op ) { m_op = op; + return *this; + } + + ResultInfoBuilder& ResultInfoBuilder::setMacroName( const std::string& macroName ) { + m_macroName = macroName; + return *this; } ResultInfoBuilder& ResultInfoBuilder::captureBoolExpression( bool result ) {