mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 21:36:11 +01:00
Refactored most handle() calls to more specific/ descriptive calls
This commit is contained in:
parent
2800adba25
commit
db44964e27
@ -68,7 +68,7 @@ namespace Catch {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssertionHandler::handle( ITransientExpression const& expr ) {
|
void AssertionHandler::handleExpr( ITransientExpression const& expr ) {
|
||||||
|
|
||||||
bool negated = isFalseTest( m_assertionInfo.resultDisposition );
|
bool negated = isFalseTest( m_assertionInfo.resultDisposition );
|
||||||
bool result = expr.getResult() != negated;
|
bool result = expr.getResult() != negated;
|
||||||
@ -132,10 +132,26 @@ namespace Catch {
|
|||||||
m_completed = true;
|
m_completed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssertionHandler::useActiveException() {
|
void AssertionHandler::handleUnexpectedInflightException() {
|
||||||
handle( ResultWas::ThrewException, Catch::translateActiveException() );
|
handle( ResultWas::ThrewException, Catch::translateActiveException() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AssertionHandler::handleExceptionThrownAsExpected() {
|
||||||
|
handle( Catch::ResultWas::Ok );
|
||||||
|
}
|
||||||
|
void AssertionHandler::handleExceptionNotThrownAsExpected() {
|
||||||
|
handle( Catch::ResultWas::Ok );
|
||||||
|
}
|
||||||
|
|
||||||
|
void AssertionHandler::handleUnexpectedExceptionNotThrown() {
|
||||||
|
handle( Catch::ResultWas::DidntThrowException );
|
||||||
|
}
|
||||||
|
|
||||||
|
void AssertionHandler::handleThrowingCallSkipped() {
|
||||||
|
handle( Catch::ResultWas::Ok );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// 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 ) {
|
||||||
|
@ -48,21 +48,30 @@ namespace Catch {
|
|||||||
ResultDisposition::Flags resultDisposition );
|
ResultDisposition::Flags resultDisposition );
|
||||||
~AssertionHandler();
|
~AssertionHandler();
|
||||||
|
|
||||||
void handle( ITransientExpression const& expr );
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void handle( ExprLhs<T> const& expr ) {
|
void handleExpr( ExprLhs<T> const& expr ) {
|
||||||
handle( expr.makeUnaryExpr() );
|
handleExpr( expr.makeUnaryExpr() );
|
||||||
}
|
}
|
||||||
void handle( ResultWas::OfType resultType );
|
void handleExpr( ITransientExpression const& expr );
|
||||||
|
|
||||||
void handle( ResultWas::OfType resultType, StringRef const& message );
|
void handle( ResultWas::OfType resultType, StringRef const& message );
|
||||||
void handle( ResultWas::OfType resultType, ITransientExpression const* expr, bool negated );
|
void handle( ResultWas::OfType resultType, ITransientExpression const* expr, bool negated );
|
||||||
void handle( AssertionResultData const& resultData, ITransientExpression const* expr );
|
void handle( AssertionResultData const& resultData, ITransientExpression const* expr );
|
||||||
|
|
||||||
auto allowThrows() const -> bool;
|
void handleExceptionThrownAsExpected();
|
||||||
|
void handleUnexpectedExceptionNotThrown();
|
||||||
|
void handleExceptionNotThrownAsExpected();
|
||||||
|
void handleThrowingCallSkipped();
|
||||||
|
void handleUnexpectedInflightException();
|
||||||
|
|
||||||
void complete();
|
void complete();
|
||||||
void setCompleted();
|
void setCompleted();
|
||||||
void useActiveException();
|
|
||||||
|
// query
|
||||||
|
auto allowThrows() const -> bool;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void handle( ResultWas::OfType resultType );
|
||||||
};
|
};
|
||||||
|
|
||||||
void handleExceptionMatchExpr( AssertionHandler& handler, std::string const& str, StringRef matcherString );
|
void handleExceptionMatchExpr( AssertionHandler& handler, std::string const& str, StringRef matcherString );
|
||||||
|
@ -31,7 +31,7 @@
|
|||||||
#else // CATCH_CONFIG_FAST_COMPILE
|
#else // CATCH_CONFIG_FAST_COMPILE
|
||||||
|
|
||||||
#define INTERNAL_CATCH_TRY try
|
#define INTERNAL_CATCH_TRY try
|
||||||
#define INTERNAL_CATCH_CATCH( handler ) catch(...) { handler.useActiveException(); }
|
#define INTERNAL_CATCH_CATCH( handler ) catch(...) { handler.handleUnexpectedInflightException(); }
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -43,7 +43,7 @@
|
|||||||
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 { \
|
INTERNAL_CATCH_TRY { \
|
||||||
CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \
|
CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \
|
||||||
catchAssertionHandler.handle( Catch::Decomposer() <= __VA_ARGS__ ); \
|
catchAssertionHandler.handleExpr( Catch::Decomposer() <= __VA_ARGS__ ); \
|
||||||
CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS \
|
CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS \
|
||||||
} INTERNAL_CATCH_CATCH( catchAssertionHandler ) \
|
} INTERNAL_CATCH_CATCH( catchAssertionHandler ) \
|
||||||
INTERNAL_CATCH_REACT( catchAssertionHandler ) \
|
INTERNAL_CATCH_REACT( catchAssertionHandler ) \
|
||||||
@ -66,10 +66,10 @@
|
|||||||
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 ); \
|
||||||
try { \
|
try { \
|
||||||
static_cast<void>(__VA_ARGS__); \
|
static_cast<void>(__VA_ARGS__); \
|
||||||
catchAssertionHandler.handle( Catch::ResultWas::Ok ); \
|
catchAssertionHandler.handleExceptionNotThrownAsExpected(); \
|
||||||
} \
|
} \
|
||||||
catch( ... ) { \
|
catch( ... ) { \
|
||||||
catchAssertionHandler.useActiveException(); \
|
catchAssertionHandler.handleUnexpectedInflightException(); \
|
||||||
} \
|
} \
|
||||||
INTERNAL_CATCH_REACT( catchAssertionHandler ) \
|
INTERNAL_CATCH_REACT( catchAssertionHandler ) \
|
||||||
} while( false )
|
} while( false )
|
||||||
@ -81,13 +81,13 @@
|
|||||||
if( catchAssertionHandler.allowThrows() ) \
|
if( catchAssertionHandler.allowThrows() ) \
|
||||||
try { \
|
try { \
|
||||||
static_cast<void>(__VA_ARGS__); \
|
static_cast<void>(__VA_ARGS__); \
|
||||||
catchAssertionHandler.handle( Catch::ResultWas::DidntThrowException ); \
|
catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \
|
||||||
} \
|
} \
|
||||||
catch( ... ) { \
|
catch( ... ) { \
|
||||||
catchAssertionHandler.handle( Catch::ResultWas::Ok ); \
|
catchAssertionHandler.handleExceptionThrownAsExpected(); \
|
||||||
} \
|
} \
|
||||||
else \
|
else \
|
||||||
catchAssertionHandler.handle( Catch::ResultWas::Ok ); \
|
catchAssertionHandler.handleThrowingCallSkipped(); \
|
||||||
INTERNAL_CATCH_REACT( catchAssertionHandler ) \
|
INTERNAL_CATCH_REACT( catchAssertionHandler ) \
|
||||||
} while( false )
|
} while( false )
|
||||||
|
|
||||||
@ -98,16 +98,16 @@
|
|||||||
if( catchAssertionHandler.allowThrows() ) \
|
if( catchAssertionHandler.allowThrows() ) \
|
||||||
try { \
|
try { \
|
||||||
static_cast<void>(expr); \
|
static_cast<void>(expr); \
|
||||||
catchAssertionHandler.handle( Catch::ResultWas::DidntThrowException ); \
|
catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \
|
||||||
} \
|
} \
|
||||||
catch( exceptionType const& ) { \
|
catch( exceptionType const& ) { \
|
||||||
catchAssertionHandler.handle( Catch::ResultWas::Ok ); \
|
catchAssertionHandler.handleExceptionThrownAsExpected(); \
|
||||||
} \
|
} \
|
||||||
catch( ... ) { \
|
catch( ... ) { \
|
||||||
catchAssertionHandler.useActiveException(); \
|
catchAssertionHandler.handleUnexpectedInflightException(); \
|
||||||
} \
|
} \
|
||||||
else \
|
else \
|
||||||
catchAssertionHandler.handle( Catch::ResultWas::Ok ); \
|
catchAssertionHandler.handleThrowingCallSkipped(); \
|
||||||
INTERNAL_CATCH_REACT( catchAssertionHandler ) \
|
INTERNAL_CATCH_REACT( catchAssertionHandler ) \
|
||||||
} while( false )
|
} while( false )
|
||||||
|
|
||||||
@ -132,13 +132,13 @@
|
|||||||
if( catchAssertionHandler.allowThrows() ) \
|
if( catchAssertionHandler.allowThrows() ) \
|
||||||
try { \
|
try { \
|
||||||
static_cast<void>(__VA_ARGS__); \
|
static_cast<void>(__VA_ARGS__); \
|
||||||
catchAssertionHandler.handle( Catch::ResultWas::DidntThrowException ); \
|
catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \
|
||||||
} \
|
} \
|
||||||
catch( ... ) { \
|
catch( ... ) { \
|
||||||
Catch::handleExceptionMatchExpr( catchAssertionHandler, matcher, #matcher ); \
|
Catch::handleExceptionMatchExpr( catchAssertionHandler, matcher, #matcher ); \
|
||||||
} \
|
} \
|
||||||
else \
|
else \
|
||||||
catchAssertionHandler.handle( Catch::ResultWas::Ok ); \
|
catchAssertionHandler.handleThrowingCallSkipped(); \
|
||||||
INTERNAL_CATCH_REACT( catchAssertionHandler ) \
|
INTERNAL_CATCH_REACT( catchAssertionHandler ) \
|
||||||
} while( false )
|
} while( false )
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ namespace Catch {
|
|||||||
void handleExceptionMatchExpr( AssertionHandler& handler, StringMatcher const& matcher, StringRef matcherString ) {
|
void handleExceptionMatchExpr( AssertionHandler& handler, StringMatcher const& matcher, StringRef matcherString ) {
|
||||||
std::string exceptionMessage = Catch::translateActiveException();
|
std::string exceptionMessage = Catch::translateActiveException();
|
||||||
MatchExpr<std::string, StringMatcher const&> expr( exceptionMessage, matcher, matcherString );
|
MatchExpr<std::string, StringMatcher const&> expr( exceptionMessage, matcher, matcherString );
|
||||||
handler.handle( expr );
|
handler.handleExpr( expr );
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Catch
|
} // namespace Catch
|
||||||
|
@ -60,7 +60,7 @@ namespace Catch {
|
|||||||
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 { \
|
INTERNAL_CATCH_TRY { \
|
||||||
catchAssertionHandler.handle( Catch::makeMatchExpr( arg, matcher, #matcher ) ); \
|
catchAssertionHandler.handleExpr( Catch::makeMatchExpr( arg, matcher, #matcher ) ); \
|
||||||
} INTERNAL_CATCH_CATCH( catchAssertionHandler ) \
|
} INTERNAL_CATCH_CATCH( catchAssertionHandler ) \
|
||||||
INTERNAL_CATCH_REACT( catchAssertionHandler ) \
|
INTERNAL_CATCH_REACT( catchAssertionHandler ) \
|
||||||
} while( false )
|
} while( false )
|
||||||
@ -73,16 +73,16 @@ namespace Catch {
|
|||||||
if( catchAssertionHandler.allowThrows() ) \
|
if( catchAssertionHandler.allowThrows() ) \
|
||||||
try { \
|
try { \
|
||||||
static_cast<void>(__VA_ARGS__ ); \
|
static_cast<void>(__VA_ARGS__ ); \
|
||||||
catchAssertionHandler.handle( Catch::ResultWas::DidntThrowException ); \
|
catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \
|
||||||
} \
|
} \
|
||||||
catch( exceptionType const& ex ) { \
|
catch( exceptionType const& ex ) { \
|
||||||
catchAssertionHandler.handle( Catch::makeMatchExpr( ex, matcher, #matcher ) ); \
|
catchAssertionHandler.handleExpr( Catch::makeMatchExpr( ex, matcher, #matcher ) ); \
|
||||||
} \
|
} \
|
||||||
catch( ... ) { \
|
catch( ... ) { \
|
||||||
catchAssertionHandler.useActiveException(); \
|
catchAssertionHandler.handleUnexpectedInflightException(); \
|
||||||
} \
|
} \
|
||||||
else \
|
else \
|
||||||
catchAssertionHandler.handle( Catch::ResultWas::Ok ); \
|
catchAssertionHandler.handleThrowingCallSkipped(); \
|
||||||
INTERNAL_CATCH_REACT( catchAssertionHandler ) \
|
INTERNAL_CATCH_REACT( catchAssertionHandler ) \
|
||||||
} while( false )
|
} while( false )
|
||||||
|
|
||||||
|
@ -302,7 +302,7 @@ namespace Catch {
|
|||||||
m_lastAssertionInfo.lineInfo,
|
m_lastAssertionInfo.lineInfo,
|
||||||
m_lastAssertionInfo.capturedExpression,
|
m_lastAssertionInfo.capturedExpression,
|
||||||
m_lastAssertionInfo.resultDisposition );
|
m_lastAssertionInfo.resultDisposition );
|
||||||
handler.useActiveException();
|
handler.handleUnexpectedInflightException();
|
||||||
handler.setCompleted();
|
handler.setCompleted();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user