TEST_CASE_PERSISTENT_FIXTURE: A new fixture macro for allowing persistent fixtures throughout a TEST_CASE (#2885)

This PR introduces a new `TEST_CASE` macro called `TEST_CASE_PERSISTENT_FIXTURE`. `TEST_CASE_PERSISTENT_FIXTURE` offers the same functionality as `TEST_CASE_METHOD` except for one difference. The object on which the test method is invoked is only created once for all invocations of the test case. The object is created just after the `testCaseStarting` event is broadcast and the object is destroyed just before the `testCaseEnding` event is broadcast.

The main motivation for this new functionality is to allow `TEST_CASE`s to do expensive setup and teardown once per `TEST_CASE`, without having to resort to abusing event listeners or static function variables with manual initialization.


Implements #1602

---------

Co-authored-by: Martin Hořeňovský <martin.horenovsky@gmail.com>
This commit is contained in:
Keith Stockdale
2024-08-05 16:01:41 +01:00
committed by GitHub
parent 33e24b14fc
commit f7cd0ba051
31 changed files with 643 additions and 62 deletions

View File

@@ -11,34 +11,28 @@
* and expressions in assertion macros are not run.
*/
#include <catch2/catch_test_macros.hpp>
#include <catch2/benchmark/catch_benchmark.hpp>
#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers.hpp>
#include <catch2/matchers/catch_matchers_predicate.hpp>
#include <iostream>
struct foo {
foo(){
REQUIRE_NOTHROW( print() );
}
void print() const {
std::cout << "This should not happen\n";
}
foo() { REQUIRE_NOTHROW( print() ); }
void print() const { std::cout << "This should not happen\n"; }
};
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wglobal-constructors"
#if defined( __clang__ )
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wglobal-constructors"
#endif
// Construct foo, but `foo::print` should not be run
static foo f;
#if defined(__clang__)
#if defined( __clang__ )
// The test is unused since the registration is disabled
#pragma clang diagnostic ignored "-Wunused-function"
# pragma clang diagnostic ignored "-Wunused-function"
#endif
// This test should not be run, because it won't be registered
@@ -60,6 +54,26 @@ TEST_CASE( "Disabled Macros" ) {
BENCHMARK( "Disabled benchmark" ) { REQUIRE( 1 == 2 ); };
}
#if defined(__clang__)
#pragma clang diagnostic pop
struct DisabledFixture {};
TEST_CASE_PERSISTENT_FIXTURE( DisabledFixture, "Disabled Persistent Fixture" ) {
CHECK( 1 == 2 );
REQUIRE( 1 == 2 );
std::cout << "This should not happen\n";
FAIL();
// Test that static assertions don't fire when macros are disabled
STATIC_CHECK( 0 == 1 );
STATIC_REQUIRE( !true );
CAPTURE( 1 );
CAPTURE( 1, "captured" );
REQUIRE_THAT( 1,
Catch::Matchers::Predicate( []( int ) { return false; } ) );
BENCHMARK( "Disabled benchmark" ) { REQUIRE( 1 == 2 ); };
}
#if defined( __clang__ )
# pragma clang diagnostic pop
#endif

View File

@@ -68,6 +68,8 @@ Nor would this
:test-result: PASS A TEMPLATE_TEST_CASE_METHOD_SIG based test run that succeeds - 6
:test-result: FAIL A TEST_CASE_METHOD based test run that fails
:test-result: PASS A TEST_CASE_METHOD based test run that succeeds
:test-result: FAIL A TEST_CASE_PERSISTENT_FIXTURE based test run that fails
:test-result: PASS A TEST_CASE_PERSISTENT_FIXTURE based test run that succeeds
:test-result: PASS A Template product test case - Foo<float>
:test-result: PASS A Template product test case - Foo<int>
:test-result: PASS A Template product test case - std::vector<float>

View File

@@ -66,6 +66,8 @@
:test-result: PASS A TEMPLATE_TEST_CASE_METHOD_SIG based test run that succeeds - 6
:test-result: FAIL A TEST_CASE_METHOD based test run that fails
:test-result: PASS A TEST_CASE_METHOD based test run that succeeds
:test-result: FAIL A TEST_CASE_PERSISTENT_FIXTURE based test run that fails
:test-result: PASS A TEST_CASE_PERSISTENT_FIXTURE based test run that succeeds
:test-result: PASS A Template product test case - Foo<float>
:test-result: PASS A Template product test case - Foo<int>
:test-result: PASS A Template product test case - std::vector<float>

View File

@@ -241,6 +241,10 @@ Class.tests.cpp:<line number>: passed: Nttp_Fixture<V>::value > 0 for: 3 > 0
Class.tests.cpp:<line number>: passed: Nttp_Fixture<V>::value > 0 for: 6 > 0
Class.tests.cpp:<line number>: failed: m_a == 2 for: 1 == 2
Class.tests.cpp:<line number>: passed: m_a == 1 for: 1 == 1
Class.tests.cpp:<line number>: passed: m_a++ == 0 for: 0 == 0
Class.tests.cpp:<line number>: failed: m_a == 0 for: 1 == 0
Class.tests.cpp:<line number>: passed: m_a++ == 0 for: 0 == 0
Class.tests.cpp:<line number>: passed: m_a == 1 for: 1 == 1
Misc.tests.cpp:<line number>: passed: x.size() == 0 for: 0 == 0
Misc.tests.cpp:<line number>: passed: x.size() == 0 for: 0 == 0
Misc.tests.cpp:<line number>: passed: x.size() == 0 for: 0 == 0
@@ -2840,7 +2844,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: 416 | 311 passed | 85 failed | 6 skipped | 14 failed as expected
assertions: 2255 | 2074 passed | 146 failed | 35 failed as expected
test cases: 418 | 312 passed | 86 failed | 6 skipped | 14 failed as expected
assertions: 2259 | 2077 passed | 147 failed | 35 failed as expected

View File

@@ -239,6 +239,10 @@ Class.tests.cpp:<line number>: passed: Nttp_Fixture<V>::value > 0 for: 3 > 0
Class.tests.cpp:<line number>: passed: Nttp_Fixture<V>::value > 0 for: 6 > 0
Class.tests.cpp:<line number>: failed: m_a == 2 for: 1 == 2
Class.tests.cpp:<line number>: passed: m_a == 1 for: 1 == 1
Class.tests.cpp:<line number>: passed: m_a++ == 0 for: 0 == 0
Class.tests.cpp:<line number>: failed: m_a == 0 for: 1 == 0
Class.tests.cpp:<line number>: passed: m_a++ == 0 for: 0 == 0
Class.tests.cpp:<line number>: passed: m_a == 1 for: 1 == 1
Misc.tests.cpp:<line number>: passed: x.size() == 0 for: 0 == 0
Misc.tests.cpp:<line number>: passed: x.size() == 0 for: 0 == 0
Misc.tests.cpp:<line number>: passed: x.size() == 0 for: 0 == 0
@@ -2829,7 +2833,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: 416 | 311 passed | 85 failed | 6 skipped | 14 failed as expected
assertions: 2255 | 2074 passed | 146 failed | 35 failed as expected
test cases: 418 | 312 passed | 86 failed | 6 skipped | 14 failed as expected
assertions: 2259 | 2077 passed | 147 failed | 35 failed as expected

View File

@@ -297,6 +297,18 @@ Class.tests.cpp:<line number>: FAILED:
with expansion:
1 == 2
-------------------------------------------------------------------------------
A TEST_CASE_PERSISTENT_FIXTURE based test run that fails
Second partial run
-------------------------------------------------------------------------------
Class.tests.cpp:<line number>
...............................................................................
Class.tests.cpp:<line number>: FAILED:
REQUIRE( m_a == 0 )
with expansion:
1 == 0
-------------------------------------------------------------------------------
A couple of nested sections followed by a failure
-------------------------------------------------------------------------------
@@ -1598,6 +1610,6 @@ due to unexpected exception with message:
Why would you throw a std::string?
===============================================================================
test cases: 416 | 325 passed | 70 failed | 7 skipped | 14 failed as expected
assertions: 2238 | 2074 passed | 129 failed | 35 failed as expected
test cases: 418 | 326 passed | 71 failed | 7 skipped | 14 failed as expected
assertions: 2242 | 2077 passed | 130 failed | 35 failed as expected

View File

@@ -2023,6 +2023,54 @@ A TEST_CASE_METHOD based test run that succeeds
Class.tests.cpp:<line number>
...............................................................................
Class.tests.cpp:<line number>: PASSED:
REQUIRE( m_a == 1 )
with expansion:
1 == 1
-------------------------------------------------------------------------------
A TEST_CASE_PERSISTENT_FIXTURE based test run that fails
First partial run
-------------------------------------------------------------------------------
Class.tests.cpp:<line number>
...............................................................................
Class.tests.cpp:<line number>: PASSED:
REQUIRE( m_a++ == 0 )
with expansion:
0 == 0
-------------------------------------------------------------------------------
A TEST_CASE_PERSISTENT_FIXTURE based test run that fails
Second partial run
-------------------------------------------------------------------------------
Class.tests.cpp:<line number>
...............................................................................
Class.tests.cpp:<line number>: FAILED:
REQUIRE( m_a == 0 )
with expansion:
1 == 0
-------------------------------------------------------------------------------
A TEST_CASE_PERSISTENT_FIXTURE based test run that succeeds
First partial run
-------------------------------------------------------------------------------
Class.tests.cpp:<line number>
...............................................................................
Class.tests.cpp:<line number>: PASSED:
REQUIRE( m_a++ == 0 )
with expansion:
0 == 0
-------------------------------------------------------------------------------
A TEST_CASE_PERSISTENT_FIXTURE based test run that succeeds
Second partial run
-------------------------------------------------------------------------------
Class.tests.cpp:<line number>
...............................................................................
Class.tests.cpp:<line number>: PASSED:
REQUIRE( m_a == 1 )
with expansion:
@@ -18894,6 +18942,6 @@ Misc.tests.cpp:<line number>
Misc.tests.cpp:<line number>: PASSED:
===============================================================================
test cases: 416 | 311 passed | 85 failed | 6 skipped | 14 failed as expected
assertions: 2255 | 2074 passed | 146 failed | 35 failed as expected
test cases: 418 | 312 passed | 86 failed | 6 skipped | 14 failed as expected
assertions: 2259 | 2077 passed | 147 failed | 35 failed as expected

View File

@@ -2021,6 +2021,54 @@ A TEST_CASE_METHOD based test run that succeeds
Class.tests.cpp:<line number>
...............................................................................
Class.tests.cpp:<line number>: PASSED:
REQUIRE( m_a == 1 )
with expansion:
1 == 1
-------------------------------------------------------------------------------
A TEST_CASE_PERSISTENT_FIXTURE based test run that fails
First partial run
-------------------------------------------------------------------------------
Class.tests.cpp:<line number>
...............................................................................
Class.tests.cpp:<line number>: PASSED:
REQUIRE( m_a++ == 0 )
with expansion:
0 == 0
-------------------------------------------------------------------------------
A TEST_CASE_PERSISTENT_FIXTURE based test run that fails
Second partial run
-------------------------------------------------------------------------------
Class.tests.cpp:<line number>
...............................................................................
Class.tests.cpp:<line number>: FAILED:
REQUIRE( m_a == 0 )
with expansion:
1 == 0
-------------------------------------------------------------------------------
A TEST_CASE_PERSISTENT_FIXTURE based test run that succeeds
First partial run
-------------------------------------------------------------------------------
Class.tests.cpp:<line number>
...............................................................................
Class.tests.cpp:<line number>: PASSED:
REQUIRE( m_a++ == 0 )
with expansion:
0 == 0
-------------------------------------------------------------------------------
A TEST_CASE_PERSISTENT_FIXTURE based test run that succeeds
Second partial run
-------------------------------------------------------------------------------
Class.tests.cpp:<line number>
...............................................................................
Class.tests.cpp:<line number>: PASSED:
REQUIRE( m_a == 1 )
with expansion:
@@ -18883,6 +18931,6 @@ Misc.tests.cpp:<line number>
Misc.tests.cpp:<line number>: PASSED:
===============================================================================
test cases: 416 | 311 passed | 85 failed | 6 skipped | 14 failed as expected
assertions: 2255 | 2074 passed | 146 failed | 35 failed as expected
test cases: 418 | 312 passed | 86 failed | 6 skipped | 14 failed as expected
assertions: 2259 | 2077 passed | 147 failed | 35 failed as expected

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuitesloose text artifact
>
<testsuite name="<exe-name>" errors="17" failures="129" skipped="12" tests="2267" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<testsuite name="<exe-name>" errors="17" failures="130" skipped="12" tests="2271" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<properties>
<property name="random-seed" value="1"/>
<property name="filters" value="&quot;*&quot; ~[!nonportable] ~[!benchmark] ~[approvals]"/>
@@ -313,6 +313,18 @@ at Class.tests.cpp:<line number>
</failure>
</testcase>
<testcase classname="<exe-name>.Fixture" name="A TEST_CASE_METHOD based test run that succeeds" time="{duration}" status="run"/>
<testcase classname="<exe-name>.Persistent_Fixture" name="A TEST_CASE_PERSISTENT_FIXTURE based test run that fails/First partial run" time="{duration}" status="run"/>
<testcase classname="<exe-name>.Persistent_Fixture" name="A TEST_CASE_PERSISTENT_FIXTURE based test run that fails/Second partial run" time="{duration}" status="run">
<failure message="m_a == 0" type="REQUIRE">
FAILED:
REQUIRE( m_a == 0 )
with expansion:
1 == 0
at Class.tests.cpp:<line number>
</failure>
</testcase>
<testcase classname="<exe-name>.Persistent_Fixture" name="A TEST_CASE_PERSISTENT_FIXTURE based test run that succeeds/First partial run" time="{duration}" status="run"/>
<testcase classname="<exe-name>.Persistent_Fixture" name="A TEST_CASE_PERSISTENT_FIXTURE based test run that succeeds/Second partial run" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="A Template product test case - Foo&lt;float>" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="A Template product test case - Foo&lt;int>" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="A Template product test case - std::vector&lt;float>" time="{duration}" status="run"/>

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="<exe-name>" errors="17" failures="129" skipped="12" tests="2267" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<testsuite name="<exe-name>" errors="17" failures="130" skipped="12" tests="2271" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<properties>
<property name="random-seed" value="1"/>
<property name="filters" value="&quot;*&quot; ~[!nonportable] ~[!benchmark] ~[approvals]"/>
@@ -312,6 +312,18 @@ at Class.tests.cpp:<line number>
</failure>
</testcase>
<testcase classname="<exe-name>.Fixture" name="A TEST_CASE_METHOD based test run that succeeds" time="{duration}" status="run"/>
<testcase classname="<exe-name>.Persistent_Fixture" name="A TEST_CASE_PERSISTENT_FIXTURE based test run that fails/First partial run" time="{duration}" status="run"/>
<testcase classname="<exe-name>.Persistent_Fixture" name="A TEST_CASE_PERSISTENT_FIXTURE based test run that fails/Second partial run" time="{duration}" status="run">
<failure message="m_a == 0" type="REQUIRE">
FAILED:
REQUIRE( m_a == 0 )
with expansion:
1 == 0
at Class.tests.cpp:<line number>
</failure>
</testcase>
<testcase classname="<exe-name>.Persistent_Fixture" name="A TEST_CASE_PERSISTENT_FIXTURE based test run that succeeds/First partial run" time="{duration}" status="run"/>
<testcase classname="<exe-name>.Persistent_Fixture" name="A TEST_CASE_PERSISTENT_FIXTURE based test run that succeeds/Second partial run" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="A Template product test case - Foo&lt;float>" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="A Template product test case - Foo&lt;int>" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="A Template product test case - std::vector&lt;float>" time="{duration}" status="run"/>

View File

@@ -519,6 +519,18 @@ at Class.tests.cpp:<line number>
</failure>
</testCase>
<testCase name="A TEST_CASE_METHOD based test run that succeeds" duration="{duration}"/>
<testCase name="A TEST_CASE_PERSISTENT_FIXTURE based test run that fails/First partial run" duration="{duration}"/>
<testCase name="A TEST_CASE_PERSISTENT_FIXTURE based test run that fails/Second partial run" duration="{duration}">
<failure message="REQUIRE(m_a == 0)">
FAILED:
REQUIRE( m_a == 0 )
with expansion:
1 == 0
at Class.tests.cpp:<line number>
</failure>
</testCase>
<testCase name="A TEST_CASE_PERSISTENT_FIXTURE based test run that succeeds/First partial run" duration="{duration}"/>
<testCase name="A TEST_CASE_PERSISTENT_FIXTURE based test run that succeeds/Second partial run" duration="{duration}"/>
<testCase name="Template test case method with test types specified inside std::tuple - MyTypes - 0" duration="{duration}"/>
<testCase name="Template test case method with test types specified inside std::tuple - MyTypes - 1" duration="{duration}"/>
<testCase name="Template test case method with test types specified inside std::tuple - MyTypes - 2" duration="{duration}"/>

View File

@@ -518,6 +518,18 @@ at Class.tests.cpp:<line number>
</failure>
</testCase>
<testCase name="A TEST_CASE_METHOD based test run that succeeds" duration="{duration}"/>
<testCase name="A TEST_CASE_PERSISTENT_FIXTURE based test run that fails/First partial run" duration="{duration}"/>
<testCase name="A TEST_CASE_PERSISTENT_FIXTURE based test run that fails/Second partial run" duration="{duration}">
<failure message="REQUIRE(m_a == 0)">
FAILED:
REQUIRE( m_a == 0 )
with expansion:
1 == 0
at Class.tests.cpp:<line number>
</failure>
</testCase>
<testCase name="A TEST_CASE_PERSISTENT_FIXTURE based test run that succeeds/First partial run" duration="{duration}"/>
<testCase name="A TEST_CASE_PERSISTENT_FIXTURE based test run that succeeds/Second partial run" duration="{duration}"/>
<testCase name="Template test case method with test types specified inside std::tuple - MyTypes - 0" duration="{duration}"/>
<testCase name="Template test case method with test types specified inside std::tuple - MyTypes - 1" duration="{duration}"/>
<testCase name="Template test case method with test types specified inside std::tuple - MyTypes - 2" duration="{duration}"/>

View File

@@ -478,6 +478,14 @@ ok {test-number} - Nttp_Fixture<V>::value > 0 for: 6 > 0
not ok {test-number} - m_a == 2 for: 1 == 2
# A TEST_CASE_METHOD based test run that succeeds
ok {test-number} - m_a == 1 for: 1 == 1
# A TEST_CASE_PERSISTENT_FIXTURE based test run that fails
ok {test-number} - m_a++ == 0 for: 0 == 0
# A TEST_CASE_PERSISTENT_FIXTURE based test run that fails
not ok {test-number} - m_a == 0 for: 1 == 0
# A TEST_CASE_PERSISTENT_FIXTURE based test run that succeeds
ok {test-number} - m_a++ == 0 for: 0 == 0
# A TEST_CASE_PERSISTENT_FIXTURE based test run that succeeds
ok {test-number} - m_a == 1 for: 1 == 1
# A Template product test case - Foo<float>
ok {test-number} - x.size() == 0 for: 0 == 0
# A Template product test case - Foo<int>
@@ -4539,5 +4547,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0
ok {test-number} -
# xmlentitycheck
ok {test-number} -
1..2267
1..2271

View File

@@ -476,6 +476,14 @@ ok {test-number} - Nttp_Fixture<V>::value > 0 for: 6 > 0
not ok {test-number} - m_a == 2 for: 1 == 2
# A TEST_CASE_METHOD based test run that succeeds
ok {test-number} - m_a == 1 for: 1 == 1
# A TEST_CASE_PERSISTENT_FIXTURE based test run that fails
ok {test-number} - m_a++ == 0 for: 0 == 0
# A TEST_CASE_PERSISTENT_FIXTURE based test run that fails
not ok {test-number} - m_a == 0 for: 1 == 0
# A TEST_CASE_PERSISTENT_FIXTURE based test run that succeeds
ok {test-number} - m_a++ == 0 for: 0 == 0
# A TEST_CASE_PERSISTENT_FIXTURE based test run that succeeds
ok {test-number} - m_a == 1 for: 1 == 1
# A Template product test case - Foo<float>
ok {test-number} - x.size() == 0 for: 0 == 0
# A Template product test case - Foo<int>
@@ -4528,5 +4536,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0
ok {test-number} -
# xmlentitycheck
ok {test-number} -
1..2267
1..2271

View File

@@ -166,6 +166,11 @@
##teamcity[testFinished name='A TEST_CASE_METHOD based test run that fails' duration="{duration}"]
##teamcity[testStarted name='A TEST_CASE_METHOD based test run that succeeds']
##teamcity[testFinished name='A TEST_CASE_METHOD based test run that succeeds' duration="{duration}"]
##teamcity[testStarted name='A TEST_CASE_PERSISTENT_FIXTURE based test run that fails']
##teamcity[testFailed name='A TEST_CASE_PERSISTENT_FIXTURE based test run that fails' message='-------------------------------------------------------------------------------|nSecond partial run|n-------------------------------------------------------------------------------|nClass.tests.cpp:<line number>|n...............................................................................|n|nClass.tests.cpp:<line number>|nexpression failed|n REQUIRE( m_a == 0 )|nwith expansion:|n 1 == 0|n']
##teamcity[testFinished name='A TEST_CASE_PERSISTENT_FIXTURE based test run that fails' duration="{duration}"]
##teamcity[testStarted name='A TEST_CASE_PERSISTENT_FIXTURE based test run that succeeds']
##teamcity[testFinished name='A TEST_CASE_PERSISTENT_FIXTURE based test run that succeeds' duration="{duration}"]
##teamcity[testStarted name='A Template product test case - Foo<float>']
##teamcity[testFinished name='A Template product test case - Foo<float>' duration="{duration}"]
##teamcity[testStarted name='A Template product test case - Foo<int>']

View File

@@ -166,6 +166,11 @@
##teamcity[testFinished name='A TEST_CASE_METHOD based test run that fails' duration="{duration}"]
##teamcity[testStarted name='A TEST_CASE_METHOD based test run that succeeds']
##teamcity[testFinished name='A TEST_CASE_METHOD based test run that succeeds' duration="{duration}"]
##teamcity[testStarted name='A TEST_CASE_PERSISTENT_FIXTURE based test run that fails']
##teamcity[testFailed name='A TEST_CASE_PERSISTENT_FIXTURE based test run that fails' message='-------------------------------------------------------------------------------|nSecond partial run|n-------------------------------------------------------------------------------|nClass.tests.cpp:<line number>|n...............................................................................|n|nClass.tests.cpp:<line number>|nexpression failed|n REQUIRE( m_a == 0 )|nwith expansion:|n 1 == 0|n']
##teamcity[testFinished name='A TEST_CASE_PERSISTENT_FIXTURE based test run that fails' duration="{duration}"]
##teamcity[testStarted name='A TEST_CASE_PERSISTENT_FIXTURE based test run that succeeds']
##teamcity[testFinished name='A TEST_CASE_PERSISTENT_FIXTURE based test run that succeeds' duration="{duration}"]
##teamcity[testStarted name='A Template product test case - Foo<float>']
##teamcity[testFinished name='A Template product test case - Foo<float>' duration="{duration}"]
##teamcity[testStarted name='A Template product test case - Foo<int>']

View File

@@ -2056,6 +2056,56 @@ Nor would this
</Expression>
<OverallResult success="true" skips="0"/>
</TestCase>
<TestCase name="A TEST_CASE_PERSISTENT_FIXTURE based test run that fails" tags="[.][class][failing]" filename="tests/<exe-name>/UsageTests/Class.tests.cpp" >
<Section name="First partial run" filename="tests/<exe-name>/UsageTests/Class.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/UsageTests/Class.tests.cpp" >
<Original>
m_a++ == 0
</Original>
<Expanded>
0 == 0
</Expanded>
</Expression>
<OverallResults successes="1" failures="0" expectedFailures="0" skipped="false"/>
</Section>
<Section name="Second partial run" filename="tests/<exe-name>/UsageTests/Class.tests.cpp" >
<Expression success="false" type="REQUIRE" filename="tests/<exe-name>/UsageTests/Class.tests.cpp" >
<Original>
m_a == 0
</Original>
<Expanded>
1 == 0
</Expanded>
</Expression>
<OverallResults successes="0" failures="1" expectedFailures="0" skipped="false"/>
</Section>
<OverallResult success="false" skips="0"/>
</TestCase>
<TestCase name="A TEST_CASE_PERSISTENT_FIXTURE based test run that succeeds" tags="[class]" filename="tests/<exe-name>/UsageTests/Class.tests.cpp" >
<Section name="First partial run" filename="tests/<exe-name>/UsageTests/Class.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/UsageTests/Class.tests.cpp" >
<Original>
m_a++ == 0
</Original>
<Expanded>
0 == 0
</Expanded>
</Expression>
<OverallResults successes="1" failures="0" expectedFailures="0" skipped="false"/>
</Section>
<Section name="Second partial run" filename="tests/<exe-name>/UsageTests/Class.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/UsageTests/Class.tests.cpp" >
<Original>
m_a == 1
</Original>
<Expanded>
1 == 1
</Expanded>
</Expression>
<OverallResults successes="1" failures="0" expectedFailures="0" skipped="false"/>
</Section>
<OverallResult success="true" skips="0"/>
</TestCase>
<TestCase name="A Template product test case - Foo&lt;float>" tags="[product][template]" filename="tests/<exe-name>/UsageTests/Misc.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/UsageTests/Misc.tests.cpp" >
<Original>
@@ -21832,6 +21882,6 @@ Approx( -1.95996398454005449 )
</Section>
<OverallResult success="true" skips="0"/>
</TestCase>
<OverallResults successes="2074" failures="146" expectedFailures="35" skips="12"/>
<OverallResultsCases successes="311" failures="85" expectedFailures="14" skips="6"/>
<OverallResults successes="2077" failures="147" expectedFailures="35" skips="12"/>
<OverallResultsCases successes="312" failures="86" expectedFailures="14" skips="6"/>
</Catch2TestRun>

View File

@@ -2056,6 +2056,56 @@ Nor would this
</Expression>
<OverallResult success="true" skips="0"/>
</TestCase>
<TestCase name="A TEST_CASE_PERSISTENT_FIXTURE based test run that fails" tags="[.][class][failing]" filename="tests/<exe-name>/UsageTests/Class.tests.cpp" >
<Section name="First partial run" filename="tests/<exe-name>/UsageTests/Class.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/UsageTests/Class.tests.cpp" >
<Original>
m_a++ == 0
</Original>
<Expanded>
0 == 0
</Expanded>
</Expression>
<OverallResults successes="1" failures="0" expectedFailures="0" skipped="false"/>
</Section>
<Section name="Second partial run" filename="tests/<exe-name>/UsageTests/Class.tests.cpp" >
<Expression success="false" type="REQUIRE" filename="tests/<exe-name>/UsageTests/Class.tests.cpp" >
<Original>
m_a == 0
</Original>
<Expanded>
1 == 0
</Expanded>
</Expression>
<OverallResults successes="0" failures="1" expectedFailures="0" skipped="false"/>
</Section>
<OverallResult success="false" skips="0"/>
</TestCase>
<TestCase name="A TEST_CASE_PERSISTENT_FIXTURE based test run that succeeds" tags="[class]" filename="tests/<exe-name>/UsageTests/Class.tests.cpp" >
<Section name="First partial run" filename="tests/<exe-name>/UsageTests/Class.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/UsageTests/Class.tests.cpp" >
<Original>
m_a++ == 0
</Original>
<Expanded>
0 == 0
</Expanded>
</Expression>
<OverallResults successes="1" failures="0" expectedFailures="0" skipped="false"/>
</Section>
<Section name="Second partial run" filename="tests/<exe-name>/UsageTests/Class.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/UsageTests/Class.tests.cpp" >
<Original>
m_a == 1
</Original>
<Expanded>
1 == 1
</Expanded>
</Expression>
<OverallResults successes="1" failures="0" expectedFailures="0" skipped="false"/>
</Section>
<OverallResult success="true" skips="0"/>
</TestCase>
<TestCase name="A Template product test case - Foo&lt;float>" tags="[product][template]" filename="tests/<exe-name>/UsageTests/Misc.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/UsageTests/Misc.tests.cpp" >
<Original>
@@ -21831,6 +21881,6 @@ Approx( -1.95996398454005449 )
</Section>
<OverallResult success="true" skips="0"/>
</TestCase>
<OverallResults successes="2074" failures="146" expectedFailures="35" skips="12"/>
<OverallResultsCases successes="311" failures="85" expectedFailures="14" skips="6"/>
<OverallResults successes="2077" failures="147" expectedFailures="35" skips="12"/>
<OverallResultsCases successes="312" failures="86" expectedFailures="14" skips="6"/>
</Catch2TestRun>

View File

@@ -32,6 +32,10 @@ namespace {
int m_a;
};
struct Persistent_Fixture {
mutable int m_a = 0;
};
template <typename T> struct Template_Fixture {
Template_Fixture(): m_a( 1 ) {}
@@ -64,6 +68,17 @@ TEST_CASE_METHOD( Fixture, "A TEST_CASE_METHOD based test run that succeeds", "[
REQUIRE( m_a == 1 );
}
TEST_CASE_PERSISTENT_FIXTURE( Persistent_Fixture, "A TEST_CASE_PERSISTENT_FIXTURE based test run that succeeds", "[class]" )
{
SECTION( "First partial run" ) {
REQUIRE( m_a++ == 0 );
}
SECTION( "Second partial run" ) {
REQUIRE( m_a == 1 );
}
}
TEMPLATE_TEST_CASE_METHOD(Template_Fixture, "A TEMPLATE_TEST_CASE_METHOD based test run that succeeds", "[class][template]", int, float, double) {
REQUIRE( Template_Fixture<TestType>::m_a == 1 );
}
@@ -96,6 +111,17 @@ namespace Inner
REQUIRE( m_a == 2 );
}
TEST_CASE_PERSISTENT_FIXTURE( Persistent_Fixture, "A TEST_CASE_PERSISTENT_FIXTURE based test run that fails", "[.][class][failing]" )
{
SECTION( "First partial run" ) {
REQUIRE( m_a++ == 0 );
}
SECTION( "Second partial run" ) {
REQUIRE( m_a == 0 );
}
}
TEMPLATE_TEST_CASE_METHOD(Template_Fixture,"A TEMPLATE_TEST_CASE_METHOD based test run that fails", "[.][class][template][failing]", int, float, double)
{
REQUIRE( Template_Fixture<TestType>::m_a == 2 );