File indexing completed on 2025-01-18 09:54:06
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef CATCH_TEST_REGISTRY_HPP_INCLUDED
0009 #define CATCH_TEST_REGISTRY_HPP_INCLUDED
0010
0011 #include <catch2/internal/catch_config_static_analysis_support.hpp>
0012 #include <catch2/internal/catch_source_line_info.hpp>
0013 #include <catch2/internal/catch_noncopyable.hpp>
0014 #include <catch2/interfaces/catch_interfaces_test_invoker.hpp>
0015 #include <catch2/internal/catch_stringref.hpp>
0016 #include <catch2/internal/catch_unique_ptr.hpp>
0017 #include <catch2/internal/catch_unique_name.hpp>
0018 #include <catch2/internal/catch_preprocessor_remove_parens.hpp>
0019
0020
0021
0022
0023 #if defined(__GNUC__) && !defined(__clang__) && __GNUC__ <= 5
0024 #pragma GCC diagnostic ignored "-Wunused-variable"
0025 #endif
0026
0027
0028
0029 namespace Catch {
0030
0031 template<typename C>
0032 class TestInvokerAsMethod : public ITestInvoker {
0033 void (C::*m_testAsMethod)();
0034 public:
0035 TestInvokerAsMethod( void (C::*testAsMethod)() ) noexcept : m_testAsMethod( testAsMethod ) {}
0036
0037 void invoke() const override {
0038 C obj;
0039 (obj.*m_testAsMethod)();
0040 }
0041 };
0042
0043 Detail::unique_ptr<ITestInvoker> makeTestInvoker( void(*testAsFunction)() );
0044
0045 template<typename C>
0046 Detail::unique_ptr<ITestInvoker> makeTestInvoker( void (C::*testAsMethod)() ) {
0047 return Detail::make_unique<TestInvokerAsMethod<C>>( testAsMethod );
0048 }
0049
0050 struct NameAndTags {
0051 constexpr NameAndTags( StringRef name_ = StringRef(),
0052 StringRef tags_ = StringRef() ) noexcept:
0053 name( name_ ), tags( tags_ ) {}
0054 StringRef name;
0055 StringRef tags;
0056 };
0057
0058 struct AutoReg : Detail::NonCopyable {
0059 AutoReg( Detail::unique_ptr<ITestInvoker> invoker, SourceLineInfo const& lineInfo, StringRef classOrMethod, NameAndTags const& nameAndTags ) noexcept;
0060 };
0061
0062 }
0063
0064 #if defined(CATCH_CONFIG_DISABLE)
0065 #define INTERNAL_CATCH_TESTCASE_NO_REGISTRATION( TestName, ... ) \
0066 static inline void TestName()
0067 #define INTERNAL_CATCH_TESTCASE_METHOD_NO_REGISTRATION( TestName, ClassName, ... ) \
0068 namespace{ \
0069 struct TestName : INTERNAL_CATCH_REMOVE_PARENS(ClassName) { \
0070 void test(); \
0071 }; \
0072 } \
0073 void TestName::test()
0074 #endif
0075
0076
0077 #if !defined(CATCH_CONFIG_EXPERIMENTAL_STATIC_ANALYSIS_SUPPORT)
0078
0079
0080 #define INTERNAL_CATCH_TESTCASE2( TestName, ... ) \
0081 static void TestName(); \
0082 CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
0083 CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
0084 CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \
0085 namespace{ const Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( Catch::makeTestInvoker( &TestName ), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), Catch::NameAndTags{ __VA_ARGS__ } ); } \
0086 CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
0087 static void TestName()
0088 #define INTERNAL_CATCH_TESTCASE( ... ) \
0089 INTERNAL_CATCH_TESTCASE2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEST_ ), __VA_ARGS__ )
0090
0091 #else
0092
0093
0094
0095 namespace Catch {
0096 namespace Detail {
0097 struct DummyUse {
0098 DummyUse( void ( * )( int ) );
0099 };
0100 }
0101 }
0102
0103
0104
0105
0106
0107
0108 static int catchInternalSectionHint = 0;
0109
0110 # define INTERNAL_CATCH_TESTCASE2( fname ) \
0111 static void fname( int ); \
0112 CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
0113 CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
0114 CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \
0115 static const Catch::Detail::DummyUse INTERNAL_CATCH_UNIQUE_NAME( \
0116 dummyUser )( &fname ); \
0117 CATCH_INTERNAL_SUPPRESS_SHADOW_WARNINGS \
0118 static void fname( [[maybe_unused]] int catchInternalSectionHint ) \
0119 CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
0120 # define INTERNAL_CATCH_TESTCASE( ... ) \
0121 INTERNAL_CATCH_TESTCASE2( INTERNAL_CATCH_UNIQUE_NAME( dummyFunction ) )
0122
0123
0124 #endif
0125
0126
0127 #define INTERNAL_CATCH_TEST_CASE_METHOD2( TestName, ClassName, ... )\
0128 CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
0129 CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
0130 CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \
0131 namespace{ \
0132 struct TestName : INTERNAL_CATCH_REMOVE_PARENS(ClassName) { \
0133 void test(); \
0134 }; \
0135 const Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( \
0136 Catch::makeTestInvoker( &TestName::test ), \
0137 CATCH_INTERNAL_LINEINFO, \
0138 #ClassName##_catch_sr, \
0139 Catch::NameAndTags{ __VA_ARGS__ } ); \
0140 } \
0141 CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
0142 void TestName::test()
0143 #define INTERNAL_CATCH_TEST_CASE_METHOD( ClassName, ... ) \
0144 INTERNAL_CATCH_TEST_CASE_METHOD2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEST_ ), ClassName, __VA_ARGS__ )
0145
0146
0147
0148 #define INTERNAL_CATCH_METHOD_AS_TEST_CASE( QualifiedMethod, ... ) \
0149 CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
0150 CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
0151 CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \
0152 namespace { \
0153 const Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( \
0154 Catch::makeTestInvoker( &QualifiedMethod ), \
0155 CATCH_INTERNAL_LINEINFO, \
0156 "&" #QualifiedMethod##_catch_sr, \
0157 Catch::NameAndTags{ __VA_ARGS__ } ); \
0158 } \
0159 CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
0160
0161
0162
0163 #define INTERNAL_CATCH_REGISTER_TESTCASE( Function, ... ) \
0164 do { \
0165 CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
0166 CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
0167 CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \
0168 Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( Catch::makeTestInvoker( Function ), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), Catch::NameAndTags{ __VA_ARGS__ } ); \
0169 CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
0170 } while(false)
0171
0172
0173 #endif