diff options
| author | Martin Hořeňovský | 2017-07-28 21:34:34 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2017-07-28 21:34:34 +0200 |
| commit | 0ca4cfb7432d37dbca4164c274a6b4f6e37d2dd4 (patch) | |
| tree | 80fbcb75f48ca7ddf6695f2ba8e2a454187111d0 /include | |
| parent | 35c1301bd58222eace4afe61b666b580a0814d4e (diff) | |
| download | catch3-0ca4cfb7432d37dbca4164c274a6b4f6e37d2dd4.tar.gz | |
Introduce compile time toggle to remove Matchers from TU
The toggle is `CATCH_CONFIG_DISABLE_MATCHERS` and the only use is
to speed up compilation of small TUs. For large ones it is likely
insignificant, because the speed up is constant relative to
number of tests/assertions in TU.
Diffstat (limited to 'include')
| -rw-r--r-- | include/catch.hpp | 18 | ||||
| -rw-r--r-- | include/internal/catch_capture.hpp | 7 | ||||
| -rw-r--r-- | include/internal/catch_matchers.cpp | 4 | ||||
| -rw-r--r-- | include/internal/catch_matchers.hpp | 4 | ||||
| -rw-r--r-- | include/internal/catch_matchers_string.cpp | 4 | ||||
| -rw-r--r-- | include/internal/catch_matchers_string.h | 4 | ||||
| -rw-r--r-- | include/internal/catch_matchers_vector.h | 5 | ||||
| -rw-r--r-- | include/internal/catch_objc.hpp | 4 | ||||
| -rw-r--r-- | include/internal/catch_result_builder.cpp | 4 | ||||
| -rw-r--r-- | include/internal/catch_result_builder.h | 2 |
10 files changed, 47 insertions, 9 deletions
diff --git a/include/catch.hpp b/include/catch.hpp index a58fdb1c..ead6c337 100644 --- a/include/catch.hpp +++ b/include/catch.hpp @@ -63,7 +63,6 @@ #endif ////// - // If this config identifier is defined then all CATCH macros are prefixed with CATCH_ #ifdef CATCH_CONFIG_PREFIX_ALL @@ -77,8 +76,10 @@ #define CATCH_REQUIRE_THROWS( ... ) INTERNAL_CATCH_THROWS( "CATCH_REQUIRE_THROWS", Catch::ResultDisposition::Normal, "", __VA_ARGS__ ) #define CATCH_REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CATCH_REQUIRE_THROWS_AS", exceptionType, Catch::ResultDisposition::Normal, expr ) +#if defined(CATCH_CONFIG_DISABLE_MATCHERS) #define CATCH_REQUIRE_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "CATCH_REQUIRE_THROWS_WITH", Catch::ResultDisposition::Normal, matcher, expr ) #define CATCH_REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "CATCH_REQUIRE_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::Normal, matcher, expr ) +#endif// CATCH_CONFIG_DISABLE_MATCHERS #define CATCH_REQUIRE_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "CATCH_REQUIRE_NOTHROW", Catch::ResultDisposition::Normal, __VA_ARGS__ ) #define CATCH_CHECK( ... ) INTERNAL_CATCH_TEST( "CATCH_CHECK", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) @@ -89,10 +90,13 @@ #define CATCH_CHECK_THROWS( ... ) INTERNAL_CATCH_THROWS( "CATCH_CHECK_THROWS", Catch::ResultDisposition::ContinueOnFailure, "", __VA_ARGS__ ) #define CATCH_CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CATCH_CHECK_THROWS_AS", exceptionType, Catch::ResultDisposition::ContinueOnFailure, expr ) +#if defined(CATCH_CONFIG_DISABLE_MATCHERS) #define CATCH_CHECK_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "CATCH_CHECK_THROWS_WITH", Catch::ResultDisposition::ContinueOnFailure, matcher, expr ) #define CATCH_CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "CATCH_CHECK_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::ContinueOnFailure, matcher, expr ) +#endif // CATCH_CONFIG_DISABLE_MATCHERS #define CATCH_CHECK_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "CATCH_CHECK_NOTHROW", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) +#if defined(CATCH_CONFIG_DISABLE_MATCHERS) #define CATCH_CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CATCH_CHECK_THAT", matcher, Catch::ResultDisposition::ContinueOnFailure, arg ) #if defined(CATCH_CONFIG_FAST_COMPILE) @@ -100,7 +104,7 @@ #else #define CATCH_REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CATCH_REQUIRE_THAT", matcher, Catch::ResultDisposition::Normal, arg ) #endif - +#endif // CATCH_CONFIG_DISABLE_MATCHERS #define CATCH_INFO( msg ) INTERNAL_CATCH_INFO( "CATCH_INFO", msg ) #define CATCH_WARN( msg ) INTERNAL_CATCH_MSG( "CATCH_WARN", Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, msg ) @@ -144,8 +148,10 @@ #define REQUIRE_THROWS( ... ) INTERNAL_CATCH_THROWS( "REQUIRE_THROWS", Catch::ResultDisposition::Normal, __VA_ARGS__ ) #define REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "REQUIRE_THROWS_AS", exceptionType, Catch::ResultDisposition::Normal, expr ) +#if defined(CATCH_CONFIG_DISABLE_MATCHERS) #define REQUIRE_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "REQUIRE_THROWS_WITH", Catch::ResultDisposition::Normal, matcher, expr ) #define REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "REQUIRE_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::Normal, matcher, expr ) +#endif // CATCH_CONFIG_DISABLE_MATCHERS #define REQUIRE_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "REQUIRE_NOTHROW", Catch::ResultDisposition::Normal, __VA_ARGS__ ) #define CHECK( ... ) INTERNAL_CATCH_TEST( "CHECK", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) @@ -156,18 +162,22 @@ #define CHECK_THROWS( ... ) INTERNAL_CATCH_THROWS( "CHECK_THROWS", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) #define CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CHECK_THROWS_AS", exceptionType, Catch::ResultDisposition::ContinueOnFailure, expr ) +#if defined(CATCH_CONFIG_DISABLE_MATCHERS) #define CHECK_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "CHECK_THROWS_WITH", Catch::ResultDisposition::ContinueOnFailure, matcher, expr ) #define CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "CHECK_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::ContinueOnFailure, matcher, expr ) +#endif // CATCH_CONFIG_DISABLE_MATCHERS #define CHECK_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "CHECK_NOTHROW", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) + +#if defined(CATCH_CONFIG_DISABLE_MATCHERS) #define CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CHECK_THAT", matcher, Catch::ResultDisposition::ContinueOnFailure, arg ) #if defined(CATCH_CONFIG_FAST_COMPILE) #define REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT_NO_TRY( "REQUIRE_THAT", matcher, Catch::ResultDisposition::Normal, arg ) #else #define REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "REQUIRE_THAT", matcher, Catch::ResultDisposition::Normal, arg ) -#endif - +#endif // CATCH_CONFIG_FAST_COMPILE +#endif // CATCH_CONFIG_DISABLE_MATCHERS #define INFO( msg ) INTERNAL_CATCH_INFO( "INFO", msg ) #define WARN( msg ) INTERNAL_CATCH_MSG( "WARN", Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, msg ) diff --git a/include/internal/catch_capture.hpp b/include/internal/catch_capture.hpp index 1c862505..fa6952e4 100644 --- a/include/internal/catch_capture.hpp +++ b/include/internal/catch_capture.hpp @@ -42,7 +42,7 @@ INTERNAL_CATCH_REACT( __catchResult ) \ } while( Catch::isTrue( false && static_cast<bool>( !!(expr) ) ) ) // expr here is never evaluated at runtime but it forces the compiler to give it a look // The double negation silences MSVC's C4800 warning, the static_cast forces short-circuit evaluation if the type has overloaded &&. - +#if defined(CATCH_CONFIG_DISABLE_MATCHERS) #define INTERNAL_CHECK_THAT_NO_TRY( macroName, matcher, resultDisposition, arg ) \ do { \ Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #arg ", " #matcher, resultDisposition ); \ @@ -51,7 +51,7 @@ __catchResult.unsetExceptionGuard(); \ INTERNAL_CATCH_REACT( __catchResult ) \ } while( Catch::alwaysFalse() ) - +#endif // CATCH_CONFIG_DISABLE_MATCHERS #else /////////////////////////////////////////////////////////////////////////////// // In the event of a failure works out if the debugger needs to be invoked @@ -155,6 +155,7 @@ #define INTERNAL_CATCH_INFO( macroName, log ) \ Catch::ScopedMessage INTERNAL_CATCH_UNIQUE_NAME( scopedMessage ) = Catch::MessageBuilder( macroName, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log; +#if defined(CATCH_CONFIG_DISABLE_MATCHERS) /////////////////////////////////////////////////////////////////////////////// #define INTERNAL_CHECK_THAT( macroName, matcher, resultDisposition, arg ) \ do { \ @@ -204,7 +205,7 @@ __catchResult.captureResult( Catch::ResultWas::Ok ); \ INTERNAL_CATCH_REACT( __catchResult ) \ } while( Catch::alwaysFalse() ) - +#endif // CATCH_CONFIG_DISABLE_MATCHERS #endif // TWOBLUECUBES_CATCH_CAPTURE_HPP_INCLUDED diff --git a/include/internal/catch_matchers.cpp b/include/internal/catch_matchers.cpp index 38ae8c77..a2620bc5 100644 --- a/include/internal/catch_matchers.cpp +++ b/include/internal/catch_matchers.cpp @@ -5,6 +5,8 @@ * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */ +#if defined(CATCH_CONFIG_DISABLE_MATCHERS) + #include "catch_matchers.hpp" namespace Catch { @@ -24,3 +26,5 @@ using namespace Matchers; using Matchers::Impl::MatcherBase; } // namespace Catch + +#endif // CATCH_CONFIG_DISABLE_MATCHERS
\ No newline at end of file diff --git a/include/internal/catch_matchers.hpp b/include/internal/catch_matchers.hpp index 4f41cb01..37787a9c 100644 --- a/include/internal/catch_matchers.hpp +++ b/include/internal/catch_matchers.hpp @@ -8,6 +8,8 @@ #ifndef TWOBLUECUBES_CATCH_MATCHERS_HPP_INCLUDED #define TWOBLUECUBES_CATCH_MATCHERS_HPP_INCLUDED +#if defined(CATCH_CONFIG_DISABLE_MATCHERS) + #include "catch_common.h" #include <vector> @@ -179,4 +181,6 @@ using Matchers::Impl::MatcherBase; } // namespace Catch +#endif // CATCH_CONFIG_DISABLE_MATCHERS + #endif // TWOBLUECUBES_CATCH_MATCHERS_HPP_INCLUDED diff --git a/include/internal/catch_matchers_string.cpp b/include/internal/catch_matchers_string.cpp index 2f8ffdb8..54f44d6d 100644 --- a/include/internal/catch_matchers_string.cpp +++ b/include/internal/catch_matchers_string.cpp @@ -6,6 +6,8 @@ * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */ +#if defined(CATCH_CONFIG_DISABLE_MATCHERS) + #include "catch_matchers_string.h" #include "catch_string_manip.h" @@ -92,3 +94,5 @@ namespace Matchers { } // namespace Matchers } // namespace Catch + +#endif // CATCH_CONFIG_DISABLE_MATCHERS diff --git a/include/internal/catch_matchers_string.h b/include/internal/catch_matchers_string.h index eca35789..ab3f1c44 100644 --- a/include/internal/catch_matchers_string.h +++ b/include/internal/catch_matchers_string.h @@ -8,6 +8,8 @@ #ifndef TWOBLUECUBES_CATCH_MATCHERS_STRING_H_INCLUDED #define TWOBLUECUBES_CATCH_MATCHERS_STRING_H_INCLUDED +#if defined(CATCH_CONFIG_DISABLE_MATCHERS) + #include "catch_matchers.hpp" #include <string> @@ -66,4 +68,6 @@ namespace Matchers { } // namespace Matchers } // namespace Catch +#endif // CATCH_CONFIG_DISABLE_MATCHERS + #endif // TWOBLUECUBES_CATCH_MATCHERS_STRING_H_INCLUDED diff --git a/include/internal/catch_matchers_vector.h b/include/internal/catch_matchers_vector.h index 4bf39d70..de1c52b2 100644 --- a/include/internal/catch_matchers_vector.h +++ b/include/internal/catch_matchers_vector.h @@ -8,6 +8,9 @@ #ifndef TWOBLUECUBES_CATCH_MATCHERS_VECTOR_H_INCLUDED #define TWOBLUECUBES_CATCH_MATCHERS_VECTOR_H_INCLUDED +#if defined(CATCH_CONFIG_DISABLE_MATCHERS) + + #include "catch_matchers.hpp" namespace Catch { @@ -112,4 +115,6 @@ namespace Matchers { } // namespace Matchers } // namespace Catch +#endif // CATCH_CONFIG_DISABLE_MATCHERS + #endif // TWOBLUECUBES_CATCH_MATCHERS_VECTOR_H_INCLUDED diff --git a/include/internal/catch_objc.hpp b/include/internal/catch_objc.hpp index 350dc72c..2a8ec2f9 100644 --- a/include/internal/catch_objc.hpp +++ b/include/internal/catch_objc.hpp @@ -101,6 +101,8 @@ namespace Catch { return noTestMethods; } +#if defined(CATCH_CONFIG_DISABLE_MATCHERS) + namespace Matchers { namespace Impl { namespace NSStringMatchers { @@ -189,6 +191,8 @@ namespace Catch { using namespace Matchers; +#endif // CATCH_CONFIG_DISABLE_MATCHERS + } // namespace Catch /////////////////////////////////////////////////////////////////////////////// diff --git a/include/internal/catch_result_builder.cpp b/include/internal/catch_result_builder.cpp index a1fed54e..cf0b1b16 100644 --- a/include/internal/catch_result_builder.cpp +++ b/include/internal/catch_result_builder.cpp @@ -72,7 +72,7 @@ namespace Catch { setResultType( resultType ); captureExpression(); } - +#if defined(CATCH_CONFIG_DISABLE_MATCHERS) void ResultBuilder::captureExpectedException( std::string const& expectedMessage ) { if( expectedMessage.empty() ) captureExpectedException( Matchers::Impl::MatchAllOf<std::string>() ); @@ -96,7 +96,7 @@ namespace Catch { AssertionResult result( m_assertionInfo, data ); handleResult( result ); } - +#endif // CATCH_CONFIG_DISABLE_MATCHERS void ResultBuilder::captureExpression() { AssertionResult result = build(); handleResult( result ); diff --git a/include/internal/catch_result_builder.h b/include/internal/catch_result_builder.h index 45bc8920..2b5dd145 100644 --- a/include/internal/catch_result_builder.h +++ b/include/internal/catch_result_builder.h @@ -58,8 +58,10 @@ namespace Catch { void useActiveException( ResultDisposition::Flags resultDisposition = ResultDisposition::Normal ); void captureResult( ResultWas::OfType resultType ); void captureExpression(); +#if defined(CATCH_CONFIG_DISABLE_MATCHERS) void captureExpectedException( std::string const& expectedMessage ); void captureExpectedException( Matchers::Impl::MatcherBase<std::string> const& matcher ); +#endif // CATCH_CONFIG_DISABLE_MATCHERS void handleResult( AssertionResult const& result ); void react(); bool shouldDebugBreak() const; |