Back to home page

EIC code displayed by LXR

 
 

    


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

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_MESSAGE_HPP_INCLUDED
0009 #define CATCH_MESSAGE_HPP_INCLUDED
0010 
0011 #include <catch2/internal/catch_result_type.hpp>
0012 #include <catch2/internal/catch_reusable_string_stream.hpp>
0013 #include <catch2/internal/catch_stream_end_stop.hpp>
0014 #include <catch2/internal/catch_message_info.hpp>
0015 #include <catch2/catch_tostring.hpp>
0016 
0017 #include <string>
0018 #include <vector>
0019 
0020 namespace Catch {
0021 
0022     struct SourceLineInfo;
0023     class IResultCapture;
0024 
0025     struct MessageStream {
0026 
0027         template<typename T>
0028         MessageStream& operator << ( T const& value ) {
0029             m_stream << value;
0030             return *this;
0031         }
0032 
0033         ReusableStringStream m_stream;
0034     };
0035 
0036     struct MessageBuilder : MessageStream {
0037         MessageBuilder( StringRef macroName,
0038                         SourceLineInfo const& lineInfo,
0039                         ResultWas::OfType type ):
0040             m_info(macroName, lineInfo, type) {}
0041 
0042         template<typename T>
0043         MessageBuilder&& operator << ( T const& value ) && {
0044             m_stream << value;
0045             return CATCH_MOVE(*this);
0046         }
0047 
0048         MessageInfo m_info;
0049     };
0050 
0051     class ScopedMessage {
0052     public:
0053         explicit ScopedMessage( MessageBuilder&& builder );
0054         ScopedMessage( ScopedMessage& duplicate ) = delete;
0055         ScopedMessage( ScopedMessage&& old ) noexcept;
0056         ~ScopedMessage();
0057 
0058         MessageInfo m_info;
0059         bool m_moved = false;
0060     };
0061 
0062     class Capturer {
0063         std::vector<MessageInfo> m_messages;
0064         IResultCapture& m_resultCapture;
0065         size_t m_captured = 0;
0066     public:
0067         Capturer( StringRef macroName, SourceLineInfo const& lineInfo, ResultWas::OfType resultType, StringRef names );
0068 
0069         Capturer(Capturer const&) = delete;
0070         Capturer& operator=(Capturer const&) = delete;
0071 
0072         ~Capturer();
0073 
0074         void captureValue( size_t index, std::string const& value );
0075 
0076         template<typename T>
0077         void captureValues( size_t index, T const& value ) {
0078             captureValue( index, Catch::Detail::stringify( value ) );
0079         }
0080 
0081         template<typename T, typename... Ts>
0082         void captureValues( size_t index, T const& value, Ts const&... values ) {
0083             captureValue( index, Catch::Detail::stringify(value) );
0084             captureValues( index+1, values... );
0085         }
0086     };
0087 
0088 } // end namespace Catch
0089 
0090 ///////////////////////////////////////////////////////////////////////////////
0091 #define INTERNAL_CATCH_MSG( macroName, messageType, resultDisposition, ... ) \
0092     do { \
0093         Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, Catch::StringRef(), resultDisposition ); \
0094         catchAssertionHandler.handleMessage( messageType, ( Catch::MessageStream() << __VA_ARGS__ + ::Catch::StreamEndStop() ).m_stream.str() ); \
0095         INTERNAL_CATCH_REACT( catchAssertionHandler ) \
0096     } while( false )
0097 
0098 ///////////////////////////////////////////////////////////////////////////////
0099 #define INTERNAL_CATCH_CAPTURE( varName, macroName, ... ) \
0100     Catch::Capturer varName( macroName##_catch_sr,        \
0101                              CATCH_INTERNAL_LINEINFO,     \
0102                              Catch::ResultWas::Info,      \
0103                              #__VA_ARGS__##_catch_sr );   \
0104     varName.captureValues( 0, __VA_ARGS__ )
0105 
0106 ///////////////////////////////////////////////////////////////////////////////
0107 #define INTERNAL_CATCH_INFO( macroName, log ) \
0108     const Catch::ScopedMessage INTERNAL_CATCH_UNIQUE_NAME( scopedMessage )( Catch::MessageBuilder( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log )
0109 
0110 ///////////////////////////////////////////////////////////////////////////////
0111 #define INTERNAL_CATCH_UNSCOPED_INFO( macroName, log ) \
0112     Catch::getResultCapture().emplaceUnscopedMessage( Catch::MessageBuilder( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log )
0113 
0114 
0115 #if defined(CATCH_CONFIG_PREFIX_ALL) && !defined(CATCH_CONFIG_DISABLE)
0116 
0117   #define CATCH_INFO( msg ) INTERNAL_CATCH_INFO( "CATCH_INFO", msg )
0118   #define CATCH_UNSCOPED_INFO( msg ) INTERNAL_CATCH_UNSCOPED_INFO( "CATCH_UNSCOPED_INFO", msg )
0119   #define CATCH_WARN( msg ) INTERNAL_CATCH_MSG( "CATCH_WARN", Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, msg )
0120   #define CATCH_CAPTURE( ... ) INTERNAL_CATCH_CAPTURE( INTERNAL_CATCH_UNIQUE_NAME(capturer), "CATCH_CAPTURE", __VA_ARGS__ )
0121 
0122 #elif defined(CATCH_CONFIG_PREFIX_ALL) && defined(CATCH_CONFIG_DISABLE)
0123 
0124   #define CATCH_INFO( msg )          (void)(0)
0125   #define CATCH_UNSCOPED_INFO( msg ) (void)(0)
0126   #define CATCH_WARN( msg )          (void)(0)
0127   #define CATCH_CAPTURE( ... )       (void)(0)
0128 
0129 #elif !defined(CATCH_CONFIG_PREFIX_ALL) && !defined(CATCH_CONFIG_DISABLE)
0130 
0131   #define INFO( msg ) INTERNAL_CATCH_INFO( "INFO", msg )
0132   #define UNSCOPED_INFO( msg ) INTERNAL_CATCH_UNSCOPED_INFO( "UNSCOPED_INFO", msg )
0133   #define WARN( msg ) INTERNAL_CATCH_MSG( "WARN", Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, msg )
0134   #define CAPTURE( ... ) INTERNAL_CATCH_CAPTURE( INTERNAL_CATCH_UNIQUE_NAME(capturer), "CAPTURE", __VA_ARGS__ )
0135 
0136 #elif !defined(CATCH_CONFIG_PREFIX_ALL) && defined(CATCH_CONFIG_DISABLE)
0137 
0138   #define INFO( msg )          (void)(0)
0139   #define UNSCOPED_INFO( msg ) (void)(0)
0140   #define WARN( msg )          (void)(0)
0141   #define CAPTURE( ... )       (void)(0)
0142 
0143 #endif // end of user facing macro declarations
0144 
0145 
0146 
0147 
0148 #endif // CATCH_MESSAGE_HPP_INCLUDED