Bake exception guard into assertion handler flow

This commit is contained in:
Phil Nash 2017-11-23 16:52:46 +00:00
parent f052762c11
commit 5323202652
4 changed files with 9 additions and 18 deletions

View File

@ -61,7 +61,7 @@ namespace Catch {
getCurrentContext().getResultCapture()->assertionStarting( m_assertionInfo ); getCurrentContext().getResultCapture()->assertionStarting( m_assertionInfo );
} }
AssertionHandler::~AssertionHandler() { AssertionHandler::~AssertionHandler() {
if ( m_inExceptionGuard ) { if ( !m_handled ) {
handle( ResultWas::ThrewException, "Exception translation was disabled by CATCH_CONFIG_FAST_COMPILE" ); handle( ResultWas::ThrewException, "Exception translation was disabled by CATCH_CONFIG_FAST_COMPILE" );
getCurrentContext().getResultCapture()->exceptionEarlyReported(); getCurrentContext().getResultCapture()->exceptionEarlyReported();
} }
@ -76,6 +76,7 @@ namespace Catch {
{ {
getCurrentContext().getResultCapture()->assertionRun(); getCurrentContext().getResultCapture()->assertionRun();
getCurrentContext().getResultCapture()->assertionPassed(); getCurrentContext().getResultCapture()->assertionPassed();
m_handled = true;
return; return;
} }
@ -95,6 +96,7 @@ namespace Catch {
} }
void AssertionHandler::handle( AssertionResultData const& resultData, ITransientExpression const* expr ) { void AssertionHandler::handle( AssertionResultData const& resultData, ITransientExpression const* expr ) {
m_handled = true;
getResultCapture().assertionRun(); getResultCapture().assertionRun();
AssertionResult assertionResult{ m_assertionInfo, resultData }; AssertionResult assertionResult{ m_assertionInfo, resultData };
@ -136,15 +138,6 @@ namespace Catch {
handle( ResultWas::ThrewException, Catch::translateActiveException() ); handle( ResultWas::ThrewException, Catch::translateActiveException() );
} }
void AssertionHandler::setExceptionGuard() {
assert( m_inExceptionGuard == false );
m_inExceptionGuard = true;
}
void AssertionHandler::unsetExceptionGuard() {
assert( m_inExceptionGuard == true );
m_inExceptionGuard = false;
}
// This is the overload that takes a string and infers the Equals matcher from it // This is the overload that takes a string and infers the Equals matcher from it
// The more general overload, that takes any string matcher, is in catch_capture_matchers.cpp // The more general overload, that takes any string matcher, is in catch_capture_matchers.cpp
void handleExceptionMatchExpr( AssertionHandler& handler, std::string const& str, StringRef matcherString ) { void handleExceptionMatchExpr( AssertionHandler& handler, std::string const& str, StringRef matcherString ) {

View File

@ -36,7 +36,7 @@ namespace Catch {
AssertionInfo m_assertionInfo; AssertionInfo m_assertionInfo;
bool m_shouldDebugBreak = false; bool m_shouldDebugBreak = false;
bool m_shouldThrow = false; bool m_shouldThrow = false;
bool m_inExceptionGuard = false; bool m_handled = false;
public: public:
AssertionHandler AssertionHandler
@ -62,8 +62,6 @@ namespace Catch {
void reactWithDebugBreak() const; void reactWithDebugBreak() const;
void reactWithoutDebugBreak() const; void reactWithoutDebugBreak() const;
void useActiveException(); void useActiveException();
void setExceptionGuard();
void unsetExceptionGuard();
}; };
void handleExceptionMatchExpr( AssertionHandler& handler, std::string const& str, StringRef matcherString ); void handleExceptionMatchExpr( AssertionHandler& handler, std::string const& str, StringRef matcherString );

View File

@ -34,8 +34,8 @@
// macros. // macros.
// This can potentially cause false negative, if the test code catches // This can potentially cause false negative, if the test code catches
// the exception before it propagates back up to the runner. // the exception before it propagates back up to the runner.
#define INTERNAL_CATCH_TRY( capturer ) capturer.setExceptionGuard(); #define INTERNAL_CATCH_TRY
#define INTERNAL_CATCH_CATCH( capturer ) capturer.unsetExceptionGuard(); #define INTERNAL_CATCH_CATCH( capturer )
#else // CATCH_CONFIG_FAST_COMPILE #else // CATCH_CONFIG_FAST_COMPILE
@ -48,7 +48,7 @@
if( handler.shouldDebugBreak() ) CATCH_BREAK_INTO_DEBUGGER(); \ if( handler.shouldDebugBreak() ) CATCH_BREAK_INTO_DEBUGGER(); \
handler.reactWithoutDebugBreak(); handler.reactWithoutDebugBreak();
#define INTERNAL_CATCH_TRY( capturer ) try #define INTERNAL_CATCH_TRY try
#define INTERNAL_CATCH_CATCH( capturer ) catch(...) { capturer.useActiveException(); } #define INTERNAL_CATCH_CATCH( capturer ) catch(...) { capturer.useActiveException(); }
#endif #endif
@ -57,7 +57,7 @@
#define INTERNAL_CATCH_TEST( macroName, resultDisposition, ... ) \ #define INTERNAL_CATCH_TEST( macroName, resultDisposition, ... ) \
do { \ do { \
Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition ); \ Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition ); \
INTERNAL_CATCH_TRY( catchAssertionHandler ) { \ INTERNAL_CATCH_TRY { \
CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \ CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \
catchAssertionHandler.handle( Catch::Decomposer() <= __VA_ARGS__ ); \ catchAssertionHandler.handle( Catch::Decomposer() <= __VA_ARGS__ ); \
CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS \ CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS \

View File

@ -59,7 +59,7 @@ namespace Catch {
#define INTERNAL_CHECK_THAT( macroName, matcher, resultDisposition, arg ) \ #define INTERNAL_CHECK_THAT( macroName, matcher, resultDisposition, arg ) \
do { \ do { \
Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(arg) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \ Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(arg) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \
INTERNAL_CATCH_TRY( catchAssertionHandler ) { \ INTERNAL_CATCH_TRY { \
catchAssertionHandler.handle( Catch::makeMatchExpr( arg, matcher, #matcher ) ); \ catchAssertionHandler.handle( Catch::makeMatchExpr( arg, matcher, #matcher ) ); \
} INTERNAL_CATCH_CATCH( catchAssertionHandler ) \ } INTERNAL_CATCH_CATCH( catchAssertionHandler ) \
INTERNAL_CATCH_REACT( catchAssertionHandler ) \ INTERNAL_CATCH_REACT( catchAssertionHandler ) \