Implemented CHECK_NO_FAIL

This commit is contained in:
Phil Nash
2012-11-13 09:44:52 +00:00
parent af1a321860
commit d539da9030
12 changed files with 119 additions and 55 deletions

View File

@@ -16,18 +16,15 @@ namespace Catch {
struct AssertionInfo
{
AssertionInfo() {}
AssertionInfo( const std::string& _macroName, const SourceLineInfo& _lineInfo, const std::string& _capturedExpression = "", bool _shouldNegate = false )
: macroName( _macroName ),
lineInfo( _lineInfo ),
capturedExpression( _capturedExpression )
{
if( _shouldNegate )
capturedExpression = "!" + _capturedExpression;
}
AssertionInfo( const std::string& _macroName,
const SourceLineInfo& _lineInfo,
const std::string& _capturedExpression,
ResultDisposition::Flags _resultDisposition );
std::string macroName;
SourceLineInfo lineInfo;
std::string capturedExpression;
ResultDisposition::Flags resultDisposition;
};
struct AssertionResultData
@@ -45,7 +42,8 @@ namespace Catch {
AssertionResult( const AssertionInfo& info, const AssertionResultData& data );
~AssertionResult();
bool ok() const;
bool isOk() const;
bool succeeded() const;
ResultWas::OfType getResultType() const;
bool hasExpression() const;
bool hasMessage() const;

View File

@@ -12,6 +12,20 @@
namespace Catch {
AssertionInfo::AssertionInfo( const std::string& _macroName,
const SourceLineInfo& _lineInfo,
const std::string& _capturedExpression,
ResultDisposition::Flags _resultDisposition )
: macroName( _macroName ),
lineInfo( _lineInfo ),
capturedExpression( _capturedExpression ),
resultDisposition( _resultDisposition )
{
if( shouldNegate( resultDisposition ) )
capturedExpression = "!" + _capturedExpression;
}
AssertionResult::AssertionResult() {}
AssertionResult::AssertionResult( const AssertionInfo& info, const AssertionResultData& data )
@@ -21,8 +35,14 @@ namespace Catch {
AssertionResult::~AssertionResult() {}
bool AssertionResult::ok() const {
return isOk( m_resultData.resultType );
// Result was a success
bool AssertionResult::succeeded() const {
return Catch::isOk( m_resultData.resultType );
}
// Result was a success, or failure is suppressed
bool AssertionResult::isOk() const {
return Catch::isOk( m_resultData.resultType ) || shouldSuppressFailure( m_info.resultDisposition );
}
ResultWas::OfType AssertionResult::getResultType() const {

View File

@@ -94,7 +94,7 @@ inline bool isTrue( bool value ){ return value; }
///////////////////////////////////////////////////////////////////////////////
#define INTERNAL_CATCH_ACCEPT_INFO( expr, macroName, resultDisposition ) \
Catch::AssertionInfo INTERNAL_CATCH_ASSERTIONINFO_NAME( macroName, CATCH_INTERNAL_LINEINFO, expr, testFlag( resultDisposition, Catch::ResultDisposition::NegateResult ) );
Catch::AssertionInfo INTERNAL_CATCH_ASSERTIONINFO_NAME( macroName, CATCH_INTERNAL_LINEINFO, expr, resultDisposition );
///////////////////////////////////////////////////////////////////////////////
#define INTERNAL_CATCH_TEST( expr, resultDisposition, macroName ) \
@@ -114,12 +114,12 @@ inline bool isTrue( bool value ){ return value; }
///////////////////////////////////////////////////////////////////////////////
#define INTERNAL_CATCH_IF( expr, resultDisposition, macroName ) \
INTERNAL_CATCH_TEST( expr, resultDisposition, macroName ); \
if( Catch::getResultCapture().getLastResult()->ok() )
if( Catch::getResultCapture().getLastResult()->succeeded() )
///////////////////////////////////////////////////////////////////////////////
#define INTERNAL_CATCH_ELSE( expr, resultDisposition, macroName ) \
INTERNAL_CATCH_TEST( expr, resultDisposition, macroName ); \
if( !Catch::getResultCapture().getLastResult()->ok() )
if( !Catch::getResultCapture().getLastResult()->succeeded() )
///////////////////////////////////////////////////////////////////////////////
#define INTERNAL_CATCH_NO_THROW( expr, resultDisposition, macroName ) \

View File

@@ -39,7 +39,7 @@ namespace Catch {
return *this;
}
ExpressionResultBuilder& ExpressionResultBuilder::endExpression( ResultDisposition::Flags resultDisposition ) {
m_exprComponents.shouldNegate = testFlag( resultDisposition, ResultDisposition::NegateResult );
m_exprComponents.shouldNegate = shouldNegate( resultDisposition );
return *this;
}
ExpressionResultBuilder& ExpressionResultBuilder::setLhs( const std::string& lhs ) {

View File

@@ -57,6 +57,8 @@ namespace Catch {
inline bool resetFlag( int flags, int bitOrBitsToReset ) { return static_cast<ResultDisposition::Flags>( flags & ~bitOrBitsToReset ); }
inline bool shouldContinueOnFailure( int flags ) { return testFlag( flags, ResultDisposition::ContinueOnFailure ); }
inline bool shouldNegate( int flags ) { return testFlag( flags, ResultDisposition::NegateResult ); }
inline bool shouldSuppressFailure( int flags ) { return testFlag( flags, ResultDisposition::SuppressFail ); }
} // end namespace Catch

View File

@@ -139,7 +139,7 @@ namespace Catch {
if( result.getResultType() == ResultWas::Ok ) {
m_totals.assertions.passed++;
}
else if( !result.ok() ) {
else if( !result.isOk() ) {
m_totals.assertions.failed++;
{
@@ -235,7 +235,7 @@ namespace Catch {
ResultAction::Value action = ResultAction::None;
if( !m_lastResult.ok() ) {
if( !m_lastResult.isOk() ) {
action = ResultAction::Failed;
if( shouldDebugBreak() )
action = (ResultAction::Value)( action | ResultAction::Debug );
@@ -247,7 +247,7 @@ namespace Catch {
void runCurrentTest( std::string& redirectedCout, std::string& redirectedCerr ) {
try {
m_lastAssertionInfo = AssertionInfo( "TEST_CASE", m_runningTest->getTestCaseInfo().getLineInfo() );
m_lastAssertionInfo = AssertionInfo( "TEST_CASE", m_runningTest->getTestCaseInfo().getLineInfo(), "", ResultDisposition::Normal );
m_runningTest->reset();
Counts prevAssertions = m_totals.assertions;
if( m_reporter->shouldRedirectStdout() ) {