mirror of
				https://github.com/catchorg/Catch2.git
				synced 2025-10-31 12:17:11 +01:00 
			
		
		
		
	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.
			
			
This commit is contained in:
		| @@ -515,7 +515,8 @@ namespace Catch { | ||||
|          return m_lastAssertionPassed; | ||||
|     } | ||||
|  | ||||
|     void RunContext::assertionPassed() { | ||||
|     void RunContext::assertionPassedFastPath(SourceLineInfo lineInfo) { | ||||
|         m_lastKnownLineInfo = lineInfo; | ||||
|         m_lastAssertionPassed = true; | ||||
|         ++m_totals.assertions.passed; | ||||
|         m_messageScopes.clear(); | ||||
| @@ -603,7 +604,8 @@ namespace Catch { | ||||
|  | ||||
|         if( result ) { | ||||
|             if (!m_includeSuccessfulResults) { | ||||
|                 assertionPassed(); | ||||
|                 // Fast path if neither user nor reporter asked for passing assertions | ||||
|                 assertionPassedFastPath(info.lineInfo); | ||||
|             } | ||||
|             else { | ||||
|                 reportExpr(info, ResultWas::Ok, &expr, negated); | ||||
|   | ||||
| @@ -108,7 +108,7 @@ namespace Catch { | ||||
|  | ||||
|         bool lastAssertionPassed() override; | ||||
|  | ||||
|         void assertionPassed(); | ||||
|         void assertionPassedFastPath(SourceLineInfo lineInfo); | ||||
|  | ||||
|     public: | ||||
|         // !TBD We need to do this another way! | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Martin Hořeňovský
					Martin Hořeňovský