Add UNSCOPED_CAPTURE

Closes #2954
Closes #3010
This commit is contained in:
Martin Hořeňovský committed 2026-01-11 14:53:08 +01:00
1 parent b59f4f3522
commit 2580eadc42
26 files changed
+265 -54

No files matched your search

@@ -299,6 +299,7 @@ Message from section two
:test-result: PASS Trim strings
:test-result: PASS Type conversions of RangeEquals and similar
:test-result: FAIL Unexpected exceptions can be translated
:test-result: FAIL Unscoped capture outlives scope
:test-result: PASS Upcasting special member functions
:test-result: PASS Usage of AllMatch range matcher
:test-result: PASS Usage of AllTrue range matcher
@@ -292,6 +292,7 @@
:test-result: PASS Trim strings
:test-result: PASS Type conversions of RangeEquals and similar
:test-result: FAIL Unexpected exceptions can be translated
:test-result: FAIL Unscoped capture outlives scope
:test-result: PASS Upcasting special member functions
:test-result: PASS Usage of AllMatch range matcher
:test-result: PASS Usage of AllTrue range matcher
@@ -2205,6 +2205,7 @@ MatchersRanges.tests.cpp:<line number>: passed: a, UnorderedRangeEquals( b ) for
MatchersRanges.tests.cpp:<line number>: passed: vector_a, RangeEquals( array_a_plus_1, close_enough ) for: { 1, 2, 3 } elements are { 2, 3, 4 }
MatchersRanges.tests.cpp:<line number>: passed: vector_a, UnorderedRangeEquals( array_a_plus_1, close_enough ) for: { 1, 2, 3 } unordered elements are { 2, 3, 4 }
Exception.tests.cpp:<line number>: failed: unexpected exception with message: '3.14000000000000012'
Message.tests.cpp:<line number>: failed: false with 3 messages: 'i := 1' and 'j := 2' and 'i + j := 3'
UniquePtr.tests.cpp:<line number>: passed: bptr->i == 3 for: 3 == 3
UniquePtr.tests.cpp:<line number>: passed: bptr->i == 3 for: 3 == 3
MatchersRanges.tests.cpp:<line number>: passed: data, AllMatch(SizeIs(5)) for: { { 0, 1, 2, 3, 5 }, { 4, -3, -2, 5, 0 }, { 0, 0, 0, 5, 0 }, { 0, -5, 0, 5, 0 }, { 1, 0, 0, -1, 5 } } all match has size == 5
@@ -2894,7 +2895,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: 436 | 317 passed | 95 failed | 6 skipped | 18 failed as expected
assertions: 2309 | 2110 passed | 157 failed | 42 failed as expected
test cases: 437 | 317 passed | 96 failed | 6 skipped | 18 failed as expected
assertions: 2311 | 2110 passed | 158 failed | 43 failed as expected
@@ -2198,6 +2198,7 @@ MatchersRanges.tests.cpp:<line number>: passed: a, UnorderedRangeEquals( b ) for
MatchersRanges.tests.cpp:<line number>: passed: vector_a, RangeEquals( array_a_plus_1, close_enough ) for: { 1, 2, 3 } elements are { 2, 3, 4 }
MatchersRanges.tests.cpp:<line number>: passed: vector_a, UnorderedRangeEquals( array_a_plus_1, close_enough ) for: { 1, 2, 3 } unordered elements are { 2, 3, 4 }
Exception.tests.cpp:<line number>: failed: unexpected exception with message: '3.14000000000000012'
Message.tests.cpp:<line number>: failed: false with 3 messages: 'i := 1' and 'j := 2' and 'i + j := 3'
UniquePtr.tests.cpp:<line number>: passed: bptr->i == 3 for: 3 == 3
UniquePtr.tests.cpp:<line number>: passed: bptr->i == 3 for: 3 == 3
MatchersRanges.tests.cpp:<line number>: passed: data, AllMatch(SizeIs(5)) for: { { 0, 1, 2, 3, 5 }, { 4, -3, -2, 5, 0 }, { 0, 0, 0, 5, 0 }, { 0, -5, 0, 5, 0 }, { 1, 0, 0, -1, 5 } } all match has size == 5
@@ -2883,7 +2884,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: 436 | 317 passed | 95 failed | 6 skipped | 18 failed as expected
assertions: 2309 | 2110 passed | 157 failed | 42 failed as expected
test cases: 437 | 317 passed | 96 failed | 6 skipped | 18 failed as expected
assertions: 2311 | 2110 passed | 158 failed | 43 failed as expected
@@ -1203,6 +1203,19 @@ Exception.tests.cpp:<line number>: FAILED:
due to unexpected exception with message:
3.14000000000000012
-------------------------------------------------------------------------------
Unscoped capture outlives scope
-------------------------------------------------------------------------------
Message.tests.cpp:<line number>
...............................................................................
Message.tests.cpp:<line number>: FAILED:
REQUIRE( false )
with messages:
i := 1
j := 2
i + j := 3
-------------------------------------------------------------------------------
Vector Approx matcher -- failing
Empty and non empty vectors are not approx equal
@@ -1730,6 +1743,6 @@ due to unexpected exception with message:
Why would you throw a std::string?
===============================================================================
test cases: 436 | 335 passed | 76 failed | 7 skipped | 18 failed as expected
assertions: 2288 | 2110 passed | 136 failed | 42 failed as expected
test cases: 437 | 335 passed | 76 failed | 7 skipped | 19 failed as expected
assertions: 2289 | 2110 passed | 136 failed | 43 failed as expected
@@ -14324,6 +14324,29 @@ Exception.tests.cpp:<line number>: FAILED:
due to unexpected exception with message:
3.14000000000000012
-------------------------------------------------------------------------------
Unscoped capture outlives scope
A
-------------------------------------------------------------------------------
Message.tests.cpp:<line number>
...............................................................................
No assertions in section 'A'
-------------------------------------------------------------------------------
Unscoped capture outlives scope
-------------------------------------------------------------------------------
Message.tests.cpp:<line number>
...............................................................................
Message.tests.cpp:<line number>: FAILED:
REQUIRE( false )
with messages:
i := 1
j := 2
i + j := 3
-------------------------------------------------------------------------------
Upcasting special member functions
Move constructor
@@ -19349,6 +19372,6 @@ Misc.tests.cpp:<line number>
Misc.tests.cpp:<line number>: PASSED:
===============================================================================
test cases: 436 | 317 passed | 95 failed | 6 skipped | 18 failed as expected
assertions: 2309 | 2110 passed | 157 failed | 42 failed as expected
test cases: 437 | 317 passed | 96 failed | 6 skipped | 18 failed as expected
assertions: 2311 | 2110 passed | 158 failed | 43 failed as expected
@@ -14317,6 +14317,29 @@ Exception.tests.cpp:<line number>: FAILED:
due to unexpected exception with message:
3.14000000000000012
-------------------------------------------------------------------------------
Unscoped capture outlives scope
A
-------------------------------------------------------------------------------
Message.tests.cpp:<line number>
...............................................................................
No assertions in section 'A'
-------------------------------------------------------------------------------
Unscoped capture outlives scope
-------------------------------------------------------------------------------
Message.tests.cpp:<line number>
...............................................................................
Message.tests.cpp:<line number>: FAILED:
REQUIRE( false )
with messages:
i := 1
j := 2
i + j := 3
-------------------------------------------------------------------------------
Upcasting special member functions
Move constructor
@@ -19338,6 +19361,6 @@ Misc.tests.cpp:<line number>
Misc.tests.cpp:<line number>: PASSED:
===============================================================================
test cases: 436 | 317 passed | 95 failed | 6 skipped | 18 failed as expected
assertions: 2309 | 2110 passed | 157 failed | 42 failed as expected
test cases: 437 | 317 passed | 96 failed | 6 skipped | 18 failed as expected
assertions: 2311 | 2110 passed | 158 failed | 43 failed as expected
+13 -1
View File
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuitesloose text artifact
>
<testsuite name="<exe-name>" errors="17" failures="140" skipped="12" tests="2321" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<testsuite name="<exe-name>" errors="17" failures="141" skipped="12" tests="2323" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<properties>
<property name="random-seed" value="1"/>
<property name="filters" value="&quot;*&quot; ~[!nonportable] ~[!benchmark] ~[approvals]"/>
@@ -1694,6 +1694,18 @@ FAILED:
at Exception.tests.cpp:<line number>
</error>
</testcase>
<testcase classname="<exe-name>.global" name="Unscoped capture outlives scope" time="{duration}" status="run">
<skipped message="TEST_CASE tagged with !mayfail"/>
<failure message="false" type="REQUIRE">
FAILED:
REQUIRE( false )
i := 1
j := 2
i + j := 3
at Message.tests.cpp:<line number>
</failure>
</testcase>
<testcase classname="<exe-name>.global" name="Unscoped capture outlives scope/A" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Upcasting special member functions" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Upcasting special member functions/Move constructor" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Upcasting special member functions/move assignment" time="{duration}" status="run"/>
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="<exe-name>" errors="17" failures="140" skipped="12" tests="2321" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<testsuite name="<exe-name>" errors="17" failures="141" skipped="12" tests="2323" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<properties>
<property name="random-seed" value="1"/>
<property name="filters" value="&quot;*&quot; ~[!nonportable] ~[!benchmark] ~[approvals]"/>
@@ -1693,6 +1693,18 @@ FAILED:
at Exception.tests.cpp:<line number>
</error>
</testcase>
<testcase classname="<exe-name>.global" name="Unscoped capture outlives scope" time="{duration}" status="run">
<skipped message="TEST_CASE tagged with !mayfail"/>
<failure message="false" type="REQUIRE">
FAILED:
REQUIRE( false )
i := 1
j := 2
i + j := 3
at Message.tests.cpp:<line number>
</failure>
</testcase>
<testcase classname="<exe-name>.global" name="Unscoped capture outlives scope/A" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Upcasting special member functions" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Upcasting special member functions/Move constructor" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Upcasting special member functions/move assignment" time="{duration}" status="run"/>
@@ -1833,6 +1833,17 @@ at Message.tests.cpp:<line number>
<testCase name="Standard output from all sections is reported/one" duration="{duration}"/>
<testCase name="Standard output from all sections is reported/two" duration="{duration}"/>
<testCase name="The NO_FAIL macro reports a failure but does not fail the test" duration="{duration}"/>
<testCase name="Unscoped capture outlives scope" duration="{duration}">
<skipped message="REQUIRE(false)">
FAILED:
REQUIRE( false )
i := 1
j := 2
i + j := 3
at Message.tests.cpp:<line number>
</skipped>
</testCase>
<testCase name="Unscoped capture outlives scope/A" duration="{duration}"/>
<testCase name="just failure" duration="{duration}">
<failure message="FAIL()">
FAILED:
@@ -1832,6 +1832,17 @@ at Message.tests.cpp:<line number>
<testCase name="Standard output from all sections is reported/one" duration="{duration}"/>
<testCase name="Standard output from all sections is reported/two" duration="{duration}"/>
<testCase name="The NO_FAIL macro reports a failure but does not fail the test" duration="{duration}"/>
<testCase name="Unscoped capture outlives scope" duration="{duration}">
<skipped message="REQUIRE(false)">
FAILED:
REQUIRE( false )
i := 1
j := 2
i + j := 3
at Message.tests.cpp:<line number>
</skipped>
</testCase>
<testCase name="Unscoped capture outlives scope/A" duration="{duration}"/>
<testCase name="just failure" duration="{duration}">
<failure message="FAIL()">
FAILED:
+3 -1
View File
@@ -3417,6 +3417,8 @@ ok {test-number} - vector_a, RangeEquals( array_a_plus_1, close_enough ) for: {
ok {test-number} - vector_a, UnorderedRangeEquals( array_a_plus_1, close_enough ) for: { 1, 2, 3 } unordered elements are { 2, 3, 4 }
# Unexpected exceptions can be translated
not ok {test-number} - unexpected exception with message: '3.14000000000000012'
# Unscoped capture outlives scope
not ok {test-number} - false with 3 messages: 'i := 1' and 'j := 2' and 'i + j := 3'
# Upcasting special member functions
ok {test-number} - bptr->i == 3 for: 3 == 3
# Upcasting special member functions
@@ -4639,5 +4641,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0
ok {test-number} -
# xmlentitycheck
ok {test-number} -
1..2321
1..2323
@@ -3410,6 +3410,8 @@ ok {test-number} - vector_a, RangeEquals( array_a_plus_1, close_enough ) for: {
ok {test-number} - vector_a, UnorderedRangeEquals( array_a_plus_1, close_enough ) for: { 1, 2, 3 } unordered elements are { 2, 3, 4 }
# Unexpected exceptions can be translated
not ok {test-number} - unexpected exception with message: '3.14000000000000012'
# Unscoped capture outlives scope
not ok {test-number} - false with 3 messages: 'i := 1' and 'j := 2' and 'i + j := 3'
# Upcasting special member functions
ok {test-number} - bptr->i == 3 for: 3 == 3
# Upcasting special member functions
@@ -4628,5 +4630,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0
ok {test-number} -
# xmlentitycheck
ok {test-number} -
1..2321
1..2323
@@ -727,6 +727,9 @@
##teamcity[testStarted name='Unexpected exceptions can be translated']
##teamcity[testFailed name='Unexpected exceptions can be translated' message='Exception.tests.cpp:<line number>|n...............................................................................|n|nException.tests.cpp:<line number>|nunexpected exception with message:|n "3.14000000000000012"']
##teamcity[testFinished name='Unexpected exceptions can be translated' duration="{duration}"]
##teamcity[testStarted name='Unscoped capture outlives scope']
##teamcity[testIgnored name='Unscoped capture outlives scope' message='Message.tests.cpp:<line number>|n...............................................................................|n|nMessage.tests.cpp:<line number>|nexpression failed with messages:|n "i := 1"|n "j := 2"|n "i + j := 3"|n REQUIRE( false )|nwith expansion:|n false|n- failure ignore as test marked as |'ok to fail|'|n']
##teamcity[testFinished name='Unscoped capture outlives scope' duration="{duration}"]
##teamcity[testStarted name='Upcasting special member functions']
##teamcity[testFinished name='Upcasting special member functions' duration="{duration}"]
##teamcity[testStarted name='Usage of AllMatch range matcher']
@@ -727,6 +727,9 @@
##teamcity[testStarted name='Unexpected exceptions can be translated']
##teamcity[testFailed name='Unexpected exceptions can be translated' message='Exception.tests.cpp:<line number>|n...............................................................................|n|nException.tests.cpp:<line number>|nunexpected exception with message:|n "3.14000000000000012"']
##teamcity[testFinished name='Unexpected exceptions can be translated' duration="{duration}"]
##teamcity[testStarted name='Unscoped capture outlives scope']
##teamcity[testIgnored name='Unscoped capture outlives scope' message='Message.tests.cpp:<line number>|n...............................................................................|n|nMessage.tests.cpp:<line number>|nexpression failed with messages:|n "i := 1"|n "j := 2"|n "i + j := 3"|n REQUIRE( false )|nwith expansion:|n false|n- failure ignore as test marked as |'ok to fail|'|n']
##teamcity[testFinished name='Unscoped capture outlives scope' duration="{duration}"]
##teamcity[testStarted name='Upcasting special member functions']
##teamcity[testFinished name='Upcasting special member functions' duration="{duration}"]
##teamcity[testStarted name='Usage of AllMatch range matcher']
+25 -2
View File
@@ -16561,6 +16561,29 @@ There is no extra whitespace here
</Exception>
<OverallResult success="false" skips="0"/>
</TestCase>
<TestCase name="Unscoped capture outlives scope" tags="[!shouldfail][capture][messages][unscoped]" filename="tests/<exe-name>/UsageTests/Message.tests.cpp" >
<Section name="A" filename="tests/<exe-name>/UsageTests/Message.tests.cpp" >
<OverallResults successes="0" failures="1" expectedFailures="0" skipped="false"/>
</Section>
<Info filename="tests/<exe-name>/UsageTests/Message.tests.cpp" >
i := 1
</Info>
<Info filename="tests/<exe-name>/UsageTests/Message.tests.cpp" >
j := 2
</Info>
<Info filename="tests/<exe-name>/UsageTests/Message.tests.cpp" >
i + j := 3
</Info>
<Expression success="false" type="REQUIRE" filename="tests/<exe-name>/UsageTests/Message.tests.cpp" >
<Original>
false
</Original>
<Expanded>
false
</Expanded>
</Expression>
<OverallResult success="false" skips="0"/>
</TestCase>
<TestCase name="Upcasting special member functions" tags="[internals][unique-ptr]" filename="tests/<exe-name>/IntrospectiveTests/UniquePtr.tests.cpp" >
<Section name="Move constructor" filename="tests/<exe-name>/IntrospectiveTests/UniquePtr.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/UniquePtr.tests.cpp" >
@@ -22393,6 +22416,6 @@ Approx( -1.95996398454005449 )
</Section>
<OverallResult success="true" skips="0"/>
</TestCase>
<OverallResults successes="2110" failures="157" expectedFailures="42" skips="12"/>
<OverallResultsCases successes="317" failures="95" expectedFailures="18" skips="6"/>
<OverallResults successes="2110" failures="158" expectedFailures="43" skips="12"/>
<OverallResultsCases successes="317" failures="96" expectedFailures="18" skips="6"/>
</Catch2TestRun>
@@ -16561,6 +16561,29 @@ There is no extra whitespace here
</Exception>
<OverallResult success="false" skips="0"/>
</TestCase>
<TestCase name="Unscoped capture outlives scope" tags="[!shouldfail][capture][messages][unscoped]" filename="tests/<exe-name>/UsageTests/Message.tests.cpp" >
<Section name="A" filename="tests/<exe-name>/UsageTests/Message.tests.cpp" >
<OverallResults successes="0" failures="1" expectedFailures="0" skipped="false"/>
</Section>
<Info filename="tests/<exe-name>/UsageTests/Message.tests.cpp" >
i := 1
</Info>
<Info filename="tests/<exe-name>/UsageTests/Message.tests.cpp" >
j := 2
</Info>
<Info filename="tests/<exe-name>/UsageTests/Message.tests.cpp" >
i + j := 3
</Info>
<Expression success="false" type="REQUIRE" filename="tests/<exe-name>/UsageTests/Message.tests.cpp" >
<Original>
false
</Original>
<Expanded>
false
</Expanded>
</Expression>
<OverallResult success="false" skips="0"/>
</TestCase>
<TestCase name="Upcasting special member functions" tags="[internals][unique-ptr]" filename="tests/<exe-name>/IntrospectiveTests/UniquePtr.tests.cpp" >
<Section name="Move constructor" filename="tests/<exe-name>/IntrospectiveTests/UniquePtr.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/UniquePtr.tests.cpp" >
@@ -22392,6 +22415,6 @@ Approx( -1.95996398454005449 )
</Section>
<OverallResult success="true" skips="0"/>
</TestCase>
<OverallResults successes="2110" failures="157" expectedFailures="42" skips="12"/>
<OverallResultsCases successes="317" failures="95" expectedFailures="18" skips="6"/>
<OverallResults successes="2110" failures="158" expectedFailures="43" skips="12"/>
<OverallResultsCases successes="317" failures="96" expectedFailures="18" skips="6"/>
</Catch2TestRun>
@@ -369,3 +369,13 @@ TEST_CASE(
UNSCOPED_INFO( "b" );
REQUIRE( false );
}
TEST_CASE( "Unscoped capture outlives scope",
"[messages][unscoped][capture][!shouldfail]" ) {
int i = 1;
SECTION( "A" ) {
int j = 2;
UNSCOPED_CAPTURE( i, j, i + j );
}
REQUIRE( false );
}