mirror of
https://github.com/catchorg/Catch2.git
synced 2025-11-13 18:09:33 +01: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:
@@ -83,7 +83,7 @@ Matchers.tests.cpp:<line number>: passed: smallest_non_zero, !WithinULP( -smalle
|
||||
Matchers.tests.cpp:<line number>: passed: smallest_non_zero, WithinULP( -smallest_non_zero, 2 ) for: 0.0f is within 2 ULPs of -1.40129846e-45f ([-4.20389539e-45, 1.40129846e-45])
|
||||
Matchers.tests.cpp:<line number>: passed: smallest_non_zero, !WithinULP( -smallest_non_zero, 1 ) for: 0.0f not is within 1 ULPs of -1.40129846e-45f ([-2.80259693e-45, -0.00000000e+00])
|
||||
Generators.tests.cpp:<line number>: failed: unexpected exception with message: 'failure to init'; expression was: {Unknown expression after the reported line}
|
||||
Exception.tests.cpp:<line number>: failed: unexpected exception with message: 'answer := 42'; expression was: {Unknown expression after the reported line} with 1 message: 'expected exception'
|
||||
Exception.tests.cpp:<line number>: failed: unexpected exception with message: 'expected exception'; expression was: {Unknown expression after the reported line}
|
||||
Exception.tests.cpp:<line number>: failed: unexpected exception with message: 'answer := 42'; expression was: thisThrows() with 1 message: 'expected exception'
|
||||
Exception.tests.cpp:<line number>: passed: thisThrows() with 1 message: 'answer := 42'
|
||||
Compilation.tests.cpp:<line number>: passed: 42 == f for: 42 == {?}
|
||||
@@ -361,6 +361,9 @@ Message.tests.cpp:<line number>: passed: with 7 messages: 'custom_index_op<int>{
|
||||
Message.tests.cpp:<line number>: passed: with 11 messages: '("comma, in string", "escaped, \", ") := "escaped, ", "' and '"single quote in string,'," := "single quote in string,',"' and '"some escapes, \\,\\\\" := "some escapes, \,\\"' and '"some, ), unmatched, } prenheses {[<" := "some, ), unmatched, } prenheses {[<"' and ''"' := '"'' and ''\'' := '''' and '',' := ','' and ''}' := '}'' and '')' := ')'' and ''(' := '('' and ''{' := '{''
|
||||
ToStringGeneral.tests.cpp:<line number>: passed: true with 1 message: 'i := 2'
|
||||
ToStringGeneral.tests.cpp:<line number>: passed: true with 1 message: '3'
|
||||
Message.tests.cpp:<line number>: failed: false with 1 message: 'a := 1'
|
||||
Message.tests.cpp:<line number>: passed: true with 1 message: 'a := 1'
|
||||
Message.tests.cpp:<line number>: failed: false with 1 message: 'a := 1'
|
||||
Details.tests.cpp:<line number>: passed: eq( "", "" ) for: true
|
||||
Details.tests.cpp:<line number>: passed: !(eq( "", "a" )) for: !false
|
||||
Details.tests.cpp:<line number>: passed: eq( "a", "a" ) for: true
|
||||
@@ -1730,6 +1733,11 @@ BDD.tests.cpp:<line number>: passed: v.capacity() >= 10 for: 10 >= 10
|
||||
BDD.tests.cpp:<line number>: passed: v.size() == 0 for: 0 == 0
|
||||
BDD.tests.cpp:<line number>: passed: v.capacity() >= 10 for: 10 >= 10
|
||||
BDD.tests.cpp:<line number>: passed: v.size() == 0 for: 0 == 0
|
||||
Message.tests.cpp:<line number>: failed: false with 1 message: 'This will be reported multiple times'
|
||||
Message.tests.cpp:<line number>: failed: false with 1 message: 'This will be reported multiple times'
|
||||
Message.tests.cpp:<line number>: failed: false with 1 message: 'Should be in scope at the end'
|
||||
Message.tests.cpp:<line number>: passed: true with 1 message: 'Should survive a section end'
|
||||
Message.tests.cpp:<line number>: failed: false with 1 message: 'Should survive a section end'
|
||||
Approx.tests.cpp:<line number>: passed: d == Approx( 1.23 ) for: 1.22999999999999998
|
||||
==
|
||||
Approx( 1.22999999999999998 )
|
||||
@@ -2843,7 +2851,7 @@ InternalBenchmark.tests.cpp:<line number>: passed: med == 18. for: 18.0 == 18.0
|
||||
InternalBenchmark.tests.cpp:<line number>: passed: q3 == 23. for: 23.0 == 23.0
|
||||
Misc.tests.cpp:<line number>: passed:
|
||||
Misc.tests.cpp:<line number>: passed:
|
||||
test cases: 423 | 313 passed | 90 failed | 6 skipped | 14 failed as expected
|
||||
assertions: 2273 | 2087 passed | 151 failed | 35 failed as expected
|
||||
test cases: 428 | 313 passed | 95 failed | 6 skipped | 14 failed as expected
|
||||
assertions: 2281 | 2089 passed | 157 failed | 35 failed as expected
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user