Move AssertionResult when passing it inside RunContext

This commit is contained in:
Martin Hořeňovský 2023-05-06 21:45:39 +02:00
parent c57b5cdf43
commit 8ca504cbc9
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
2 changed files with 16 additions and 13 deletions

View File

@ -267,7 +267,7 @@ namespace Catch {
} }
void RunContext::assertionEnded(AssertionResult const & result) { void RunContext::assertionEnded(AssertionResult&& result) {
if (result.getResultType() == ResultWas::Ok) { if (result.getResultType() == ResultWas::Ok) {
m_totals.assertions.passed++; m_totals.assertions.passed++;
m_lastAssertionPassed = true; m_lastAssertionPassed = true;
@ -289,12 +289,13 @@ namespace Catch {
m_reporter->assertionEnded(AssertionStats(result, m_messages, m_totals)); m_reporter->assertionEnded(AssertionStats(result, m_messages, m_totals));
if (result.getResultType() != ResultWas::Warning) if ( result.getResultType() != ResultWas::Warning ) {
m_messageScopes.clear(); m_messageScopes.clear();
}
// Reset working state // Reset working state
resetAssertionInfo(); resetAssertionInfo();
m_lastResult = result; m_lastResult = CATCH_MOVE( result );
} }
void RunContext::resetAssertionInfo() { void RunContext::resetAssertionInfo() {
m_lastAssertionInfo.macroName = StringRef(); m_lastAssertionInfo.macroName = StringRef();
@ -445,7 +446,7 @@ namespace Catch {
tempResult.message = static_cast<std::string>(message); tempResult.message = static_cast<std::string>(message);
AssertionResult result(m_lastAssertionInfo, CATCH_MOVE(tempResult)); AssertionResult result(m_lastAssertionInfo, CATCH_MOVE(tempResult));
assertionEnded(result); assertionEnded(CATCH_MOVE(result) );
handleUnfinishedSections(); handleUnfinishedSections();
@ -595,7 +596,7 @@ namespace Catch {
AssertionResult assertionResult{ info, CATCH_MOVE( data ) }; AssertionResult assertionResult{ info, CATCH_MOVE( data ) };
assertionResult.m_resultData.lazyExpression.m_transientExpression = expr; assertionResult.m_resultData.lazyExpression.m_transientExpression = expr;
assertionEnded( assertionResult ); assertionEnded( CATCH_MOVE(assertionResult) );
} }
void RunContext::handleMessage( void RunContext::handleMessage(
@ -610,8 +611,10 @@ namespace Catch {
data.message = static_cast<std::string>(message); data.message = static_cast<std::string>(message);
AssertionResult assertionResult{ m_lastAssertionInfo, AssertionResult assertionResult{ m_lastAssertionInfo,
CATCH_MOVE( data ) }; CATCH_MOVE( data ) };
assertionEnded( assertionResult );
if ( !assertionResult.isOk() ) { const auto isOk = assertionResult.isOk();
assertionEnded( CATCH_MOVE(assertionResult) );
if ( !isOk ) {
populateReaction( reaction ); populateReaction( reaction );
} else if ( resultType == ResultWas::ExplicitSkip ) { } else if ( resultType == ResultWas::ExplicitSkip ) {
// TODO: Need to handle this explicitly, as ExplicitSkip is // TODO: Need to handle this explicitly, as ExplicitSkip is
@ -636,7 +639,7 @@ namespace Catch {
AssertionResultData data( ResultWas::ThrewException, LazyExpression( false ) ); AssertionResultData data( ResultWas::ThrewException, LazyExpression( false ) );
data.message = CATCH_MOVE(message); data.message = CATCH_MOVE(message);
AssertionResult assertionResult{ info, CATCH_MOVE(data) }; AssertionResult assertionResult{ info, CATCH_MOVE(data) };
assertionEnded( assertionResult ); assertionEnded( CATCH_MOVE(assertionResult) );
populateReaction( reaction ); populateReaction( reaction );
} }
@ -654,7 +657,7 @@ namespace Catch {
AssertionResultData data( ResultWas::ThrewException, LazyExpression( false ) ); AssertionResultData data( ResultWas::ThrewException, LazyExpression( false ) );
data.message = "Exception translation was disabled by CATCH_CONFIG_FAST_COMPILE"s; data.message = "Exception translation was disabled by CATCH_CONFIG_FAST_COMPILE"s;
AssertionResult assertionResult{ info, CATCH_MOVE( data ) }; AssertionResult assertionResult{ info, CATCH_MOVE( data ) };
assertionEnded( assertionResult ); assertionEnded( CATCH_MOVE(assertionResult) );
} }
void RunContext::handleNonExpr( void RunContext::handleNonExpr(
AssertionInfo const &info, AssertionInfo const &info,
@ -665,10 +668,10 @@ namespace Catch {
AssertionResultData data( resultType, LazyExpression( false ) ); AssertionResultData data( resultType, LazyExpression( false ) );
AssertionResult assertionResult{ info, CATCH_MOVE( data ) }; AssertionResult assertionResult{ info, CATCH_MOVE( data ) };
assertionEnded( assertionResult );
if( !assertionResult.isOk() ) const auto isOk = assertionResult.isOk();
populateReaction( reaction ); assertionEnded( CATCH_MOVE(assertionResult) );
if ( !isOk ) { populateReaction( reaction ); }
} }

View File

@ -121,7 +121,7 @@ namespace Catch {
void resetAssertionInfo(); void resetAssertionInfo();
bool testForMissingAssertions( Counts& assertions ); bool testForMissingAssertions( Counts& assertions );
void assertionEnded( AssertionResult const& result ); void assertionEnded( AssertionResult&& result );
void reportExpr void reportExpr
( AssertionInfo const &info, ( AssertionInfo const &info,
ResultWas::OfType resultType, ResultWas::OfType resultType,