Renamed ResultInfo -> AssertionResult

This commit is contained in:
Phil Nash 2012-10-16 08:27:21 +01:00
parent 175da3ef64
commit d16955f63a
15 changed files with 111 additions and 97 deletions

View File

@ -35,8 +35,8 @@ public:
return *this;
}
ResultInfo getInfo () const {
return ResultInfoBuilder()
AssertionResult getInfo () const {
return AssertionResultBuilder()
.setResultType( ResultWas::Info )
.setMessage( m_oss.str() )
.setMacroName( "SCOPED_INFO" )

View File

@ -18,50 +18,50 @@ class Expression {
void operator = ( const Expression& );
public:
Expression( ResultInfoBuilder& result, T lhs )
Expression( AssertionResultBuilder& result, T lhs )
: m_result( result.setLhs( Catch::toString( lhs ) ) ),
m_lhs( lhs )
{}
template<typename RhsT>
ResultInfoBuilder& operator == ( const RhsT& rhs ) {
AssertionResultBuilder& operator == ( const RhsT& rhs ) {
return captureExpression<Internal::IsEqualTo>( rhs );
}
template<typename RhsT>
ResultInfoBuilder& operator != ( const RhsT& rhs ) {
AssertionResultBuilder& operator != ( const RhsT& rhs ) {
return captureExpression<Internal::IsNotEqualTo>( rhs );
}
template<typename RhsT>
ResultInfoBuilder& operator < ( const RhsT& rhs ) {
AssertionResultBuilder& operator < ( const RhsT& rhs ) {
return captureExpression<Internal::IsLessThan>( rhs );
}
template<typename RhsT>
ResultInfoBuilder& operator > ( const RhsT& rhs ) {
AssertionResultBuilder& operator > ( const RhsT& rhs ) {
return captureExpression<Internal::IsGreaterThan>( rhs );
}
template<typename RhsT>
ResultInfoBuilder& operator <= ( const RhsT& rhs ) {
AssertionResultBuilder& operator <= ( const RhsT& rhs ) {
return captureExpression<Internal::IsLessThanOrEqualTo>( rhs );
}
template<typename RhsT>
ResultInfoBuilder& operator >= ( const RhsT& rhs ) {
AssertionResultBuilder& operator >= ( const RhsT& rhs ) {
return captureExpression<Internal::IsGreaterThanOrEqualTo>( rhs );
}
ResultInfoBuilder& operator == ( bool rhs ) {
AssertionResultBuilder& operator == ( bool rhs ) {
return captureExpression<Internal::IsEqualTo>( rhs );
}
ResultInfoBuilder& operator != ( bool rhs ) {
AssertionResultBuilder& operator != ( bool rhs ) {
return captureExpression<Internal::IsNotEqualTo>( rhs );
}
operator ResultInfoBuilder& () {
operator AssertionResultBuilder& () {
return m_result.setResultType( m_lhs ? ResultWas::Ok : ResultWas::ExpressionFailed );
}
@ -73,7 +73,7 @@ public:
private:
template<Internal::Operator Op, typename RhsT>
ResultInfoBuilder& captureExpression( const RhsT& rhs ) {
AssertionResultBuilder& captureExpression( const RhsT& rhs ) {
return m_result
.setResultType( Internal::compare<Op>( m_lhs, rhs ) ? ResultWas::Ok : ResultWas::ExpressionFailed )
.setRhs( Catch::toString( rhs ) )
@ -81,7 +81,7 @@ private:
}
private:
ResultInfoBuilder& m_result;
AssertionResultBuilder& m_result;
T m_lhs;
};

View File

@ -87,13 +87,13 @@ public:
return *this;
}
operator ResultInfoBuilder&() {
operator AssertionResultBuilder&() {
m_result.setMessage( m_messageStream.str() );
return m_result;
}
private:
ResultInfoBuilder m_result;
AssertionResultBuilder m_result;
std::ostringstream m_messageStream;
};

View File

@ -17,14 +17,14 @@ namespace Catch {
class TestCaseInfo;
class ScopedInfo;
class ResultInfoBuilder;
class ResultInfo;
class AssertionResultBuilder;
class AssertionResult;
struct IResultCapture {
virtual ~IResultCapture();
virtual void testEnded( const ResultInfo& result ) = 0;
virtual void testEnded( const AssertionResult& result ) = 0;
virtual bool sectionStarted( const std::string& name,
const std::string& description,
const SourceLineInfo& lineInfo,
@ -36,11 +36,11 @@ namespace Catch {
virtual ResultAction::Value acceptResult( bool result ) = 0;
virtual ResultAction::Value acceptResult( ResultWas::OfType result ) = 0;
virtual ResultAction::Value acceptExpression( const ResultInfoBuilder& resultInfo ) = 0;
virtual ResultAction::Value acceptExpression( const AssertionResultBuilder& resultInfo ) = 0;
virtual void acceptMessage( const std::string& msg ) = 0;
virtual std::string getCurrentTestName() const = 0;
virtual const ResultInfo* getLastResult() const = 0;
virtual const AssertionResult* getLastResult() const = 0;
};
}

View File

@ -49,23 +49,37 @@ namespace Catch
};
class TestCaseInfo;
class ResultInfo;
class AssertionResult;
struct IReporter : IShared {
virtual ~IReporter();
virtual bool shouldRedirectStdout() const = 0;
virtual void StartTesting() = 0;
virtual void EndTesting( const Totals& totals ) = 0;
virtual void StartGroup( const std::string& groupName ) = 0;
virtual void EndGroup( const std::string& groupName, const Totals& totals ) = 0;
virtual void StartTestCase( const TestCaseInfo& testInfo ) = 0;
// TestCaseResult
virtual void EndTestCase( const TestCaseInfo& testInfo, const Totals& totals, const std::string& stdOut, const std::string& stdErr ) = 0;
// SectionInfo
virtual void StartSection( const std::string& sectionName, const std::string& description ) = 0;
// Section Result
virtual void EndSection( const std::string& sectionName, const Counts& assertions ) = 0;
// - merge into SectionResult ?
virtual void NoAssertionsInSection( const std::string& sectionName ) = 0;
virtual void NoAssertionsInTestCase( const std::string& testName ) = 0;
virtual void EndSection( const std::string& sectionName, const Counts& assertions ) = 0;
virtual void StartTestCase( const TestCaseInfo& testInfo ) = 0;
// - merge into SectionResult, TestCaseResult, GroupResult & TestRunResult
virtual void Aborted() = 0;
virtual void EndTestCase( const TestCaseInfo& testInfo, const Totals& totals, const std::string& stdOut, const std::string& stdErr ) = 0;
virtual void Result( const ResultInfo& result ) = 0;
// AssertionReslt
virtual void Result( const AssertionResult& result ) = 0;
};
struct IReporterFactory {

View File

@ -5,8 +5,8 @@
* Distributed under the Boost Software License, Version 1.0. (See accompanying
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef TWOBLUECUBES_CATCH_RESULTINFO_H_INCLUDED
#define TWOBLUECUBES_CATCH_RESULTINFO_H_INCLUDED
#ifndef TWOBLUECUBES_CATCH_ASSERTIONRESULT_H_INCLUDED
#define TWOBLUECUBES_CATCH_ASSERTIONRESULT_H_INCLUDED
#include <string>
#include "catch_result_type.h"
@ -25,11 +25,11 @@ namespace Catch {
ResultWas::OfType resultType;
};
class ResultInfo {
class AssertionResult {
public:
ResultInfo();
ResultInfo( const ResultData& data );
~ResultInfo();
AssertionResult();
AssertionResult( const ResultData& data );
~AssertionResult();
bool ok() const;
ResultWas::OfType getResultType() const;
@ -49,4 +49,4 @@ namespace Catch {
} // end namespace Catch
#endif // TWOBLUECUBES_CATCH_RESULTINFO_H_INCLUDED
#endif // TWOBLUECUBES_CATCH_ASSERTIONRESULT_H_INCLUDED

View File

@ -5,63 +5,63 @@
* Distributed under the Boost Software License, Version 1.0. (See accompanying
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef TWOBLUECUBES_CATCH_RESULTINFO_HPP_INCLUDED
#define TWOBLUECUBES_CATCH_RESULTINFO_HPP_INCLUDED
#ifndef TWOBLUECUBES_CATCH_ASSERTIONRESULT_HPP_INCLUDED
#define TWOBLUECUBES_CATCH_ASSERTIONRESULT_HPP_INCLUDED
#include "catch_resultinfo.h"
namespace Catch {
ResultInfo::ResultInfo() {}
AssertionResult::AssertionResult() {}
ResultInfo::ResultInfo( const ResultData& data ) : m_data( data ) {}
AssertionResult::AssertionResult( const ResultData& data ) : m_data( data ) {}
ResultInfo::~ResultInfo() {}
AssertionResult::~AssertionResult() {}
bool ResultInfo::ok() const {
bool AssertionResult::ok() const {
return isOk( m_data.resultType );
}
ResultWas::OfType ResultInfo::getResultType() const {
ResultWas::OfType AssertionResult::getResultType() const {
return m_data.resultType;
}
bool ResultInfo::hasExpression() const {
bool AssertionResult::hasExpression() const {
return !m_data.capturedExpression.empty();
}
bool ResultInfo::hasMessage() const {
bool AssertionResult::hasMessage() const {
return !m_data.message.empty();
}
std::string ResultInfo::getExpression() const {
std::string AssertionResult::getExpression() const {
return m_data.capturedExpression;
}
bool ResultInfo::hasExpandedExpression() const {
bool AssertionResult::hasExpandedExpression() const {
return hasExpression() && getExpandedExpression() != getExpression();
}
std::string ResultInfo::getExpandedExpression() const {
std::string AssertionResult::getExpandedExpression() const {
return m_data.reconstructedExpression;
}
std::string ResultInfo::getMessage() const {
std::string AssertionResult::getMessage() const {
return m_data.message;
}
std::string ResultInfo::getFilename() const {
std::string AssertionResult::getFilename() const {
return m_data.lineInfo.file;
}
std::size_t ResultInfo::getLine() const {
std::size_t AssertionResult::getLine() const {
return m_data.lineInfo.line;
}
std::string ResultInfo::getTestMacroName() const {
std::string AssertionResult::getTestMacroName() const {
return m_data.macroName;
}
} // end namespace Catch
#endif // TWOBLUECUBES_CATCH_RESULTINFO_HPP_INCLUDED
#endif // TWOBLUECUBES_CATCH_ASSERTIONRESULT_HPP_INCLUDED

View File

@ -5,8 +5,8 @@
* Distributed under the Boost Software License, Version 1.0. (See accompanying
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef TWOBLUECUBES_CATCH_RESULTINFO_BUILDER_H_INCLUDED
#define TWOBLUECUBES_CATCH_RESULTINFO_BUILDER_H_INCLUDED
#ifndef TWOBLUECUBES_CATCH_ASSERTIONRESULT_BUILDER_H_INCLUDED
#define TWOBLUECUBES_CATCH_ASSERTIONRESULT_BUILDER_H_INCLUDED
#include "catch_tostring.hpp"
#include "catch_resultinfo.h"
@ -18,24 +18,24 @@ namespace Catch {
struct STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison;
class ResultInfoBuilder {
class AssertionResultBuilder {
public:
ResultInfoBuilder();
AssertionResultBuilder();
ResultInfoBuilder& setResultType( ResultWas::OfType result );
ResultInfoBuilder& setCapturedExpression( const std::string& capturedExpression );
ResultInfoBuilder& setIsFalse( bool isFalse );
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 );
AssertionResultBuilder& setResultType( ResultWas::OfType result );
AssertionResultBuilder& setCapturedExpression( const std::string& capturedExpression );
AssertionResultBuilder& setIsFalse( bool isFalse );
AssertionResultBuilder& setMessage( const std::string& message );
AssertionResultBuilder& setLineInfo( const SourceLineInfo& lineInfo );
AssertionResultBuilder& setLhs( const std::string& lhs );
AssertionResultBuilder& setRhs( const std::string& rhs );
AssertionResultBuilder& setOp( const std::string& op );
AssertionResultBuilder& setMacroName( const std::string& macroName );
std::string reconstructExpression() const;
ResultInfo build() const;
AssertionResult build() const;
// Disable attempts to use || and && in expressions (without parantheses)
template<typename RhsT>
@ -55,4 +55,4 @@ private:
} // end namespace Catch
#endif // TWOBLUECUBES_CATCH_RESULTINFO_BUILDER_H_INCLUDED
#endif // TWOBLUECUBES_CATCH_ASSERTIONRESULT_BUILDER_H_INCLUDED

View File

@ -5,16 +5,16 @@
* Distributed under the Boost Software License, Version 1.0. (See accompanying
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef TWOBLUECUBES_CATCH_RESULTINFO_BUILDER_HPP_INCLUDED
#define TWOBLUECUBES_CATCH_RESULTINFO_BUILDER_HPP_INCLUDED
#ifndef TWOBLUECUBES_CATCH_ASSERTIONRESULT_BUILDER_HPP_INCLUDED
#define TWOBLUECUBES_CATCH_ASSERTIONRESULT_BUILDER_HPP_INCLUDED
#include "catch_resultinfo_builder.h"
namespace Catch {
ResultInfoBuilder::ResultInfoBuilder() {}
AssertionResultBuilder::AssertionResultBuilder() {}
ResultInfoBuilder& ResultInfoBuilder::setResultType( ResultWas::OfType result ) {
AssertionResultBuilder& AssertionResultBuilder::setResultType( ResultWas::OfType result ) {
// Flip bool results if isFalse is set
if( m_isFalse && result == ResultWas::Ok )
m_data.resultType = ResultWas::ExpressionFailed;
@ -24,46 +24,46 @@ namespace Catch {
m_data.resultType = result;
return *this;
}
ResultInfoBuilder& ResultInfoBuilder::setCapturedExpression( const std::string& capturedExpression ) {
AssertionResultBuilder& AssertionResultBuilder::setCapturedExpression( const std::string& capturedExpression ) {
m_data.capturedExpression = capturedExpression;
return *this;
}
ResultInfoBuilder& ResultInfoBuilder::setIsFalse( bool isFalse ) {
AssertionResultBuilder& AssertionResultBuilder::setIsFalse( bool isFalse ) {
m_isFalse = isFalse;
return *this;
}
ResultInfoBuilder& ResultInfoBuilder::setMessage( const std::string& message ) {
AssertionResultBuilder& AssertionResultBuilder::setMessage( const std::string& message ) {
m_data.message = message;
return *this;
}
ResultInfoBuilder& ResultInfoBuilder::setLineInfo( const SourceLineInfo& lineInfo ) {
AssertionResultBuilder& AssertionResultBuilder::setLineInfo( const SourceLineInfo& lineInfo ) {
m_data.lineInfo = lineInfo;
return *this;
}
ResultInfoBuilder& ResultInfoBuilder::setMacroName( const std::string& macroName ) {
AssertionResultBuilder& AssertionResultBuilder::setMacroName( const std::string& macroName ) {
m_data.macroName = macroName;
return *this;
}
ResultInfoBuilder& ResultInfoBuilder::setLhs( const std::string& lhs ) {
AssertionResultBuilder& AssertionResultBuilder::setLhs( const std::string& lhs ) {
m_lhs = lhs;
return *this;
}
ResultInfoBuilder& ResultInfoBuilder::setRhs( const std::string& rhs ) {
AssertionResultBuilder& AssertionResultBuilder::setRhs( const std::string& rhs ) {
m_rhs = rhs;
return *this;
}
ResultInfoBuilder& ResultInfoBuilder::setOp( const std::string& op ) {
AssertionResultBuilder& AssertionResultBuilder::setOp( const std::string& op ) {
m_op = op;
return *this;
}
ResultInfo ResultInfoBuilder::build() const
AssertionResult AssertionResultBuilder::build() const
{
ResultData data = m_data;
data.reconstructedExpression = reconstructExpression();
@ -77,10 +77,10 @@ namespace Catch {
data.reconstructedExpression = "!(" + data.reconstructedExpression + ")";
}
}
return ResultInfo( data );
return AssertionResult( data );
}
std::string ResultInfoBuilder::reconstructExpression() const {
std::string AssertionResultBuilder::reconstructExpression() const {
if( m_op == "" )
return m_lhs.empty() ? m_data.capturedExpression : m_op + m_lhs;
else if( m_op == "matches" )
@ -99,4 +99,4 @@ namespace Catch {
} // end namespace Catch
#endif // TWOBLUECUBES_CATCH_RESULTINFO_BUILDER_HPP_INCLUDED
#endif // TWOBLUECUBES_CATCH_ASSERTIONRESULT_BUILDER_HPP_INCLUDED

View File

@ -140,7 +140,7 @@ namespace Catch {
return actOnCurrentResult();
}
virtual ResultAction::Value acceptExpression( const ResultInfoBuilder& resultInfo ) {
virtual ResultAction::Value acceptExpression( const AssertionResultBuilder& resultInfo ) {
m_currentResult = resultInfo;
return actOnCurrentResult();
}
@ -149,7 +149,7 @@ namespace Catch {
m_currentResult.setMessage( msg );
}
virtual void testEnded( const ResultInfo& result ) {
virtual void testEnded( const AssertionResult& result ) {
if( result.getResultType() == ResultWas::Ok ) {
m_totals.assertions.passed++;
}
@ -163,8 +163,8 @@ namespace Catch {
m_reporter->Result( (*it)->getInfo() );
}
{
std::vector<ResultInfo>::const_iterator it = m_info.begin();
std::vector<ResultInfo>::const_iterator itEnd = m_info.end();
std::vector<AssertionResult>::const_iterator it = m_info.begin();
std::vector<AssertionResult>::const_iterator itEnd = m_info.end();
for(; it != itEnd; ++it )
m_reporter->Result( *it );
}
@ -229,7 +229,7 @@ namespace Catch {
: "";
}
virtual const ResultInfo* getLastResult() const {
virtual const AssertionResult* getLastResult() const {
return &m_lastResult;
}
@ -245,7 +245,7 @@ namespace Catch {
m_lastResult = m_currentResult.build();
testEnded( m_lastResult );
m_currentResult = ResultInfoBuilder();
m_currentResult = AssertionResultBuilder();
ResultAction::Value action = ResultAction::None;
@ -293,14 +293,14 @@ namespace Catch {
private:
IMutableContext& m_context;
RunningTest* m_runningTest;
ResultInfoBuilder m_currentResult;
ResultInfo m_lastResult;
AssertionResultBuilder m_currentResult;
AssertionResult m_lastResult;
const Config& m_config;
Totals m_totals;
Ptr<IReporter> m_reporter;
std::vector<ScopedInfo*> m_scopedInfos;
std::vector<ResultInfo> m_info;
std::vector<AssertionResult> m_info;
IRunner* m_prevRunner;
IResultCapture* m_prevResultCapture;
const IConfig* m_prevConfig;

View File

@ -159,7 +159,7 @@ namespace Catch {
m_sectionSpans.pop_back();
}
virtual void Result( const ResultInfo& resultInfo ) {
virtual void Result( const AssertionResult& resultInfo ) {
if( !m_config.includeSuccessfulResults && resultInfo.getResultType() == ResultWas::Ok )
return;

View File

@ -97,7 +97,7 @@ namespace Catch {
m_currentStats->m_testCaseStats.push_back( TestCaseStats( testInfo.getName() ) );
}
virtual void Result( const Catch::ResultInfo& resultInfo ) {
virtual void Result( const Catch::AssertionResult& resultInfo ) {
if( resultInfo.getResultType() != ResultWas::Ok || m_config.includeSuccessfulResults ) {
TestCaseStats& testCaseStats = m_currentStats->m_testCaseStats.back();
TestStats stats;

View File

@ -75,7 +75,7 @@ namespace Catch {
m_currentTestSuccess = true;
}
virtual void Result( const Catch::ResultInfo& resultInfo ) {
virtual void Result( const Catch::AssertionResult& resultInfo ) {
if( !m_config.includeSuccessfulResults && resultInfo.getResultType() == ResultWas::Ok )
return;

View File

@ -31,7 +31,7 @@ namespace Catch{
return totals;
}
void MockReporter::Result( const ResultInfo& resultInfo ) {
void MockReporter::Result( const AssertionResult& resultInfo ) {
if( resultInfo.getResultType() == ResultWas::Ok )
return;

View File

@ -95,7 +95,7 @@ namespace Catch {
closeLabel( recordTestCases, testInfo.getName() );
}
virtual void Result( const ResultInfo& resultInfo );
virtual void Result( const AssertionResult& resultInfo );
private: