mirror of
https://github.com/catchorg/Catch2.git
synced 2025-08-02 13:25:41 +02:00
Regularize scoped message lifetime to only consider the object's scope
This means that: 1) Scoped messages are always removed at the end of their scope, even if the scope ended due to an exception. 2) Scoped messages outlive section end, if that section's scope is enclosed in their own. Previously neither of these were true, which has led to a number of surprising behaviour, where e.g. this: ```cpp TEST_CASE() { try { INFO( "some info" ); throw std::runtime_error( "ex" ); } catch (std::exception const&) {} REQUIRE( false ); } ``` would print "some info" as the message for the assertion, while this: ```cpp TEST_CASE() { INFO("Hello"); SECTION("dummy") {} REQUIRE(false); } ``` would not print out "Hello" as the message for the assertion. This had an underlying reason, in that it was trying to helpfully keep the messages around in case of unexpected exceptions, so that code like this: ```cpp TEST_CASE() { auto [input, expected] = GENERATE(...); CAPTURE(input); auto result = transform(input); // throws REQUIRE(result == expected); } ``` would report the value of `input` when `transform` throws. However, it was surprising in practice and was causing various issues around handling of messages in other cases. Closes #1759 Closes #2019 Closes #2959
This commit is contained in:
@@ -167,7 +167,7 @@ ok {test-number} - smallest_non_zero, !WithinULP( -smallest_non_zero, 1 ) for: 0
|
||||
# #2615 - Throwing in constructor generator fails test case but does not abort
|
||||
not ok {test-number} - unexpected exception with message: 'failure to init'; expression was: {Unknown expression after the reported line}
|
||||
# #748 - captures with unexpected exceptions
|
||||
not ok {test-number} - unexpected exception with message: 'answer := 42'; expression was: {Unknown expression after the reported line} with 1 message: 'expected exception'
|
||||
not ok {test-number} - unexpected exception with message: 'expected exception'; expression was: {Unknown expression after the reported line}
|
||||
# #748 - captures with unexpected exceptions
|
||||
not ok {test-number} - unexpected exception with message: 'answer := 42'; expression was: thisThrows() with 1 message: 'expected exception'
|
||||
# #748 - captures with unexpected exceptions
|
||||
@@ -674,6 +674,12 @@ ok {test-number} - with 11 messages: '("comma, in string", "escaped, \", ") := "
|
||||
ok {test-number} - true with 1 message: 'i := 2'
|
||||
# Capture and info messages
|
||||
ok {test-number} - true with 1 message: '3'
|
||||
# Captures do not leave block with an exception
|
||||
not ok {test-number} - false with 1 message: 'a := 1'
|
||||
# Captures outlive section end
|
||||
ok {test-number} - true with 1 message: 'a := 1'
|
||||
# Captures outlive section end
|
||||
not ok {test-number} - false with 1 message: 'a := 1'
|
||||
# CaseInsensitiveEqualsTo is case insensitive
|
||||
ok {test-number} - eq( "", "" ) for: true
|
||||
# CaseInsensitiveEqualsTo is case insensitive
|
||||
@@ -2616,6 +2622,16 @@ ok {test-number} - v.size() == 0 for: 0 == 0
|
||||
ok {test-number} - v.capacity() >= 10 for: 10 >= 10
|
||||
# Scenario: Vector resizing affects size and capacity
|
||||
ok {test-number} - v.size() == 0 for: 0 == 0
|
||||
# Scoped message applies to all assertions in scope
|
||||
not ok {test-number} - false with 1 message: 'This will be reported multiple times'
|
||||
# Scoped message applies to all assertions in scope
|
||||
not ok {test-number} - false with 1 message: 'This will be reported multiple times'
|
||||
# Scoped messages do not leave block with an exception
|
||||
not ok {test-number} - false with 1 message: 'Should be in scope at the end'
|
||||
# Scoped messages outlive section end
|
||||
ok {test-number} - true with 1 message: 'Should survive a section end'
|
||||
# Scoped messages outlive section end
|
||||
not ok {test-number} - false with 1 message: 'Should survive a section end'
|
||||
A string sent directly to stdout
|
||||
A string sent directly to stderr
|
||||
A string sent to stderr via clog
|
||||
@@ -4567,5 +4583,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0
|
||||
ok {test-number} -
|
||||
# xmlentitycheck
|
||||
ok {test-number} -
|
||||
1..2285
|
||||
1..2293
|
||||
|
||||
|
Reference in New Issue
Block a user