mirror of
https://github.com/catchorg/Catch2.git
synced 2025-09-20 03:25:40 +02:00
Moved all AssertionHandler logic into RunContext and de-virtualised interface
This makes the assertion handling much less "chatty". AssertionHandler is now just a thin shim over RunContext
This commit is contained in:
@@ -40,7 +40,8 @@ namespace Catch {
|
||||
m_context(getCurrentMutableContext()),
|
||||
m_config(_config),
|
||||
m_reporter(std::move(reporter)),
|
||||
m_lastAssertionInfo{ "", SourceLineInfo("",0), "", ResultDisposition::Normal }
|
||||
m_lastAssertionInfo{ "", SourceLineInfo("",0), "", ResultDisposition::Normal },
|
||||
m_includeSuccessfulResults( m_config->includeSuccessfulResults() )
|
||||
{
|
||||
m_context.setRunner(this);
|
||||
m_context.setConfig(m_config);
|
||||
@@ -109,9 +110,6 @@ namespace Catch {
|
||||
return *m_reporter;
|
||||
}
|
||||
|
||||
void RunContext::assertionStarting(AssertionInfo const& info) {
|
||||
m_reporter->assertionStarting( info );
|
||||
}
|
||||
void RunContext::assertionEnded(AssertionResult const & result) {
|
||||
if (result.getResultType() == ResultWas::Ok) {
|
||||
m_totals.assertions.passed++;
|
||||
@@ -223,7 +221,7 @@ namespace Catch {
|
||||
tempResult.message = message;
|
||||
AssertionResult result(m_lastAssertionInfo, tempResult);
|
||||
|
||||
getResultCapture().assertionEnded(result);
|
||||
assertionEnded(result);
|
||||
|
||||
handleUnfinishedSections();
|
||||
|
||||
@@ -296,14 +294,9 @@ namespace Catch {
|
||||
} catch (...) {
|
||||
// Under CATCH_CONFIG_FAST_COMPILE, unexpected exceptions under REQUIRE assertions
|
||||
// are reported without translation at the point of origin.
|
||||
if (m_shouldReportUnexpected) {
|
||||
AssertionHandler handler
|
||||
( m_lastAssertionInfo.macroName,
|
||||
m_lastAssertionInfo.lineInfo,
|
||||
m_lastAssertionInfo.capturedExpression,
|
||||
m_lastAssertionInfo.resultDisposition );
|
||||
handler.handleUnexpectedInflightException();
|
||||
handler.setCompleted();
|
||||
if( m_shouldReportUnexpected ) {
|
||||
AssertionReaction dummyReaction;
|
||||
handleUnexpectedInflightException( m_lastAssertionInfo, translateActiveException(), dummyReaction );
|
||||
}
|
||||
}
|
||||
m_testCaseTracker->close();
|
||||
@@ -333,6 +326,119 @@ namespace Catch {
|
||||
m_unfinishedSections.clear();
|
||||
}
|
||||
|
||||
void RunContext::handleExpr(
|
||||
AssertionInfo const& info,
|
||||
ITransientExpression const& expr,
|
||||
AssertionReaction& reaction
|
||||
) {
|
||||
m_reporter->assertionStarting( info );
|
||||
assertionRun();
|
||||
|
||||
bool negated = isFalseTest( info.resultDisposition );
|
||||
bool result = expr.getResult() != negated;
|
||||
|
||||
if( result ) {
|
||||
if (!m_includeSuccessfulResults) {
|
||||
assertionRun();
|
||||
assertionPassed();
|
||||
}
|
||||
else {
|
||||
reportExpr(info, ResultWas::Ok, &expr, negated);
|
||||
}
|
||||
}
|
||||
else {
|
||||
reportExpr(info, ResultWas::ExpressionFailed, &expr, negated );
|
||||
populateReaction( reaction );
|
||||
}
|
||||
}
|
||||
void RunContext::reportExpr(
|
||||
AssertionInfo const &info,
|
||||
ResultWas::OfType resultType,
|
||||
ITransientExpression const *expr,
|
||||
bool negated ) {
|
||||
|
||||
m_lastAssertionInfo = info;
|
||||
AssertionResultData data( resultType, LazyExpression( negated ) );
|
||||
|
||||
AssertionResult assertionResult{ info, data };
|
||||
assertionResult.m_resultData.lazyExpression.m_transientExpression = expr;
|
||||
|
||||
assertionEnded( assertionResult );
|
||||
}
|
||||
|
||||
void RunContext::handleMessage(
|
||||
AssertionInfo const& info,
|
||||
ResultWas::OfType resultType,
|
||||
StringRef const &message,
|
||||
AssertionReaction& reaction
|
||||
) {
|
||||
m_reporter->assertionStarting( info );
|
||||
|
||||
m_lastAssertionInfo = info;
|
||||
assertionRun();
|
||||
|
||||
AssertionResultData data( resultType, LazyExpression( false ) );
|
||||
data.message = message;
|
||||
AssertionResult assertionResult{ m_lastAssertionInfo, data };
|
||||
assertionEnded( assertionResult );
|
||||
if( !assertionResult.isOk() )
|
||||
populateReaction( reaction );
|
||||
}
|
||||
void RunContext::handleUnexpectedExceptionNotThrown(
|
||||
AssertionInfo const& info,
|
||||
AssertionReaction& reaction
|
||||
) {
|
||||
handleNonExpr(info, Catch::ResultWas::DidntThrowException, reaction);
|
||||
}
|
||||
|
||||
void RunContext::handleUnexpectedInflightException(
|
||||
AssertionInfo const& info,
|
||||
std::string const& message,
|
||||
AssertionReaction& reaction
|
||||
) {
|
||||
m_lastAssertionInfo = info;
|
||||
assertionRun();
|
||||
|
||||
AssertionResultData data( ResultWas::ThrewException, LazyExpression( false ) );
|
||||
data.message = message;
|
||||
AssertionResult assertionResult{ info, data };
|
||||
assertionEnded( assertionResult );
|
||||
populateReaction( reaction );
|
||||
}
|
||||
|
||||
void RunContext::populateReaction( AssertionReaction& reaction ) {
|
||||
reaction.shouldDebugBreak = m_config->shouldDebugBreak();
|
||||
reaction.shouldThrow = aborting() || (m_lastAssertionInfo.resultDisposition & ResultDisposition::Normal);
|
||||
}
|
||||
|
||||
void RunContext::handleIncomplete(
|
||||
AssertionInfo const& info
|
||||
) {
|
||||
m_lastAssertionInfo = info;
|
||||
assertionRun();
|
||||
|
||||
AssertionResultData data( ResultWas::ThrewException, LazyExpression( false ) );
|
||||
data.message = "Exception translation was disabled by CATCH_CONFIG_FAST_COMPILE";
|
||||
AssertionResult assertionResult{ info, data };
|
||||
assertionEnded( assertionResult );
|
||||
}
|
||||
void RunContext::handleNonExpr(
|
||||
AssertionInfo const &info,
|
||||
ResultWas::OfType resultType,
|
||||
AssertionReaction &reaction
|
||||
) {
|
||||
m_lastAssertionInfo = info;
|
||||
assertionRun();
|
||||
|
||||
AssertionResultData data( resultType, LazyExpression( false ) );
|
||||
AssertionResult assertionResult{ info, data };
|
||||
assertionEnded( assertionResult );
|
||||
|
||||
if( !assertionResult.isOk() )
|
||||
populateReaction( reaction );
|
||||
}
|
||||
|
||||
|
||||
IResultCapture& getResultCapture() {
|
||||
if (auto* capture = getCurrentContext().getResultCapture())
|
||||
return *capture;
|
||||
|
Reference in New Issue
Block a user