StopOnFailure now works again

This commit is contained in:
Phil Nash 2011-03-14 19:21:35 +00:00
parent b87bff21cd
commit 4890a1d80a
4 changed files with 27 additions and 15 deletions

View File

@ -46,7 +46,7 @@ TEST_CASE( "./failing/exceptions/explicit", "When checked exceptions are thrown
CHECK_NOTHROW( thisThrows() ); CHECK_NOTHROW( thisThrows() );
} }
INTERNAL_CATCH_TESTCASE_NORETURN( "./failing/exceptions/implicit", "When unchecked exceptions are thrown they are always failures" ) TEST_CASE_NORETURN( "./failing/exceptions/implicit", "When unchecked exceptions are thrown they are always failures" )
{ {
throw std::domain_error( "unexpected exception" ); throw std::domain_error( "unexpected exception" );
/*NOTREACHED*/ /*NOTREACHED*/

View File

@ -194,6 +194,12 @@ namespace Catch
m_config.stream() << "Unexpected"; m_config.stream() << "Unexpected";
m_config.stream() << " exception with message: '" << resultInfo.getMessage() << "'"; m_config.stream() << " exception with message: '" << resultInfo.getMessage() << "'";
break; break;
case ResultWas::DidntThrowException:
if( resultInfo.hasExpression() )
m_config.stream() << " because no exception was thrown where one was expected";
else
m_config.stream() << "No exception thrown where one was expected";
break;
case ResultWas::Info: case ResultWas::Info:
m_config.stream() << "info:\n'" << resultInfo.getMessage() << "'"; m_config.stream() << "info:\n'" << resultInfo.getMessage() << "'";
break; break;
@ -204,6 +210,13 @@ namespace Catch
m_config.stream() << "failed with message: '" << resultInfo.getMessage() << "'"; m_config.stream() << "failed with message: '" << resultInfo.getMessage() << "'";
break; break;
default: default:
if( !resultInfo.hasExpression() )
{
if( resultInfo.ok() )
m_config.stream() << " succeeded";
else
m_config.stream() << " failed";
}
break; break;
} }

View File

@ -537,8 +537,8 @@ inline bool isTrue
} // end namespace Catch } // end namespace Catch
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
#define INTERNAL_CATCH_ACCEPT_RESULT2( result, stopOnFailure ) \ #define INTERNAL_CATCH_ACCEPT_EXPR( expr, stopOnFailure ) \
if( Catch::ResultAction::Value action = Catch::Hub::getResultCapture().acceptResult( result ) ) \ if( Catch::ResultAction::Value action = Catch::Hub::getResultCapture().acceptExpression( expr ) ) \
{ \ { \
if( action == Catch::ResultAction::DebugFailed ) BreakIntoDebugger(); \ if( action == Catch::ResultAction::DebugFailed ) BreakIntoDebugger(); \
if( Catch::isTrue( stopOnFailure ) ) throw Catch::TestFailureException(); \ if( Catch::isTrue( stopOnFailure ) ) throw Catch::TestFailureException(); \
@ -546,34 +546,34 @@ inline bool isTrue
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
#define INTERNAL_CATCH_TEST( expr, isNot, stopOnFailure, macroName ) \ #define INTERNAL_CATCH_TEST( expr, isNot, stopOnFailure, macroName ) \
Catch::Hub::getResultCapture().acceptExpression( Catch::ResultBuilder( __FILE__, __LINE__, macroName, #expr, isNot )->*expr ); INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ResultBuilder( __FILE__, __LINE__, macroName, #expr, isNot )->*expr ), stopOnFailure );
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
#define INTERNAL_CATCH_NO_THROW( expr, stopOnFailure, macroName ) \ #define INTERNAL_CATCH_NO_THROW( expr, stopOnFailure, macroName ) \
try \ try \
{ \ { \
using namespace Catch; \
expr; \ expr; \
Hub::getResultCapture().acceptExpression( ResultBuilder( __FILE__, __LINE__, macroName, #expr ).setResultType( ResultWas::Ok ) ); \ INTERNAL_CATCH_ACCEPT_EXPR( Catch::ResultBuilder( __FILE__, __LINE__, macroName, #expr ).setResultType( Catch::ResultWas::Ok ), stopOnFailure ); \
} \ } \
catch( ... ) \ catch( ... ) \
{ \ { \
using namespace Catch; \ INTERNAL_CATCH_ACCEPT_EXPR( Catch::ResultBuilder( __FILE__, __LINE__, macroName, #expr ).setResultType( Catch::ResultWas::ThrewException ), stopOnFailure ); \
Hub::getResultCapture().acceptExpression( ResultBuilder( __FILE__, __LINE__, macroName, #expr ).setResultType( ResultWas::ThrewException ) ); \
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
#define INTERNAL_CATCH_THROWS( expr, exceptionType, stopOnFailure, macroName ) \ #define INTERNAL_CATCH_THROWS( expr, exceptionType, stopOnFailure, macroName ) \
try \ try \
{ \ { \
using namespace Catch; \
expr; \ expr; \
Hub::getResultCapture().acceptExpression( ResultBuilder( __FILE__, __LINE__, macroName, #expr ).setResultType( ResultWas::DidntThrowException ) ); \ INTERNAL_CATCH_ACCEPT_EXPR( Catch::ResultBuilder( __FILE__, __LINE__, macroName, #expr ).setResultType( Catch::ResultWas::DidntThrowException ), stopOnFailure ); \
} \
catch( Catch::TestFailureException& ) \
{ \
throw; \
} \ } \
catch( exceptionType ) \ catch( exceptionType ) \
{ \ { \
using namespace Catch; \ INTERNAL_CATCH_ACCEPT_EXPR( Catch::ResultBuilder( __FILE__, __LINE__, macroName, #expr ).setResultType( Catch::ResultWas::Ok ), stopOnFailure ); \
Hub::getResultCapture().acceptExpression( ResultBuilder( __FILE__, __LINE__, macroName, #expr ).setResultType( ResultWas::Ok ) ); \
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -581,8 +581,7 @@ inline bool isTrue
INTERNAL_CATCH_THROWS( expr, exceptionType, stopOnFailure, macroName ) \ INTERNAL_CATCH_THROWS( expr, exceptionType, stopOnFailure, macroName ) \
catch( ... ) \ catch( ... ) \
{ \ { \
using namespace Catch; \ INTERNAL_CATCH_ACCEPT_EXPR( Catch::ResultBuilder( __FILE__, __LINE__, macroName, #expr ).setResultType( Catch::ResultWas::ThrewException ), stopOnFailure ); \
Hub::getResultCapture().acceptExpression( ResultBuilder( __FILE__, __LINE__, macroName, #expr ).setResultType( ResultWas::ThrewException ) ); \
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////

View File

@ -28,7 +28,7 @@ struct ResultWas{ enum OfType
ExpressionFailed = FailureBit | 1, ExpressionFailed = FailureBit | 1,
ExplicitFailure = FailureBit | 2, ExplicitFailure = FailureBit | 2,
Exception = 0x110, Exception = 0x100 | FailureBit,
ThrewException = Exception | 1, ThrewException = Exception | 1,
DidntThrowException = Exception | 2 DidntThrowException = Exception | 2