From f7cd0ba0511b61592e70f07533d7ea30a8a5395d Mon Sep 17 00:00:00 2001 From: Keith Stockdale Date: Mon, 5 Aug 2024 16:01:41 +0100 Subject: [PATCH] TEST_CASE_PERSISTENT_FIXTURE: A new fixture macro for allowing persistent fixtures throughout a TEST_CASE (#2885) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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ý --- docs/cmake-integration.md | 1 + docs/list-of-examples.md | 1 + docs/other-macros.md | 24 --- docs/test-fixtures.md | 137 +++++++++++++++++- examples/111-Fix-PersistentFixture.cpp | 74 ++++++++++ examples/CMakeLists.txt | 1 + src/catch2/catch_test_case_info.hpp | 8 + src/catch2/catch_test_macros.hpp | 4 + .../catch_interfaces_test_invoker.hpp | 2 + src/catch2/internal/catch_run_context.cpp | 2 + src/catch2/internal/catch_test_registry.cpp | 2 + src/catch2/internal/catch_test_registry.hpp | 47 ++++++ tests/ExtraTests/X02-DisabledMacros.cpp | 46 ++++-- .../Baselines/automake.sw.approved.txt | 2 + .../Baselines/automake.sw.multi.approved.txt | 2 + .../Baselines/compact.sw.approved.txt | 8 +- .../Baselines/compact.sw.multi.approved.txt | 8 +- .../Baselines/console.std.approved.txt | 16 +- .../Baselines/console.sw.approved.txt | 52 ++++++- .../Baselines/console.sw.multi.approved.txt | 52 ++++++- .../SelfTest/Baselines/junit.sw.approved.txt | 14 +- .../Baselines/junit.sw.multi.approved.txt | 14 +- .../Baselines/sonarqube.sw.approved.txt | 12 ++ .../Baselines/sonarqube.sw.multi.approved.txt | 12 ++ tests/SelfTest/Baselines/tap.sw.approved.txt | 10 +- .../Baselines/tap.sw.multi.approved.txt | 10 +- .../Baselines/teamcity.sw.approved.txt | 5 + .../Baselines/teamcity.sw.multi.approved.txt | 5 + tests/SelfTest/Baselines/xml.sw.approved.txt | 54 ++++++- .../Baselines/xml.sw.multi.approved.txt | 54 ++++++- tests/SelfTest/UsageTests/Class.tests.cpp | 26 ++++ 31 files changed, 643 insertions(+), 62 deletions(-) create mode 100644 examples/111-Fix-PersistentFixture.cpp diff --git a/docs/cmake-integration.md b/docs/cmake-integration.md index a1bb4358..ad6ca004 100644 --- a/docs/cmake-integration.md +++ b/docs/cmake-integration.md @@ -8,6 +8,7 @@ [`CATCH_CONFIG_*` customization options in CMake](#catch_config_-customization-options-in-cmake)
[Installing Catch2 from git repository](#installing-catch2-from-git-repository)
[Installing Catch2 from vcpkg](#installing-catch2-from-vcpkg)
+[Installing Catch2 from Bazel](#installing-catch2-from-bazel)
Because we use CMake to build Catch2, we also provide a couple of integration points for our users. diff --git a/docs/list-of-examples.md b/docs/list-of-examples.md index a919408a..40d3f711 100644 --- a/docs/list-of-examples.md +++ b/docs/list-of-examples.md @@ -8,6 +8,7 @@ - Assertion: [REQUIRE, CHECK](../examples/030-Asn-Require-Check.cpp) - Fixture: [Sections](../examples/100-Fix-Section.cpp) - Fixture: [Class-based fixtures](../examples/110-Fix-ClassFixture.cpp) +- Fixture: [Persistent fixtures](../examples/111-Fix-PersistentFixture.cpp) - BDD: [SCENARIO, GIVEN, WHEN, THEN](../examples/120-Bdd-ScenarioGivenWhenThen.cpp) - Listener: [Listeners](../examples/210-Evt-EventListeners.cpp) - Configuration: [Provide your own output streams](../examples/231-Cfg-OutputStreams.cpp) diff --git a/docs/other-macros.md b/docs/other-macros.md index 24a0fb6e..79990a6a 100644 --- a/docs/other-macros.md +++ b/docs/other-macros.md @@ -93,30 +93,6 @@ TEST_CASE("STATIC_CHECK showcase", "[traits]") { ## Test case related macros -* `METHOD_AS_TEST_CASE` - -`METHOD_AS_TEST_CASE( member-function-pointer, description )` lets you -register a member function of a class as a Catch2 test case. The class -will be separately instantiated for each method registered in this way. - -```cpp -class TestClass { - std::string s; - -public: - TestClass() - :s( "hello" ) - {} - - void testCase() { - REQUIRE( s == "hello" ); - } -}; - - -METHOD_AS_TEST_CASE( TestClass::testCase, "Use class's method as a test case", "[class]" ) -``` - * `REGISTER_TEST_CASE` `REGISTER_TEST_CASE( function, description )` let's you register diff --git a/docs/test-fixtures.md b/docs/test-fixtures.md index 9c9eaa18..6bc115e2 100644 --- a/docs/test-fixtures.md +++ b/docs/test-fixtures.md @@ -1,9 +1,30 @@ # Test fixtures -## Defining test fixtures +**Contents**
+[Non-Templated test fixtures](#non-templated-test-fixtures)
+[Templated test fixtures](#templated-test-fixtures)
+[Signature-based parameterised test fixtures](#signature-based-parametrised-test-fixtures)
+[Template fixtures with types specified in template type lists](#template-fixtures-with-types-specified-in-template-type-lists)
-Although Catch allows you to group tests together as [sections within a test case](test-cases-and-sections.md), it can still be convenient, sometimes, to group them using a more traditional test fixture. Catch fully supports this too. You define the test fixture as a simple structure: +## Non-Templated test fixtures + +Although Catch2 allows you to group tests together as +[sections within a test case](test-cases-and-sections.md), it can still +be convenient, sometimes, to group them using a more traditional test. +Catch2 fully supports this too with 3 different macros for +non-templated test fixtures. They are: + +| Macro | Description | +|----------|-------------| +|1. `TEST_CASE_METHOD(className, ...)`| Creates a uniquely named class which inherits from the class specified by `className`. The test function will be a member of this derived class. An instance of the derived class will be created for every partial run of the test case. | +|2. `METHOD_AS_TEST_CASE(member-function, ...)`| Uses `member-function` as the test function. An instance of the class will be created for each partial run of the test case. | +|3. `TEST_CASE_PERSISTENT_FIXTURE(className, ...)`| Creates a uniquely named class which inherits from the class specified by `className`. The test function will be a member of this derived class. An instance of the derived class will be created at the start of the test run. That instance will be destroyed once the entire test case has ended. | + +### 1. `TEST_CASE_METHOD` + + +You define a `TEST_CASE_METHOD` test fixture as a simple structure: ```c++ class UniqueTestsFixture { @@ -30,8 +51,116 @@ class UniqueTestsFixture { } ``` -The two test cases here will create uniquely-named derived classes of UniqueTestsFixture and thus can access the `getID()` protected method and `conn` member variables. This ensures that both the test cases are able to create a DBConnection using the same method (DRY principle) and that any ID's created are unique such that the order that tests are executed does not matter. +The two test cases here will create uniquely-named derived classes of +UniqueTestsFixture and thus can access the `getID()` protected method +and `conn` member variables. This ensures that both the test cases +are able to create a DBConnection using the same method +(DRY principle) and that any ID's created are unique such that the +order that tests are executed does not matter. +### 2. `METHOD_AS_TEST_CASE` + +`METHOD_AS_TEST_CASE` lets you register a member function of a class +as a Catch2 test case. The class will be separately instantiated +for each method registered in this way. + +```cpp +class TestClass { + std::string s; + +public: + TestClass() + :s( "hello" ) + {} + + void testCase() { + REQUIRE( s == "hello" ); + } +}; + + +METHOD_AS_TEST_CASE( TestClass::testCase, "Use class's method as a test case", "[class]" ) +``` + +This type of fixture is similar to [TEST_CASE_METHOD](#1-test_case_method) except in this +case it will directly use the provided class to create an object rather than a derived +class. + +### 3. `TEST_CASE_PERSISTENT_FIXTURE` + +> [Introduced](https://github.com/catchorg/Catch2/pull/2885) in Catch2 X.Y.Z + +`TEST_CASE_PERSISTENT_FIXTURE` behaves in the same way as +[TEST_CASE_METHOD](#1-test_case_method) except that there will only be +one instance created throughout the entire run of a test case. To +demonstrate this have a look at the following example: + +```cpp +class ClassWithExpensiveSetup { +public: + ClassWithExpensiveSetup() { + // expensive construction + std::this_thread::sleep_for( std::chrono::seconds( 2 ) ); + } + + ~ClassWithExpensiveSetup() noexcept { + // expensive destruction + std::this_thread::sleep_for( std::chrono::seconds( 1 ) ); + } + + int getInt() const { return 42; } +}; + +struct MyFixture { + mutable int myInt = 0; + ClassWithExpensiveSetup expensive; +}; + +TEST_CASE_PERSISTENT_FIXTURE( MyFixture, "Tests with MyFixture" ) { + + const int val = myInt++; + + SECTION( "First partial run" ) { + const auto otherValue = expensive.getInt(); + REQUIRE( val == 0 ); + REQUIRE( otherValue == 42 ); + } + + SECTION( "Second partial run" ) { REQUIRE( val == 1 ); } +} +``` + +This example demonstates two possible use-cases of this fixture type: +1. Improve test run times by reducing the amount of expensive and +redundant setup and tear-down required. +2. Reusing results from the previous partial run, in the current +partial run. + +This test case will be executed twice as there are two leaf sections. +On the first run `val` will be `0` and on the second run `val` will be +`1`. This demonstrates that we were able to use the results of the +previous partial run in subsequent partial runs. + +Additionally, we are simulating an expensive object using +`std::this_thread::sleep_for`, but real world use-cases could be: +1. Creating a D3D12/Vulkan device +2. Connecting to a database +3. Loading a file. + +The fixture object (`MyFixture`) will be constructed just before the +test case begins, and it will be destroyed just after the test case +ends. Therefore, this expensive object will only be created and +destroyed once during the execution of this test case. If we had used +`TEST_CASE_METHOD`, `MyFixture` would have been created and destroyed +twice during the execution of this test case. + +NOTE: The member function which runs the test case is `const`. Therefore +if you want to mutate any member of the fixture it must be marked as +`mutable` as shown in this example. This is to make it clear that +the initial state of the fixture is intended to mutate during the +execution of the test case. + +## Templated test fixtures Catch2 also provides `TEMPLATE_TEST_CASE_METHOD` and `TEMPLATE_PRODUCT_TEST_CASE_METHOD` that can be used together @@ -93,7 +222,7 @@ _While there is an upper limit on the number of types you can specify in single `TEMPLATE_TEST_CASE_METHOD` or `TEMPLATE_PRODUCT_TEST_CASE_METHOD`, the limit is very high and should not be encountered in practice._ -## Signature-based parametrised test fixtures +## Signature-based parameterised test fixtures > [Introduced](https://github.com/catchorg/Catch2/issues/1609) in Catch2 2.8.0. diff --git a/examples/111-Fix-PersistentFixture.cpp b/examples/111-Fix-PersistentFixture.cpp new file mode 100644 index 00000000..2bef90ff --- /dev/null +++ b/examples/111-Fix-PersistentFixture.cpp @@ -0,0 +1,74 @@ + +// Copyright Catch2 Authors +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// SPDX-License-Identifier: BSL-1.0 + +// Fixture.cpp + +// Catch2 has three ways to express fixtures: +// - Sections +// - Traditional class-based fixtures that are created and destroyed on every +// partial run +// - Traditional class-based fixtures that are created at the start of a test +// case and destroyed at the end of a test case (this file) + +// main() provided by linkage to Catch2WithMain + +#include + +#include + +class ClassWithExpensiveSetup { +public: + ClassWithExpensiveSetup() { + // Imagine some really expensive set up here. + // e.g. + // setting up a D3D12/Vulkan Device, + // connecting to a database, + // loading a file + // etc etc etc + std::this_thread::sleep_for( std::chrono::seconds( 2 ) ); + } + + ~ClassWithExpensiveSetup() noexcept { + // We can do any clean up of the expensive class in the destructor + // e.g. + // destroy D3D12/Vulkan Device, + // disconnecting from a database, + // release file handle + // etc etc etc + std::this_thread::sleep_for( std::chrono::seconds( 1 ) ); + } + + int getInt() const { return 42; } +}; + +struct MyFixture { + + // The test case member function is const. + // Therefore we need to mark any member of the fixture + // that needs to mutate as mutable. + mutable int myInt = 0; + ClassWithExpensiveSetup expensive; +}; + +// Only one object of type MyFixture will be instantiated for the run +// of this test case even though there are two leaf sections. +// This is useful if your test case requires an object that is +// expensive to create and could be reused for each partial run of the +// test case. +TEST_CASE_PERSISTENT_FIXTURE( MyFixture, "Tests with MyFixture" ) { + + const int val = myInt++; + + SECTION( "First partial run" ) { + const auto otherValue = expensive.getInt(); + REQUIRE( val == 0 ); + REQUIRE( otherValue == 42 ); + } + + SECTION( "Second partial run" ) { REQUIRE( val == 1 ); } +} \ No newline at end of file diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 7e629e09..4647df1d 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -28,6 +28,7 @@ set( SOURCES_IDIOMATIC_EXAMPLES 030-Asn-Require-Check.cpp 100-Fix-Section.cpp 110-Fix-ClassFixture.cpp + 111-Fix-PersistentFixture.cpp 120-Bdd-ScenarioGivenWhenThen.cpp 210-Evt-EventListeners.cpp 232-Cfg-CustomMain.cpp diff --git a/src/catch2/catch_test_case_info.hpp b/src/catch2/catch_test_case_info.hpp index da9927e7..00b393b2 100644 --- a/src/catch2/catch_test_case_info.hpp +++ b/src/catch2/catch_test_case_info.hpp @@ -112,6 +112,14 @@ namespace Catch { TestCaseHandle(TestCaseInfo* info, ITestInvoker* invoker) : m_info(info), m_invoker(invoker) {} + void prepareTestCase() const { + m_invoker->prepareTestCase(); + } + + void tearDownTestCase() const { + m_invoker->tearDownTestCase(); + } + void invoke() const { m_invoker->invoke(); } diff --git a/src/catch2/catch_test_macros.hpp b/src/catch2/catch_test_macros.hpp index 1088afbe..6ee2129f 100644 --- a/src/catch2/catch_test_macros.hpp +++ b/src/catch2/catch_test_macros.hpp @@ -43,6 +43,7 @@ #define CATCH_TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ ) #define CATCH_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ ) #define CATCH_METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ ) + #define CATCH_TEST_CASE_PERSISTENT_FIXTURE( className, ... ) INTERNAL_CATCH_TEST_CASE_PERSISTENT_FIXTURE( className, __VA_ARGS__ ) #define CATCH_REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ ) #define CATCH_SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ ) #define CATCH_DYNAMIC_SECTION( ... ) INTERNAL_CATCH_DYNAMIC_SECTION( __VA_ARGS__ ) @@ -97,6 +98,7 @@ #define CATCH_TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEST_ )) #define CATCH_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEST_ )) #define CATCH_METHOD_AS_TEST_CASE( method, ... ) + #define CATCH_TEST_CASE_PERSISTENT_FIXTURE( className, ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEST_ )) #define CATCH_REGISTER_TEST_CASE( Function, ... ) (void)(0) #define CATCH_SECTION( ... ) #define CATCH_DYNAMIC_SECTION( ... ) @@ -142,6 +144,7 @@ #define TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ ) #define TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ ) #define METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ ) + #define TEST_CASE_PERSISTENT_FIXTURE( className, ... ) INTERNAL_CATCH_TEST_CASE_PERSISTENT_FIXTURE( className, __VA_ARGS__ ) #define REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ ) #define SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ ) #define DYNAMIC_SECTION( ... ) INTERNAL_CATCH_DYNAMIC_SECTION( __VA_ARGS__ ) @@ -195,6 +198,7 @@ #define TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEST_ ), __VA_ARGS__) #define TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEST_ )) #define METHOD_AS_TEST_CASE( method, ... ) + #define TEST_CASE_PERSISTENT_FIXTURE( className, ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEST_ ), __VA_ARGS__) #define REGISTER_TEST_CASE( Function, ... ) (void)(0) #define SECTION( ... ) #define DYNAMIC_SECTION( ... ) diff --git a/src/catch2/interfaces/catch_interfaces_test_invoker.hpp b/src/catch2/interfaces/catch_interfaces_test_invoker.hpp index 3caeff9a..124a7f7d 100644 --- a/src/catch2/interfaces/catch_interfaces_test_invoker.hpp +++ b/src/catch2/interfaces/catch_interfaces_test_invoker.hpp @@ -12,6 +12,8 @@ namespace Catch { class ITestInvoker { public: + virtual void prepareTestCase(); + virtual void tearDownTestCase(); virtual void invoke() const = 0; virtual ~ITestInvoker(); // = default }; diff --git a/src/catch2/internal/catch_run_context.cpp b/src/catch2/internal/catch_run_context.cpp index 07691788..8711352c 100644 --- a/src/catch2/internal/catch_run_context.cpp +++ b/src/catch2/internal/catch_run_context.cpp @@ -185,6 +185,7 @@ namespace Catch { auto const& testInfo = testCase.getTestCaseInfo(); m_reporter->testCaseStarting(testInfo); + testCase.prepareTestCase(); m_activeTestCase = &testCase; @@ -254,6 +255,7 @@ namespace Catch { deltaTotals.testCases.failed++; } m_totals.testCases += deltaTotals.testCases; + testCase.tearDownTestCase(); m_reporter->testCaseEnded(TestCaseStats(testInfo, deltaTotals, CATCH_MOVE(redirectedCout), diff --git a/src/catch2/internal/catch_test_registry.cpp b/src/catch2/internal/catch_test_registry.cpp index e9c999fe..07e44617 100644 --- a/src/catch2/internal/catch_test_registry.cpp +++ b/src/catch2/internal/catch_test_registry.cpp @@ -16,6 +16,8 @@ #include namespace Catch { + void ITestInvoker::prepareTestCase() {} + void ITestInvoker::tearDownTestCase() {} ITestInvoker::~ITestInvoker() = default; namespace { diff --git a/src/catch2/internal/catch_test_registry.hpp b/src/catch2/internal/catch_test_registry.hpp index c62fbdcc..e275f2b9 100644 --- a/src/catch2/internal/catch_test_registry.hpp +++ b/src/catch2/internal/catch_test_registry.hpp @@ -47,6 +47,33 @@ Detail::unique_ptr makeTestInvoker( void (C::*testAsMethod)() ) { return Detail::make_unique>( testAsMethod ); } +template +class TestInvokerFixture : public ITestInvoker { + void ( C::*m_testAsMethod )() const; + Detail::unique_ptr m_fixture = nullptr; + +public: + TestInvokerFixture( void ( C::*testAsMethod )() const) noexcept : m_testAsMethod( testAsMethod ) {} + + void prepareTestCase() override { + m_fixture = Detail::make_unique(); + } + + void tearDownTestCase() override { + m_fixture.reset(); + } + + void invoke() const override { + auto* f = m_fixture.get(); + ( f->*m_testAsMethod )(); + } +}; + +template +Detail::unique_ptr makeTestInvokerFixture( void ( C::*testAsMethod )() const ) { + return Detail::make_unique>( testAsMethod ); +} + struct NameAndTags { constexpr NameAndTags( StringRef name_ = StringRef(), StringRef tags_ = StringRef() ) noexcept: @@ -143,6 +170,26 @@ static int catchInternalSectionHint = 0; #define INTERNAL_CATCH_TEST_CASE_METHOD( ClassName, ... ) \ INTERNAL_CATCH_TEST_CASE_METHOD2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEST_ ), ClassName, __VA_ARGS__ ) + /////////////////////////////////////////////////////////////////////////////// + #define INTERNAL_CATCH_TEST_CASE_PERSISTENT_FIXTURE2( TestName, ClassName, ... ) \ + CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ + CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ + CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \ + namespace { \ + struct TestName : INTERNAL_CATCH_REMOVE_PARENS( ClassName ) { \ + void test() const; \ + }; \ + const Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( \ + Catch::makeTestInvokerFixture( &TestName::test ), \ + CATCH_INTERNAL_LINEINFO, \ + #ClassName##_catch_sr, \ + Catch::NameAndTags{ __VA_ARGS__ } ); /* NOLINT */ \ + } \ + CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \ + void TestName::test() const + #define INTERNAL_CATCH_TEST_CASE_PERSISTENT_FIXTURE( ClassName, ... ) \ + INTERNAL_CATCH_TEST_CASE_PERSISTENT_FIXTURE2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEST_ ), ClassName, __VA_ARGS__ ) + /////////////////////////////////////////////////////////////////////////////// #define INTERNAL_CATCH_METHOD_AS_TEST_CASE( QualifiedMethod, ... ) \ diff --git a/tests/ExtraTests/X02-DisabledMacros.cpp b/tests/ExtraTests/X02-DisabledMacros.cpp index 68bc2add..231adfb0 100644 --- a/tests/ExtraTests/X02-DisabledMacros.cpp +++ b/tests/ExtraTests/X02-DisabledMacros.cpp @@ -11,34 +11,28 @@ * and expressions in assertion macros are not run. */ - -#include #include +#include #include #include #include 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 diff --git a/tests/SelfTest/Baselines/automake.sw.approved.txt b/tests/SelfTest/Baselines/automake.sw.approved.txt index dbdf395c..ce9475b8 100644 --- a/tests/SelfTest/Baselines/automake.sw.approved.txt +++ b/tests/SelfTest/Baselines/automake.sw.approved.txt @@ -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 :test-result: PASS A Template product test case - Foo :test-result: PASS A Template product test case - std::vector diff --git a/tests/SelfTest/Baselines/automake.sw.multi.approved.txt b/tests/SelfTest/Baselines/automake.sw.multi.approved.txt index 4029ec65..06f2f58d 100644 --- a/tests/SelfTest/Baselines/automake.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/automake.sw.multi.approved.txt @@ -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 :test-result: PASS A Template product test case - Foo :test-result: PASS A Template product test case - std::vector diff --git a/tests/SelfTest/Baselines/compact.sw.approved.txt b/tests/SelfTest/Baselines/compact.sw.approved.txt index 9363cb54..0f107e71 100644 --- a/tests/SelfTest/Baselines/compact.sw.approved.txt +++ b/tests/SelfTest/Baselines/compact.sw.approved.txt @@ -241,6 +241,10 @@ Class.tests.cpp:: passed: Nttp_Fixture::value > 0 for: 3 > 0 Class.tests.cpp:: passed: Nttp_Fixture::value > 0 for: 6 > 0 Class.tests.cpp:: failed: m_a == 2 for: 1 == 2 Class.tests.cpp:: passed: m_a == 1 for: 1 == 1 +Class.tests.cpp:: passed: m_a++ == 0 for: 0 == 0 +Class.tests.cpp:: failed: m_a == 0 for: 1 == 0 +Class.tests.cpp:: passed: m_a++ == 0 for: 0 == 0 +Class.tests.cpp:: passed: m_a == 1 for: 1 == 1 Misc.tests.cpp:: passed: x.size() == 0 for: 0 == 0 Misc.tests.cpp:: passed: x.size() == 0 for: 0 == 0 Misc.tests.cpp:: passed: x.size() == 0 for: 0 == 0 @@ -2840,7 +2844,7 @@ InternalBenchmark.tests.cpp:: passed: med == 18. for: 18.0 == 18.0 InternalBenchmark.tests.cpp:: passed: q3 == 23. for: 23.0 == 23.0 Misc.tests.cpp:: passed: Misc.tests.cpp:: 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 diff --git a/tests/SelfTest/Baselines/compact.sw.multi.approved.txt b/tests/SelfTest/Baselines/compact.sw.multi.approved.txt index 4007dfca..4b9d35c6 100644 --- a/tests/SelfTest/Baselines/compact.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/compact.sw.multi.approved.txt @@ -239,6 +239,10 @@ Class.tests.cpp:: passed: Nttp_Fixture::value > 0 for: 3 > 0 Class.tests.cpp:: passed: Nttp_Fixture::value > 0 for: 6 > 0 Class.tests.cpp:: failed: m_a == 2 for: 1 == 2 Class.tests.cpp:: passed: m_a == 1 for: 1 == 1 +Class.tests.cpp:: passed: m_a++ == 0 for: 0 == 0 +Class.tests.cpp:: failed: m_a == 0 for: 1 == 0 +Class.tests.cpp:: passed: m_a++ == 0 for: 0 == 0 +Class.tests.cpp:: passed: m_a == 1 for: 1 == 1 Misc.tests.cpp:: passed: x.size() == 0 for: 0 == 0 Misc.tests.cpp:: passed: x.size() == 0 for: 0 == 0 Misc.tests.cpp:: passed: x.size() == 0 for: 0 == 0 @@ -2829,7 +2833,7 @@ InternalBenchmark.tests.cpp:: passed: med == 18. for: 18.0 == 18.0 InternalBenchmark.tests.cpp:: passed: q3 == 23. for: 23.0 == 23.0 Misc.tests.cpp:: passed: Misc.tests.cpp:: 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 diff --git a/tests/SelfTest/Baselines/console.std.approved.txt b/tests/SelfTest/Baselines/console.std.approved.txt index 9b398435..f3196855 100644 --- a/tests/SelfTest/Baselines/console.std.approved.txt +++ b/tests/SelfTest/Baselines/console.std.approved.txt @@ -297,6 +297,18 @@ Class.tests.cpp:: FAILED: with expansion: 1 == 2 +------------------------------------------------------------------------------- +A TEST_CASE_PERSISTENT_FIXTURE based test run that fails + Second partial run +------------------------------------------------------------------------------- +Class.tests.cpp: +............................................................................... + +Class.tests.cpp:: 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 diff --git a/tests/SelfTest/Baselines/console.sw.approved.txt b/tests/SelfTest/Baselines/console.sw.approved.txt index de89152e..ba18ad1f 100644 --- a/tests/SelfTest/Baselines/console.sw.approved.txt +++ b/tests/SelfTest/Baselines/console.sw.approved.txt @@ -2023,6 +2023,54 @@ A TEST_CASE_METHOD based test run that succeeds Class.tests.cpp: ............................................................................... +Class.tests.cpp:: 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: +............................................................................... + +Class.tests.cpp:: 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: +............................................................................... + +Class.tests.cpp:: 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: +............................................................................... + +Class.tests.cpp:: 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: +............................................................................... + Class.tests.cpp:: PASSED: REQUIRE( m_a == 1 ) with expansion: @@ -18894,6 +18942,6 @@ Misc.tests.cpp: Misc.tests.cpp:: 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 diff --git a/tests/SelfTest/Baselines/console.sw.multi.approved.txt b/tests/SelfTest/Baselines/console.sw.multi.approved.txt index f70c0d6f..bdb54d43 100644 --- a/tests/SelfTest/Baselines/console.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/console.sw.multi.approved.txt @@ -2021,6 +2021,54 @@ A TEST_CASE_METHOD based test run that succeeds Class.tests.cpp: ............................................................................... +Class.tests.cpp:: 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: +............................................................................... + +Class.tests.cpp:: 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: +............................................................................... + +Class.tests.cpp:: 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: +............................................................................... + +Class.tests.cpp:: 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: +............................................................................... + Class.tests.cpp:: PASSED: REQUIRE( m_a == 1 ) with expansion: @@ -18883,6 +18931,6 @@ Misc.tests.cpp: Misc.tests.cpp:: 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 diff --git a/tests/SelfTest/Baselines/junit.sw.approved.txt b/tests/SelfTest/Baselines/junit.sw.approved.txt index 1888139a..cfe9de63 100644 --- a/tests/SelfTest/Baselines/junit.sw.approved.txt +++ b/tests/SelfTest/Baselines/junit.sw.approved.txt @@ -1,7 +1,7 @@ - + @@ -313,6 +313,18 @@ at Class.tests.cpp: + + + +FAILED: + REQUIRE( m_a == 0 ) +with expansion: + 1 == 0 +at Class.tests.cpp: + + + + diff --git a/tests/SelfTest/Baselines/junit.sw.multi.approved.txt b/tests/SelfTest/Baselines/junit.sw.multi.approved.txt index b594c8c0..42db614f 100644 --- a/tests/SelfTest/Baselines/junit.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/junit.sw.multi.approved.txt @@ -1,6 +1,6 @@ - + @@ -312,6 +312,18 @@ at Class.tests.cpp: + + + +FAILED: + REQUIRE( m_a == 0 ) +with expansion: + 1 == 0 +at Class.tests.cpp: + + + + diff --git a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt index 537145cc..1b5b8757 100644 --- a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt +++ b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt @@ -519,6 +519,18 @@ at Class.tests.cpp: + + + +FAILED: + REQUIRE( m_a == 0 ) +with expansion: + 1 == 0 +at Class.tests.cpp: + + + + diff --git a/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt b/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt index 5965774d..dc6b3b31 100644 --- a/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt @@ -518,6 +518,18 @@ at Class.tests.cpp: + + + +FAILED: + REQUIRE( m_a == 0 ) +with expansion: + 1 == 0 +at Class.tests.cpp: + + + + diff --git a/tests/SelfTest/Baselines/tap.sw.approved.txt b/tests/SelfTest/Baselines/tap.sw.approved.txt index 383bd4b0..36da9a8e 100644 --- a/tests/SelfTest/Baselines/tap.sw.approved.txt +++ b/tests/SelfTest/Baselines/tap.sw.approved.txt @@ -478,6 +478,14 @@ ok {test-number} - Nttp_Fixture::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 ok {test-number} - x.size() == 0 for: 0 == 0 # A Template product test case - Foo @@ -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 diff --git a/tests/SelfTest/Baselines/tap.sw.multi.approved.txt b/tests/SelfTest/Baselines/tap.sw.multi.approved.txt index 6622a96a..64828cb1 100644 --- a/tests/SelfTest/Baselines/tap.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/tap.sw.multi.approved.txt @@ -476,6 +476,14 @@ ok {test-number} - Nttp_Fixture::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 ok {test-number} - x.size() == 0 for: 0 == 0 # A Template product test case - Foo @@ -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 diff --git a/tests/SelfTest/Baselines/teamcity.sw.approved.txt b/tests/SelfTest/Baselines/teamcity.sw.approved.txt index cec3a0ee..d305ee83 100644 --- a/tests/SelfTest/Baselines/teamcity.sw.approved.txt +++ b/tests/SelfTest/Baselines/teamcity.sw.approved.txt @@ -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:|n...............................................................................|n|nClass.tests.cpp:|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'] ##teamcity[testFinished name='A Template product test case - Foo' duration="{duration}"] ##teamcity[testStarted name='A Template product test case - Foo'] diff --git a/tests/SelfTest/Baselines/teamcity.sw.multi.approved.txt b/tests/SelfTest/Baselines/teamcity.sw.multi.approved.txt index 6f7d8f19..156a8e2c 100644 --- a/tests/SelfTest/Baselines/teamcity.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/teamcity.sw.multi.approved.txt @@ -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:|n...............................................................................|n|nClass.tests.cpp:|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'] ##teamcity[testFinished name='A Template product test case - Foo' duration="{duration}"] ##teamcity[testStarted name='A Template product test case - Foo'] diff --git a/tests/SelfTest/Baselines/xml.sw.approved.txt b/tests/SelfTest/Baselines/xml.sw.approved.txt index f8acf1d4..a00e4577 100644 --- a/tests/SelfTest/Baselines/xml.sw.approved.txt +++ b/tests/SelfTest/Baselines/xml.sw.approved.txt @@ -2056,6 +2056,56 @@ Nor would this + +
+ + + m_a++ == 0 + + + 0 == 0 + + + +
+
+ + + m_a == 0 + + + 1 == 0 + + + +
+ +
+ +
+ + + m_a++ == 0 + + + 0 == 0 + + + +
+
+ + + m_a == 1 + + + 1 == 1 + + + +
+ +
@@ -21832,6 +21882,6 @@ Approx( -1.95996398454005449 ) - - + + diff --git a/tests/SelfTest/Baselines/xml.sw.multi.approved.txt b/tests/SelfTest/Baselines/xml.sw.multi.approved.txt index 5d815a51..08a1804a 100644 --- a/tests/SelfTest/Baselines/xml.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/xml.sw.multi.approved.txt @@ -2056,6 +2056,56 @@ Nor would this
+ +
+ + + m_a++ == 0 + + + 0 == 0 + + + +
+
+ + + m_a == 0 + + + 1 == 0 + + + +
+ +
+ +
+ + + m_a++ == 0 + + + 0 == 0 + + + +
+
+ + + m_a == 1 + + + 1 == 1 + + + +
+ +
@@ -21831,6 +21881,6 @@ Approx( -1.95996398454005449 ) - - + + diff --git a/tests/SelfTest/UsageTests/Class.tests.cpp b/tests/SelfTest/UsageTests/Class.tests.cpp index 682171da..75510f10 100644 --- a/tests/SelfTest/UsageTests/Class.tests.cpp +++ b/tests/SelfTest/UsageTests/Class.tests.cpp @@ -32,6 +32,10 @@ namespace { int m_a; }; + struct Persistent_Fixture { + mutable int m_a = 0; + }; + template 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::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::m_a == 2 );