Skip to content

Commit 55b14e1

Browse files
committed
Update last seen line info in the assertionEnded fast path
This costs us about 1% perf in Debug build and 3% in Release build, but it is worth it for more precise information during unexpected exceptions or fatal errors. Given a simple test case like this ```cpp TEST_CASE("Hard fail") { REQUIRE( 1 == 1 ); REQUIRE( 2 == 2 ); throw 1; REQUIRE( 3 == 3 ); } ``` Catch2 before this change would report the line info from the `TEST_CASE` macro as the last seen expression before error. With this change, it will correctly report the line info from the `REQUIRE(2 == 2)` assertion as the last seen expression before error.
1 parent ce128f5 commit 55b14e1

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

src/catch2/internal/catch_run_context.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,8 @@ namespace Catch {
515515
return m_lastAssertionPassed;
516516
}
517517

518-
void RunContext::assertionPassed() {
518+
void RunContext::assertionPassedFastPath(SourceLineInfo lineInfo) {
519+
m_lastKnownLineInfo = lineInfo;
519520
m_lastAssertionPassed = true;
520521
++m_totals.assertions.passed;
521522
m_messageScopes.clear();
@@ -603,7 +604,8 @@ namespace Catch {
603604

604605
if( result ) {
605606
if (!m_includeSuccessfulResults) {
606-
assertionPassed();
607+
// Fast path if neither user nor reporter asked for passing assertions
608+
assertionPassedFastPath(info.lineInfo);
607609
}
608610
else {
609611
reportExpr(info, ResultWas::Ok, &expr, negated);

src/catch2/internal/catch_run_context.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ namespace Catch {
108108

109109
bool lastAssertionPassed() override;
110110

111-
void assertionPassed();
111+
void assertionPassedFastPath(SourceLineInfo lineInfo);
112112

113113
public:
114114
// !TBD We need to do this another way!

0 commit comments

Comments
 (0)