Skip to content

Commit

Permalink
Ensured that TEST_CASE_PERSISTENT_FIXTURE works with CATCH_CONFIG_DIS…
Browse files Browse the repository at this point in the history
…ABLE
  • Loading branch information
KStocky committed Aug 3, 2024
1 parent 39a4b82 commit 72ce2bd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/catch2/catch_test_macros.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +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, ... )
#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( ... )
Expand Down Expand Up @@ -198,7 +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, ... )
#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( ... )
Expand Down
46 changes: 30 additions & 16 deletions tests/ExtraTests/X02-DisabledMacros.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit 72ce2bd

Please sign in to comment.