Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorrosstang2023-08-08 04:07:31 +0800
committerGitHub2023-08-07 22:07:31 +0200
commitcd60a0301cf8dd8da076166ad865f21325bc24fe (patch)
treed07e0216f4842d87fa19868e40f33fb542d88985 /src
parentb593be21160766291bfef7ccb8b1471a4a64abd9 (diff)
downloadcatch3-cd60a0301cf8dd8da076166ad865f21325bc24fe.tar.gz
Assert Info reset need to also reset result disposition to normal to handle uncaught exception correctly (#2723)
* AssertionEnd does not reset the assertion info yet. That is done after populateReaction. And reset assertion info would also reset the result disposition to normal, so that any uncaught exception would be reported as failure * Approving test output changes due to added unit tests * Unit tests to throw std::runtime_error instead of std::exception * Add a unit test to test incomplete assertion handler --------- Co-authored-by: Ross <ross.tang@gfo-x.com>
Diffstat (limited to 'src')
-rw-r--r--src/catch2/internal/catch_run_context.cpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/catch2/internal/catch_run_context.cpp b/src/catch2/internal/catch_run_context.cpp
index 6f15cfb1..e568100d 100644
--- a/src/catch2/internal/catch_run_context.cpp
+++ b/src/catch2/internal/catch_run_context.cpp
@@ -20,6 +20,7 @@
#include <catch2/internal/catch_output_redirect.hpp>
#include <catch2/internal/catch_assertion_handler.hpp>
#include <catch2/internal/catch_test_failure_exception.hpp>
+#include <catch2/internal/catch_result_type.hpp>
#include <cassert>
#include <algorithm>
@@ -293,13 +294,14 @@ namespace Catch {
m_messageScopes.clear();
}
- // Reset working state
- resetAssertionInfo();
+ // Reset working state. assertion info will be reset after
+ // populateReaction is run if it is needed
m_lastResult = CATCH_MOVE( result );
}
void RunContext::resetAssertionInfo() {
m_lastAssertionInfo.macroName = StringRef();
m_lastAssertionInfo.capturedExpression = "{Unknown expression after the reported line}"_sr;
+ m_lastAssertionInfo.resultDisposition = ResultDisposition::Normal;
}
void RunContext::notifyAssertionStarted( AssertionInfo const& info ) {
@@ -447,6 +449,7 @@ namespace Catch {
AssertionResult result(m_lastAssertionInfo, CATCH_MOVE(tempResult));
assertionEnded(CATCH_MOVE(result) );
+ resetAssertionInfo();
handleUnfinishedSections();
@@ -583,6 +586,7 @@ namespace Catch {
reportExpr(info, ResultWas::ExpressionFailed, &expr, negated );
populateReaction( reaction );
}
+ resetAssertionInfo();
}
void RunContext::reportExpr(
AssertionInfo const &info,
@@ -621,6 +625,7 @@ namespace Catch {
// considered "OK"
reaction.shouldSkip = true;
}
+ resetAssertionInfo();
}
void RunContext::handleUnexpectedExceptionNotThrown(
AssertionInfo const& info,
@@ -641,6 +646,7 @@ namespace Catch {
AssertionResult assertionResult{ info, CATCH_MOVE(data) };
assertionEnded( CATCH_MOVE(assertionResult) );
populateReaction( reaction );
+ resetAssertionInfo();
}
void RunContext::populateReaction( AssertionReaction& reaction ) {
@@ -658,6 +664,7 @@ namespace Catch {
data.message = "Exception translation was disabled by CATCH_CONFIG_FAST_COMPILE"s;
AssertionResult assertionResult{ info, CATCH_MOVE( data ) };
assertionEnded( CATCH_MOVE(assertionResult) );
+ resetAssertionInfo();
}
void RunContext::handleNonExpr(
AssertionInfo const &info,
@@ -672,6 +679,7 @@ namespace Catch {
const auto isOk = assertionResult.isOk();
assertionEnded( CATCH_MOVE(assertionResult) );
if ( !isOk ) { populateReaction( reaction ); }
+ resetAssertionInfo();
}