Only track the last line info in RunContext

There were only two places where we used the full `AssertionInfo`
instance in `m_lastAssertionInfo`:
1) when reporting unexpected exception from running a test case
2) when reporting fatal error

because in those two places we do not have access to a real
instance of `AssertionInfo`, but we still need to send one to the
reporters. As a bonus, in both of these places we were already
constructing a fake-ish assertion info, by using the last encountered
source location, but dummying out the other information.

Instead, we only keep track of the last encountered source location,
and construct the dummy `AssertionInfo` on-demand.

This finishes the set of refactoring around `m_lastAssertionInfo`
in `RunContext` and improves the performance of running assertions
by ~5% in both Debug and Release mode.

--------------

Note that this change also causes small difference in output. It
could be avoided by having an invalidation flag and tracking where
the information would be invalidated before, but the difference
includes more precise line location for unexpected errors (both
exceptions and fatals), so I prefer the new output.
This commit is contained in:
Martin Hořeňovský
2025-07-16 20:43:34 +02:00
parent 9be81c0e05
commit 0e8112a762
18 changed files with 156 additions and 75 deletions

View File

@@ -668,9 +668,17 @@ Nor would this
<OverallResult success="true" skips="0"/>
</TestCase>
<TestCase name="#2615 - Throwing in constructor generator fails test case but does not abort" tags="[!shouldfail][generators][regression]" filename="tests/<exe-name>/UsageTests/Generators.tests.cpp" >
<Exception filename="tests/<exe-name>/UsageTests/Generators.tests.cpp" >
failure to init
</Exception>
<Expression success="false" filename="tests/<exe-name>/UsageTests/Generators.tests.cpp" >
<Original>
{Unknown expression after the reported line}
</Original>
<Expanded>
{Unknown expression after the reported line}
</Expanded>
<Exception filename="tests/<exe-name>/UsageTests/Generators.tests.cpp" >
failure to init
</Exception>
</Expression>
<OverallResult success="true" skips="0"/>
</TestCase>
<TestCase name="#748 - captures with unexpected exceptions" tags="[!shouldfail][!throws][.][failing]" filename="tests/<exe-name>/UsageTests/Exception.tests.cpp" >
@@ -678,9 +686,17 @@ Nor would this
<Info filename="tests/<exe-name>/UsageTests/Exception.tests.cpp" >
answer := 42
</Info>
<Exception filename="tests/<exe-name>/UsageTests/Exception.tests.cpp" >
expected exception
</Exception>
<Expression success="false" filename="tests/<exe-name>/UsageTests/Exception.tests.cpp" >
<Original>
{Unknown expression after the reported line}
</Original>
<Expanded>
{Unknown expression after the reported line}
</Expanded>
<Exception filename="tests/<exe-name>/UsageTests/Exception.tests.cpp" >
expected exception
</Exception>
</Expression>
<OverallResults successes="0" failures="0" expectedFailures="1" skipped="false"/>
</Section>
<Section name="inside REQUIRE_NOTHROW" filename="tests/<exe-name>/UsageTests/Exception.tests.cpp" >
@@ -18349,9 +18365,17 @@ Approx( 1.23999999999999999 )
</TestCase>
<TestCase name="When unchecked exceptions are thrown from sections they are always failures" tags="[!throws][.][failing]" filename="tests/<exe-name>/UsageTests/Exception.tests.cpp" >
<Section name="section name" filename="tests/<exe-name>/UsageTests/Exception.tests.cpp" >
<Exception filename="tests/<exe-name>/UsageTests/Exception.tests.cpp" >
unexpected exception
</Exception>
<Expression success="false" filename="tests/<exe-name>/UsageTests/Exception.tests.cpp" >
<Original>
{Unknown expression after the reported line}
</Original>
<Expanded>
{Unknown expression after the reported line}
</Expanded>
<Exception filename="tests/<exe-name>/UsageTests/Exception.tests.cpp" >
unexpected exception
</Exception>
</Expression>
<OverallResults successes="0" failures="1" expectedFailures="0" skipped="false"/>
</Section>
<OverallResult success="false" skips="0"/>