Started refactoring ResultInfo/Builder

This commit is contained in:
Phil Nash 2012-10-04 08:09:09 +01:00
parent 4104fb735e
commit 36d0da0194
4 changed files with 46 additions and 33 deletions

View File

@ -36,7 +36,10 @@ public:
} }
ResultInfo getInfo () const { 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: private:

View File

@ -16,12 +16,6 @@ namespace Catch {
class ResultInfo { class ResultInfo {
public: public:
ResultInfo(); ResultInfo();
ResultInfo( const char* expr,
ResultWas::OfType result,
bool isNot,
const SourceLineInfo& lineInfo,
const char* macroName,
const char* message );
~ResultInfo(); ~ResultInfo();
bool ok() const; bool ok() const;
@ -37,6 +31,12 @@ namespace Catch {
std::string getTestMacroName() const; std::string getTestMacroName() const;
protected: protected:
ResultInfo( const char* expr,
ResultWas::OfType result,
bool isNot,
const SourceLineInfo& lineInfo,
const char* macroName,
const char* message );
std::string getExpandedExpressionInternal() const; std::string getExpandedExpressionInternal() const;
bool isNotExpression( const char* expr ); bool isNotExpression( const char* expr );

View File

@ -19,23 +19,17 @@ namespace Catch {
struct STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison; struct STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison;
class ResultInfoBuilder : public ResultInfo { class ResultInfoBuilder : public ResultInfo {
public: public:
ResultInfoBuilder(); ResultInfoBuilder();
ResultInfoBuilder( const char* expr, ResultInfoBuilder& setResultType( ResultWas::OfType result );
bool isNot, ResultInfoBuilder& setMessage( const std::string& message );
const SourceLineInfo& lineInfo, ResultInfoBuilder& setLineInfo( const SourceLineInfo& lineInfo );
const char* macroName, ResultInfoBuilder& setLhs( const std::string& lhs );
const char* message = "" ); ResultInfoBuilder& setRhs( const std::string& rhs );
ResultInfoBuilder& setOp( const std::string& op );
void setResultType( ResultWas::OfType result ); ResultInfoBuilder& setMacroName( const std::string& macroName );
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 );
template<typename RhsT> template<typename RhsT>
STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator || ( const RhsT& ); 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& ); STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator && ( const RhsT& );
private: private:
ResultInfoBuilder( const char* expr,
bool isNot,
const SourceLineInfo& lineInfo,
const char* macroName );
friend class ExpressionBuilder; friend class ExpressionBuilder;
template<typename T> friend class Expression; template<typename T> friend class Expression;

View File

@ -12,17 +12,16 @@
namespace Catch { namespace Catch {
ResultInfoBuilder::ResultInfoBuilder() {}
ResultInfoBuilder::ResultInfoBuilder( const char* expr, ResultInfoBuilder::ResultInfoBuilder( const char* expr,
bool isNot, bool isNot,
const SourceLineInfo& lineInfo, const SourceLineInfo& lineInfo,
const char* macroName, const char* macroName )
const char* message ) : ResultInfo( expr, ResultWas::Unknown, isNot, lineInfo, macroName, "" )
: ResultInfo( expr, ResultWas::Unknown, isNot, lineInfo, macroName, message )
{} {}
void ResultInfoBuilder::setResultType( ResultWas::OfType result ) { ResultInfoBuilder::ResultInfoBuilder() {}
ResultInfoBuilder& ResultInfoBuilder::setResultType( ResultWas::OfType result ) {
// Flip bool results if isNot is set // Flip bool results if isNot is set
if( m_isNot && result == ResultWas::Ok ) if( m_isNot && result == ResultWas::Ok )
m_result = ResultWas::ExpressionFailed; m_result = ResultWas::ExpressionFailed;
@ -30,26 +29,37 @@ namespace Catch {
m_result = ResultWas::Ok; m_result = ResultWas::Ok;
else else
m_result = result; m_result = result;
return *this;
} }
void ResultInfoBuilder::setMessage( const std::string& message ) { ResultInfoBuilder& ResultInfoBuilder::setMessage( const std::string& message ) {
m_message = message; m_message = message;
return *this;
} }
void ResultInfoBuilder::setLineInfo( const SourceLineInfo& lineInfo ) { ResultInfoBuilder& ResultInfoBuilder::setLineInfo( const SourceLineInfo& lineInfo ) {
m_lineInfo = lineInfo; m_lineInfo = lineInfo;
return *this;
} }
void ResultInfoBuilder::setLhs( const std::string& lhs ) { ResultInfoBuilder& ResultInfoBuilder::setLhs( const std::string& lhs ) {
m_lhs = lhs; m_lhs = lhs;
return *this;
} }
void ResultInfoBuilder::setRhs( const std::string& rhs ) { ResultInfoBuilder& ResultInfoBuilder::setRhs( const std::string& rhs ) {
m_rhs = rhs; m_rhs = rhs;
return *this;
} }
void ResultInfoBuilder::setOp( const std::string& op ) { ResultInfoBuilder& ResultInfoBuilder::setOp( const std::string& op ) {
m_op = op; m_op = op;
return *this;
}
ResultInfoBuilder& ResultInfoBuilder::setMacroName( const std::string& macroName ) {
m_macroName = macroName;
return *this;
} }
ResultInfoBuilder& ResultInfoBuilder::captureBoolExpression( bool result ) { ResultInfoBuilder& ResultInfoBuilder::captureBoolExpression( bool result ) {