2020-08-30 15:43:45 +02:00
|
|
|
|
|
|
|
|
// Copyright Catch2 Authors
|
|
|
|
|
// Distributed under the Boost Software License, Version 1.0.
|
2022-10-28 11:22:53 +02:00
|
|
|
// (See accompanying file LICENSE.txt or copy at
|
2020-08-30 15:43:45 +02:00
|
|
|
// https://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
|
|
|
|
|
|
// SPDX-License-Identifier: BSL-1.0
|
2020-08-29 20:48:32 +02:00
|
|
|
#ifndef CATCH_MESSAGE_HPP_INCLUDED
|
|
|
|
|
#define CATCH_MESSAGE_HPP_INCLUDED
|
2013-02-02 19:58:04 +00:00
|
|
|
|
2023-07-19 17:04:43 +02:00
|
|
|
#include <catch2/internal/catch_config_prefix_messages.hpp>
|
2020-03-30 10:34:21 +02:00
|
|
|
#include <catch2/internal/catch_result_type.hpp>
|
2022-04-16 15:00:41 +02:00
|
|
|
#include <catch2/internal/catch_reusable_string_stream.hpp>
|
2020-11-27 10:43:07 +01:00
|
|
|
#include <catch2/internal/catch_stream_end_stop.hpp>
|
2020-05-10 16:44:27 +02:00
|
|
|
#include <catch2/internal/catch_message_info.hpp>
|
2020-03-30 10:34:21 +02:00
|
|
|
#include <catch2/catch_tostring.hpp>
|
2023-11-04 00:31:45 +01:00
|
|
|
#include <catch2/interfaces/catch_interfaces_capture.hpp>
|
2018-06-27 21:34:35 +01:00
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
2013-02-02 19:58:04 +00:00
|
|
|
|
|
|
|
|
namespace Catch {
|
2013-07-03 19:14:59 +01:00
|
|
|
|
2020-11-27 10:43:07 +01:00
|
|
|
struct SourceLineInfo;
|
2023-03-22 19:12:03 +01:00
|
|
|
class IResultCapture;
|
2020-11-27 10:43:07 +01:00
|
|
|
|
2017-08-08 20:17:09 +01:00
|
|
|
struct MessageStream {
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
|
MessageStream& operator << ( T const& value ) {
|
|
|
|
|
m_stream << value;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-07 18:01:10 +00:00
|
|
|
ReusableStringStream m_stream;
|
2017-08-08 20:17:09 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct MessageBuilder : MessageStream {
|
2021-05-14 16:00:15 +02:00
|
|
|
MessageBuilder( StringRef macroName,
|
2013-06-28 17:09:57 +01:00
|
|
|
SourceLineInfo const& lineInfo,
|
2021-05-14 16:00:15 +02:00
|
|
|
ResultWas::OfType type ):
|
|
|
|
|
m_info(macroName, lineInfo, type) {}
|
|
|
|
|
|
2013-02-02 19:58:04 +00:00
|
|
|
template<typename T>
|
2023-01-28 22:01:34 +01:00
|
|
|
MessageBuilder&& operator << ( T const& value ) && {
|
2013-06-28 17:09:57 +01:00
|
|
|
m_stream << value;
|
2023-01-28 22:01:34 +01:00
|
|
|
return CATCH_MOVE(*this);
|
2013-02-02 19:58:04 +00:00
|
|
|
}
|
2013-06-28 17:09:57 +01:00
|
|
|
|
|
|
|
|
MessageInfo m_info;
|
2013-02-02 19:58:04 +00:00
|
|
|
};
|
2013-06-28 17:09:57 +01:00
|
|
|
|
|
|
|
|
class ScopedMessage {
|
2013-02-02 19:58:04 +00:00
|
|
|
public:
|
2023-01-28 22:01:34 +01:00
|
|
|
explicit ScopedMessage( MessageBuilder&& builder );
|
2019-02-01 09:11:30 -06:00
|
|
|
ScopedMessage( ScopedMessage& duplicate ) = delete;
|
2020-08-19 17:44:22 +02:00
|
|
|
ScopedMessage( ScopedMessage&& old ) noexcept;
|
2013-06-28 17:09:57 +01:00
|
|
|
~ScopedMessage();
|
|
|
|
|
|
2025-08-26 12:36:06 +02:00
|
|
|
unsigned int m_messageId;
|
2020-08-19 17:44:22 +02:00
|
|
|
bool m_moved = false;
|
2013-02-02 19:58:04 +00:00
|
|
|
};
|
|
|
|
|
|
2018-06-27 21:34:35 +01:00
|
|
|
class Capturer {
|
|
|
|
|
std::vector<MessageInfo> m_messages;
|
|
|
|
|
size_t m_captured = 0;
|
|
|
|
|
public:
|
|
|
|
|
Capturer( StringRef macroName, SourceLineInfo const& lineInfo, ResultWas::OfType resultType, StringRef names );
|
2020-05-12 13:51:58 +02:00
|
|
|
|
|
|
|
|
Capturer(Capturer const&) = delete;
|
|
|
|
|
Capturer& operator=(Capturer const&) = delete;
|
|
|
|
|
|
2018-06-27 21:34:35 +01:00
|
|
|
~Capturer();
|
|
|
|
|
|
2018-11-19 23:06:06 +01:00
|
|
|
void captureValue( size_t index, std::string const& value );
|
2018-06-27 21:34:35 +01:00
|
|
|
|
|
|
|
|
template<typename T>
|
2018-11-19 23:06:06 +01:00
|
|
|
void captureValues( size_t index, T const& value ) {
|
2018-06-27 21:34:35 +01:00
|
|
|
captureValue( index, Catch::Detail::stringify( value ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename T, typename... Ts>
|
2018-11-19 23:06:06 +01:00
|
|
|
void captureValues( size_t index, T const& value, Ts const&... values ) {
|
|
|
|
|
captureValue( index, Catch::Detail::stringify(value) );
|
2018-06-27 21:34:35 +01:00
|
|
|
captureValues( index+1, values... );
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2013-02-02 19:58:04 +00:00
|
|
|
} // end namespace Catch
|
|
|
|
|
|
2020-04-29 14:02:53 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
#define INTERNAL_CATCH_MSG( macroName, messageType, resultDisposition, ... ) \
|
|
|
|
|
do { \
|
|
|
|
|
Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, Catch::StringRef(), resultDisposition ); \
|
|
|
|
|
catchAssertionHandler.handleMessage( messageType, ( Catch::MessageStream() << __VA_ARGS__ + ::Catch::StreamEndStop() ).m_stream.str() ); \
|
2024-09-13 13:52:17 +02:00
|
|
|
catchAssertionHandler.complete(); \
|
2020-04-29 14:02:53 +02:00
|
|
|
} while( false )
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
#define INTERNAL_CATCH_CAPTURE( varName, macroName, ... ) \
|
2023-02-23 09:37:18 +01:00
|
|
|
Catch::Capturer varName( macroName##_catch_sr, \
|
|
|
|
|
CATCH_INTERNAL_LINEINFO, \
|
|
|
|
|
Catch::ResultWas::Info, \
|
|
|
|
|
#__VA_ARGS__##_catch_sr ); \
|
2020-04-29 14:02:53 +02:00
|
|
|
varName.captureValues( 0, __VA_ARGS__ )
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
#define INTERNAL_CATCH_INFO( macroName, log ) \
|
2022-11-10 12:45:56 +00:00
|
|
|
const Catch::ScopedMessage INTERNAL_CATCH_UNIQUE_NAME( scopedMessage )( Catch::MessageBuilder( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log )
|
2020-04-29 14:02:53 +02:00
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
#define INTERNAL_CATCH_UNSCOPED_INFO( macroName, log ) \
|
2025-09-23 11:01:27 +02:00
|
|
|
Catch::IResultCapture::emplaceUnscopedMessage( Catch::MessageBuilder( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log )
|
2020-04-29 14:02:53 +02:00
|
|
|
|
|
|
|
|
|
2023-07-19 17:04:43 +02:00
|
|
|
#if defined(CATCH_CONFIG_PREFIX_MESSAGES) && !defined(CATCH_CONFIG_DISABLE)
|
2020-04-29 14:02:53 +02:00
|
|
|
|
|
|
|
|
#define CATCH_INFO( msg ) INTERNAL_CATCH_INFO( "CATCH_INFO", msg )
|
|
|
|
|
#define CATCH_UNSCOPED_INFO( msg ) INTERNAL_CATCH_UNSCOPED_INFO( "CATCH_UNSCOPED_INFO", msg )
|
|
|
|
|
#define CATCH_WARN( msg ) INTERNAL_CATCH_MSG( "CATCH_WARN", Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, msg )
|
|
|
|
|
#define CATCH_CAPTURE( ... ) INTERNAL_CATCH_CAPTURE( INTERNAL_CATCH_UNIQUE_NAME(capturer), "CATCH_CAPTURE", __VA_ARGS__ )
|
|
|
|
|
|
2023-07-19 17:04:43 +02:00
|
|
|
#elif defined(CATCH_CONFIG_PREFIX_MESSAGES) && defined(CATCH_CONFIG_DISABLE)
|
2020-04-29 14:02:53 +02:00
|
|
|
|
|
|
|
|
#define CATCH_INFO( msg ) (void)(0)
|
|
|
|
|
#define CATCH_UNSCOPED_INFO( msg ) (void)(0)
|
|
|
|
|
#define CATCH_WARN( msg ) (void)(0)
|
|
|
|
|
#define CATCH_CAPTURE( ... ) (void)(0)
|
|
|
|
|
|
2023-07-19 17:04:43 +02:00
|
|
|
#elif !defined(CATCH_CONFIG_PREFIX_MESSAGES) && !defined(CATCH_CONFIG_DISABLE)
|
2020-04-29 14:02:53 +02:00
|
|
|
|
|
|
|
|
#define INFO( msg ) INTERNAL_CATCH_INFO( "INFO", msg )
|
|
|
|
|
#define UNSCOPED_INFO( msg ) INTERNAL_CATCH_UNSCOPED_INFO( "UNSCOPED_INFO", msg )
|
|
|
|
|
#define WARN( msg ) INTERNAL_CATCH_MSG( "WARN", Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, msg )
|
|
|
|
|
#define CAPTURE( ... ) INTERNAL_CATCH_CAPTURE( INTERNAL_CATCH_UNIQUE_NAME(capturer), "CAPTURE", __VA_ARGS__ )
|
|
|
|
|
|
2023-07-19 17:04:43 +02:00
|
|
|
#elif !defined(CATCH_CONFIG_PREFIX_MESSAGES) && defined(CATCH_CONFIG_DISABLE)
|
2020-04-29 14:02:53 +02:00
|
|
|
|
|
|
|
|
#define INFO( msg ) (void)(0)
|
|
|
|
|
#define UNSCOPED_INFO( msg ) (void)(0)
|
|
|
|
|
#define WARN( msg ) (void)(0)
|
|
|
|
|
#define CAPTURE( ... ) (void)(0)
|
|
|
|
|
|
|
|
|
|
#endif // end of user facing macro declarations
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-08-29 20:48:32 +02:00
|
|
|
#endif // CATCH_MESSAGE_HPP_INCLUDED
|