mirror of
				https://github.com/catchorg/Catch2.git
				synced 2025-10-31 20:27:11 +01:00 
			
		
		
		
	Construct StringRef from constant strings in macros directly using UDL
This avoids having to call `strlen` to get the constant string's length and thus should improve performance.
This commit is contained in:
		| @@ -9,8 +9,9 @@ | ||||
| #define TWOBLUECUBES_CATCH_CAPTURE_HPP_INCLUDED | ||||
|  | ||||
| #include "catch_assertionhandler.h" | ||||
| #include "catch_message.h" | ||||
| #include "catch_interfaces_capture.h" | ||||
| #include "catch_message.h" | ||||
| #include "catch_stringref.h" | ||||
|  | ||||
| #if !defined(CATCH_CONFIG_DISABLE) | ||||
|  | ||||
| @@ -40,7 +41,7 @@ | ||||
| /////////////////////////////////////////////////////////////////////////////// | ||||
| #define INTERNAL_CATCH_TEST( macroName, resultDisposition, ... ) \ | ||||
|     do { \ | ||||
|         Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition ); \ | ||||
|         Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition ); \ | ||||
|         INTERNAL_CATCH_TRY { \ | ||||
|             CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \ | ||||
|             catchAssertionHandler.handleExpr( Catch::Decomposer() <= __VA_ARGS__ ); \ | ||||
| @@ -63,7 +64,7 @@ | ||||
| /////////////////////////////////////////////////////////////////////////////// | ||||
| #define INTERNAL_CATCH_NO_THROW( macroName, resultDisposition, ... ) \ | ||||
|     do { \ | ||||
|         Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition ); \ | ||||
|         Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition ); \ | ||||
|         try { \ | ||||
|             static_cast<void>(__VA_ARGS__); \ | ||||
|             catchAssertionHandler.handleExceptionNotThrownAsExpected(); \ | ||||
| @@ -77,7 +78,7 @@ | ||||
| /////////////////////////////////////////////////////////////////////////////// | ||||
| #define INTERNAL_CATCH_THROWS( macroName, resultDisposition, ... ) \ | ||||
|     do { \ | ||||
|         Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition); \ | ||||
|         Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition); \ | ||||
|         if( catchAssertionHandler.allowThrows() ) \ | ||||
|             try { \ | ||||
|                 static_cast<void>(__VA_ARGS__); \ | ||||
| @@ -94,7 +95,7 @@ | ||||
| /////////////////////////////////////////////////////////////////////////////// | ||||
| #define INTERNAL_CATCH_THROWS_AS( macroName, exceptionType, resultDisposition, expr ) \ | ||||
|     do { \ | ||||
|         Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(expr) ", " CATCH_INTERNAL_STRINGIFY(exceptionType), resultDisposition ); \ | ||||
|         Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(expr) ", " CATCH_INTERNAL_STRINGIFY(exceptionType), resultDisposition ); \ | ||||
|         if( catchAssertionHandler.allowThrows() ) \ | ||||
|             try { \ | ||||
|                 static_cast<void>(expr); \ | ||||
| @@ -115,27 +116,27 @@ | ||||
| /////////////////////////////////////////////////////////////////////////////// | ||||
| #define INTERNAL_CATCH_MSG( macroName, messageType, resultDisposition, ... ) \ | ||||
|     do { \ | ||||
|         Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, Catch::StringRef(), resultDisposition ); \ | ||||
|         Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, Catch::StringRef(), resultDisposition ); \ | ||||
|         catchAssertionHandler.handleMessage( messageType, ( Catch::MessageStream() << __VA_ARGS__ + ::Catch::StreamEndStop() ).m_stream.str() ); \ | ||||
|         INTERNAL_CATCH_REACT( catchAssertionHandler ) \ | ||||
|     } while( false ) | ||||
|  | ||||
| /////////////////////////////////////////////////////////////////////////////// | ||||
| #define INTERNAL_CATCH_INFO( macroName, log ) \ | ||||
|     Catch::ScopedMessage INTERNAL_CATCH_UNIQUE_NAME( scopedMessage )( Catch::MessageBuilder( macroName, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log ); | ||||
|     Catch::ScopedMessage INTERNAL_CATCH_UNIQUE_NAME( scopedMessage )( Catch::MessageBuilder( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log ); | ||||
|  | ||||
| /////////////////////////////////////////////////////////////////////////////// | ||||
| // Although this is matcher-based, it can be used with just a string | ||||
| #define INTERNAL_CATCH_THROWS_STR_MATCHES( macroName, resultDisposition, matcher, ... ) \ | ||||
|     do { \ | ||||
|         Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \ | ||||
|         Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \ | ||||
|         if( catchAssertionHandler.allowThrows() ) \ | ||||
|             try { \ | ||||
|                 static_cast<void>(__VA_ARGS__); \ | ||||
|                 catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \ | ||||
|             } \ | ||||
|             catch( ... ) { \ | ||||
|                 Catch::handleExceptionMatchExpr( catchAssertionHandler, matcher, #matcher ); \ | ||||
|                 Catch::handleExceptionMatchExpr( catchAssertionHandler, matcher, #matcher##_catch_sr ); \ | ||||
|             } \ | ||||
|         else \ | ||||
|             catchAssertionHandler.handleThrowingCallSkipped(); \ | ||||
|   | ||||
| @@ -14,6 +14,7 @@ | ||||
| #include "catch_matchers_generic.hpp" | ||||
| #include "catch_matchers_string.h" | ||||
| #include "catch_matchers_vector.h" | ||||
| #include "catch_stringref.h" | ||||
|  | ||||
| namespace Catch { | ||||
|  | ||||
| @@ -55,9 +56,9 @@ namespace Catch { | ||||
| /////////////////////////////////////////////////////////////////////////////// | ||||
| #define INTERNAL_CHECK_THAT( macroName, matcher, resultDisposition, arg ) \ | ||||
|     do { \ | ||||
|         Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(arg) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \ | ||||
|         Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(arg) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \ | ||||
|         INTERNAL_CATCH_TRY { \ | ||||
|             catchAssertionHandler.handleExpr( Catch::makeMatchExpr( arg, matcher, #matcher ) ); \ | ||||
|             catchAssertionHandler.handleExpr( Catch::makeMatchExpr( arg, matcher, #matcher##_catch_sr ) ); \ | ||||
|         } INTERNAL_CATCH_CATCH( catchAssertionHandler ) \ | ||||
|         INTERNAL_CATCH_REACT( catchAssertionHandler ) \ | ||||
|     } while( false ) | ||||
| @@ -66,14 +67,14 @@ namespace Catch { | ||||
| /////////////////////////////////////////////////////////////////////////////// | ||||
| #define INTERNAL_CATCH_THROWS_MATCHES( macroName, exceptionType, resultDisposition, matcher, ... ) \ | ||||
|     do { \ | ||||
|         Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__) ", " CATCH_INTERNAL_STRINGIFY(exceptionType) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \ | ||||
|         Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__) ", " CATCH_INTERNAL_STRINGIFY(exceptionType) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \ | ||||
|         if( catchAssertionHandler.allowThrows() ) \ | ||||
|             try { \ | ||||
|                 static_cast<void>(__VA_ARGS__ ); \ | ||||
|                 catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \ | ||||
|             } \ | ||||
|             catch( exceptionType const& ex ) { \ | ||||
|                 catchAssertionHandler.handleExpr( Catch::makeMatchExpr( ex, matcher, #matcher ) ); \ | ||||
|                 catchAssertionHandler.handleExpr( Catch::makeMatchExpr( ex, matcher, #matcher##_catch_sr ) ); \ | ||||
|             } \ | ||||
|             catch( ... ) { \ | ||||
|                 catchAssertionHandler.handleUnexpectedInflightException(); \ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Martin Hořeňovský
					Martin Hořeňovský