mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-26 07:16:10 +01:00
Add partial implementation of CATCH_CONFIG_DISABLE
* Assertions are defined into (void)(0) no-op * SECTIONs are defined away (leaving {} as scope) * TEST_CASEs and TEST_CASE_METHODs are not registered. * REGISTER_TEST_CASE is defined into (void)(0) no-op * METHOD_AS_TEST_CASE is defined away
This commit is contained in:
parent
2a13593885
commit
053c29a2b8
@ -73,6 +73,7 @@ This can be useful on certain platforms that do not provide the standard iostrea
|
||||
CATCH_CONFIG_POSIX_SIGNALS // Enable handling POSIX signals
|
||||
CATCH_CONFIG_WINDOWS_CRTDBG // Enable leak checking using Windows's CRT Debug Heap
|
||||
CATCH_CONFIG_DISABLE_STRINGIFICATION // Disable stringifying the original expression
|
||||
CATCH_CONFIG_DISABLE // Disables assertions and test case registration
|
||||
|
||||
Currently Catch enables `CATCH_CONFIG_WINDOWS_SEH` only when compiled with MSVC, because some versions of MinGW do not have the necessary Win32 API support.
|
||||
|
||||
@ -97,6 +98,13 @@ _Note: If you define `CATCH_CONFIG_DISABLE_MATCHERS` in the same file as Catch's
|
||||
## `CATCH_CONFIG_DISABLE_STRINGIFICATION`
|
||||
This toggle enables a workaround for VS 2017 bug. For details see [known limitations](limitations.md#Visual Studio 2017 -- raw string literal in assert fails to compile)
|
||||
|
||||
## `CATCH_CONFIG_DISABLE`
|
||||
This toggle removes most of Catch from given file. This means that `TEST_CASE`s are not registered and assertions are turned into no-ops. Useful for keeping tests within implementation files (ie for functions with internal linkage), instead of in external files.
|
||||
|
||||
This feature is considered experimental and might change at any point.
|
||||
|
||||
_Inspired by Doctest's `DOCTEST_CONFIG_DISABLE`_
|
||||
|
||||
# Windows header clutter
|
||||
|
||||
On Windows Catch includes `windows.h`. To minimize global namespace clutter in the implementation file, it defines `NOMINMAX` and `WIN32_LEAN_AND_MEAN` before including it. You can control this behaviour via two macros:
|
||||
|
@ -9,6 +9,10 @@
|
||||
* Removed `Catch::toString` support
|
||||
* The new stringification machinery uses `Catch::StringMaker` specializations first and `operator<<` overloads second.
|
||||
* Removed legacy `SCOPED_MSG` and `SCOPED_INFO` macros
|
||||
* Removed `INTERNAL_CATCH_REGISTER_REPORTER`
|
||||
* `CATCH_REGISTER_REPORTER` should be used to register reporters
|
||||
* Removed legacy `[hide]` tag
|
||||
* `[.]`, `[.foo]` and `[!hide]` are still supported
|
||||
* Output into debugger is now colourized
|
||||
* `*_THROWS_AS(expr, exception_type)` now unconditionally appends `const&` to the exception type.
|
||||
* `CATCH_CONFIG_FAST_COMPILE` now affects the `CHECK_` family of assertions as well as `REQUIRE_` family of assertions
|
||||
@ -29,6 +33,14 @@
|
||||
* Catch uses new CLI parsing library (Clara)
|
||||
* Users can now easily add new command line options to the final executable
|
||||
* This also leads to some changes in `Catch::Session` interface
|
||||
* All parts of matchers can be removed from a TU by defining `CATCH_CONFIG_DISABLE_MATCHERS`
|
||||
* This can be used to somewhat speed up compilation times
|
||||
* An experimental implementation of `CATCH_CONFIG_DISABLE` has been added
|
||||
* Speeds up compilation by removing away Catch tests
|
||||
* Currently removes all assertions and prevents `TEST_CASE` registrations
|
||||
* Useful for implementing tests in source files
|
||||
* ie for functions in anonymous namespaces
|
||||
* Inspired by Doctest's `DOCTEST_CONFIG_DISABLE`
|
||||
|
||||
## Fixes
|
||||
|
||||
|
@ -72,6 +72,7 @@
|
||||
# undef CLARA_CONFIG_MAIN
|
||||
#endif
|
||||
|
||||
#if !defined(CATCH_CONFIG_DISABLE)
|
||||
//////
|
||||
// If this config identifier is defined then all CATCH macros are prefixed with CATCH_
|
||||
#ifdef CATCH_CONFIG_PREFIX_ALL
|
||||
@ -196,6 +197,134 @@
|
||||
|
||||
using Catch::Detail::Approx;
|
||||
|
||||
#else
|
||||
//////
|
||||
// If this config identifier is defined then all CATCH macros are prefixed with CATCH_
|
||||
#ifdef CATCH_CONFIG_PREFIX_ALL
|
||||
|
||||
#define CATCH_REQUIRE( ... ) (void)(0)
|
||||
#define CATCH_REQUIRE_FALSE( ... ) (void)(0)
|
||||
|
||||
#define CATCH_REQUIRE_THROWS( ... ) (void)(0)
|
||||
#define CATCH_REQUIRE_THROWS_AS( expr, exceptionType ) (void)(0)
|
||||
#define CATCH_REQUIRE_THROWS_WITH( expr, matcher ) (void)(0)
|
||||
#if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
|
||||
#define CATCH_REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0)
|
||||
#endif// CATCH_CONFIG_DISABLE_MATCHERS
|
||||
#define CATCH_REQUIRE_NOTHROW( ... ) (void)(0)
|
||||
|
||||
#define CATCH_CHECK( ... ) (void)(0)
|
||||
#define CATCH_CHECK_FALSE( ... ) (void)(0)
|
||||
#define CATCH_CHECKED_IF( ... ) if (__VA_ARGS__)
|
||||
#define CATCH_CHECKED_ELSE( ... ) if (!(__VA_ARGS__))
|
||||
#define CATCH_CHECK_NOFAIL( ... ) (void)(0)
|
||||
|
||||
#define CATCH_CHECK_THROWS( ... ) (void)(0)
|
||||
#define CATCH_CHECK_THROWS_AS( expr, exceptionType ) (void)(0)
|
||||
#define CATCH_CHECK_THROWS_WITH( expr, matcher ) (void)(0)
|
||||
#if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
|
||||
#define CATCH_CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0)
|
||||
#endif // CATCH_CONFIG_DISABLE_MATCHERS
|
||||
#define CATCH_CHECK_NOTHROW( ... ) (void)(0)
|
||||
|
||||
#if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
|
||||
#define CATCH_CHECK_THAT( arg, matcher ) (void)(0)
|
||||
|
||||
#define CATCH_REQUIRE_THAT( arg, matcher ) (void)(0)
|
||||
#endif // CATCH_CONFIG_DISABLE_MATCHERS
|
||||
|
||||
#define CATCH_INFO( msg ) (void)(0)
|
||||
#define CATCH_WARN( msg ) (void)(0)
|
||||
#define CATCH_CAPTURE( msg ) (void)(0)
|
||||
|
||||
#define CATCH_TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ))
|
||||
#define CATCH_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ))
|
||||
#define CATCH_METHOD_AS_TEST_CASE( method, ... )
|
||||
#define CATCH_REGISTER_TEST_CASE( Function, ... ) (void)(0)
|
||||
#define CATCH_SECTION( ... )
|
||||
#define CATCH_FAIL( ... ) (void)(0)
|
||||
#define CATCH_FAIL_CHECK( ... ) (void)(0)
|
||||
#define CATCH_SUCCEED( ... ) (void)(0)
|
||||
|
||||
#define CATCH_ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ))
|
||||
|
||||
// "BDD-style" convenience wrappers
|
||||
#define CATCH_SCENARIO( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ))
|
||||
#define CATCH_SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_METHOD_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), className )
|
||||
#define CATCH_GIVEN( desc )
|
||||
#define CATCH_WHEN( desc )
|
||||
#define CATCH_AND_WHEN( desc )
|
||||
#define CATCH_THEN( desc )
|
||||
#define CATCH_AND_THEN( desc )
|
||||
|
||||
// If CATCH_CONFIG_PREFIX_ALL is not defined then the CATCH_ prefix is not required
|
||||
#else
|
||||
|
||||
#define REQUIRE( ... ) (void)(0)
|
||||
#define REQUIRE_FALSE( ... ) (void)(0)
|
||||
|
||||
#define REQUIRE_THROWS( ... ) (void)(0)
|
||||
#define REQUIRE_THROWS_AS( expr, exceptionType ) (void)(0)
|
||||
#define REQUIRE_THROWS_WITH( expr, matcher ) (void)(0)
|
||||
#if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
|
||||
#define REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0)
|
||||
#endif // CATCH_CONFIG_DISABLE_MATCHERS
|
||||
#define REQUIRE_NOTHROW( ... ) (void)(0)
|
||||
|
||||
#define CHECK( ... ) (void)(0)
|
||||
#define CHECK_FALSE( ... ) (void)(0)
|
||||
#define CHECKED_IF( ... ) if (__VA_ARGS__)
|
||||
#define CHECKED_ELSE( ... ) if (!(__VA_ARGS__))
|
||||
#define CHECK_NOFAIL( ... ) (void)(0)
|
||||
|
||||
#define CHECK_THROWS( ... ) (void)(0)
|
||||
#define CHECK_THROWS_AS( expr, exceptionType ) (void)(0)
|
||||
#define CHECK_THROWS_WITH( expr, matcher ) (void)(0)
|
||||
#if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
|
||||
#define CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0)
|
||||
#endif // CATCH_CONFIG_DISABLE_MATCHERS
|
||||
#define CHECK_NOTHROW( ... ) (void)(0)
|
||||
|
||||
|
||||
#if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
|
||||
#define CHECK_THAT( arg, matcher ) (void)(0)
|
||||
|
||||
#define REQUIRE_THAT( arg, matcher ) (void)(0)
|
||||
#endif // CATCH_CONFIG_DISABLE_MATCHERS
|
||||
|
||||
#define INFO( msg ) (void)(0)
|
||||
#define WARN( msg ) (void)(0)
|
||||
#define CAPTURE( msg ) (void)(0)
|
||||
|
||||
#define TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ))
|
||||
#define TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ))
|
||||
#define METHOD_AS_TEST_CASE( method, ... )
|
||||
#define REGISTER_TEST_CASE( Function, ... ) (void)(0)
|
||||
#define SECTION( ... )
|
||||
#define FAIL( ... ) (void)(0)
|
||||
#define FAIL_CHECK( ... ) (void)(0)
|
||||
#define SUCCEED( ... ) (void)(0)
|
||||
#define ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ))
|
||||
|
||||
#endif
|
||||
|
||||
#define CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION( signature )
|
||||
|
||||
// "BDD-style" convenience wrappers
|
||||
#define SCENARIO( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ) )
|
||||
#define SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_METHOD_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), className )
|
||||
|
||||
#define GIVEN( desc )
|
||||
#define WHEN( desc )
|
||||
#define AND_WHEN( desc )
|
||||
#define THEN( desc )
|
||||
#define AND_THEN( desc )
|
||||
|
||||
using Catch::Detail::Approx;
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
#include "internal/catch_reenable_warnings.h"
|
||||
|
||||
#endif // TWOBLUECUBES_CATCH_HPP_INCLUDED
|
||||
|
@ -12,6 +12,8 @@
|
||||
#include "catch_message.h"
|
||||
#include "catch_interfaces_capture.h"
|
||||
|
||||
#if !defined(CATCH_CONFIG_DISABLE)
|
||||
|
||||
#if !defined(CATCH_CONFIG_DISABLE_STRINGIFICATION)
|
||||
#define CATCH_INTERNAL_STRINGIFY(...) #__VA_ARGS__
|
||||
#else
|
||||
@ -157,5 +159,6 @@
|
||||
INTERNAL_CATCH_REACT( catchAssertionHandler ) \
|
||||
} while( Catch::alwaysFalse() )
|
||||
|
||||
#endif // CATCH_CONFIG_DISABLE
|
||||
|
||||
#endif // TWOBLUECUBES_CATCH_CAPTURE_HPP_INCLUDED
|
||||
|
@ -47,6 +47,19 @@ struct AutoReg : NonCopyable {
|
||||
|
||||
} // end namespace Catch
|
||||
|
||||
#if defined(CATCH_CONFIG_DISABLE)
|
||||
#define INTERNAL_CATCH_TESTCASE_NO_REGISTRATION( TestName, ... ) \
|
||||
static void TestName()
|
||||
#define INTERNAL_CATCH_TESTCASE_METHOD_NO_REGISTRATION( TestName, ClassName, ... ) \
|
||||
namespace{ \
|
||||
struct TestName : ClassName { \
|
||||
void test(); \
|
||||
}; \
|
||||
} \
|
||||
void TestName::test()
|
||||
|
||||
#endif
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#define INTERNAL_CATCH_TESTCASE2( TestName, ... ) \
|
||||
static void TestName(); \
|
||||
|
Loading…
Reference in New Issue
Block a user