Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:54:06

0001 
0002 //              Copyright Catch2 Authors
0003 // Distributed under the Boost Software License, Version 1.0.
0004 //   (See accompanying file LICENSE.txt or copy at
0005 //        https://www.boost.org/LICENSE_1_0.txt)
0006 
0007 // SPDX-License-Identifier: BSL-1.0
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 // GCC 5 and older do not properly handle disabling unused-variable warning
0021 // with a _Pragma. This means that we have to leak the suppression to the
0022 // user code as well :-(
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 } // end namespace Catch
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__ } ); } /* NOLINT */ \
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  // ^^ !CATCH_CONFIG_EXPERIMENTAL_STATIC_ANALYSIS_SUPPORT | vv CATCH_CONFIG_EXPERIMENTAL_STATIC_ANALYSIS_SUPPORT
0092 
0093 
0094 // Dummy registrator for the dumy test case macros
0095 namespace Catch {
0096     namespace Detail {
0097         struct DummyUse {
0098             DummyUse( void ( * )( int ) );
0099         };
0100     } // namespace Detail
0101 } // namespace Catch
0102 
0103 // Note that both the presence of the argument and its exact name are
0104 // necessary for the section support.
0105 
0106 // We provide a shadowed variable so that a `SECTION` inside non-`TEST_CASE`
0107 // tests can compile. The redefined `TEST_CASE` shadows this with param.
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 // CATCH_CONFIG_EXPERIMENTAL_STATIC_ANALYSIS_SUPPORT
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__ } ); /* NOLINT */ \
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     } /* NOLINT */ \
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__ } ); /* NOLINT */ \
0169             CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
0170         } while(false)
0171 
0172 
0173 #endif // CATCH_TEST_REGISTRY_HPP_INCLUDED