diff options
| author | Riom | 2023-07-19 17:04:43 +0200 |
|---|---|---|
| committer | GitHub | 2023-07-19 17:04:43 +0200 |
| commit | 4acc51828f7f93f3b2058a63f54d112af4034503 (patch) | |
| tree | 5c24042a87d9a9f711e8a7dc3cca5ff4cbfd4921 /src/catch2 | |
| parent | 6e79e682b726f524310d55dec8ddac4e9c52fb5f (diff) | |
| download | catch3-4acc51828f7f93f3b2058a63f54d112af4034503.tar.gz | |
Introduce CATCH_CONFIG_PREFIX_MESSAGES to only prefix a few logging related macros. (#2544)
* Add missing include for VxWorks build.
std::min is defined in algorithm provides std::min. It appears to be transitively included for most platforms. For VxWorks however this explicit include is required.
* Add option CATCH_CONFIG_PREFIX_MESSAGES to selectively prefix message macros only.
In contrast to CATCH_CONFIG_PREFIX_ALL, this will only prefix the following macros:
I.e. INFO, UNSCOPED_INFO, WARN and CATCH_CAPTURE
This is mainly useful for codebases that use INFO or WARN for their own logging macros.
Diffstat (limited to 'src/catch2')
| -rw-r--r-- | src/catch2/catch_all.hpp | 1 | ||||
| -rw-r--r-- | src/catch2/catch_message.hpp | 9 | ||||
| -rw-r--r-- | src/catch2/catch_user_config.hpp.in | 1 | ||||
| -rw-r--r-- | src/catch2/internal/catch_config_prefix_messages.hpp | 29 |
4 files changed, 36 insertions, 4 deletions
diff --git a/src/catch2/catch_all.hpp b/src/catch2/catch_all.hpp index 70ec402d..cdef3946 100644 --- a/src/catch2/catch_all.hpp +++ b/src/catch2/catch_all.hpp @@ -54,6 +54,7 @@ #include <catch2/internal/catch_compiler_capabilities.hpp> #include <catch2/internal/catch_config_android_logwrite.hpp> #include <catch2/internal/catch_config_counter.hpp> +#include <catch2/internal/catch_config_prefix_messages.hpp> #include <catch2/internal/catch_config_static_analysis_support.hpp> #include <catch2/internal/catch_config_uncaught_exceptions.hpp> #include <catch2/internal/catch_config_wchar.hpp> diff --git a/src/catch2/catch_message.hpp b/src/catch2/catch_message.hpp index b348ac87..76a0fac7 100644 --- a/src/catch2/catch_message.hpp +++ b/src/catch2/catch_message.hpp @@ -8,6 +8,7 @@ #ifndef CATCH_MESSAGE_HPP_INCLUDED #define CATCH_MESSAGE_HPP_INCLUDED +#include <catch2/internal/catch_config_prefix_messages.hpp> #include <catch2/internal/catch_result_type.hpp> #include <catch2/internal/catch_reusable_string_stream.hpp> #include <catch2/internal/catch_stream_end_stop.hpp> @@ -112,28 +113,28 @@ namespace Catch { Catch::getResultCapture().emplaceUnscopedMessage( Catch::MessageBuilder( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log ) -#if defined(CATCH_CONFIG_PREFIX_ALL) && !defined(CATCH_CONFIG_DISABLE) +#if defined(CATCH_CONFIG_PREFIX_MESSAGES) && !defined(CATCH_CONFIG_DISABLE) #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__ ) -#elif defined(CATCH_CONFIG_PREFIX_ALL) && defined(CATCH_CONFIG_DISABLE) +#elif defined(CATCH_CONFIG_PREFIX_MESSAGES) && defined(CATCH_CONFIG_DISABLE) #define CATCH_INFO( msg ) (void)(0) #define CATCH_UNSCOPED_INFO( msg ) (void)(0) #define CATCH_WARN( msg ) (void)(0) #define CATCH_CAPTURE( ... ) (void)(0) -#elif !defined(CATCH_CONFIG_PREFIX_ALL) && !defined(CATCH_CONFIG_DISABLE) +#elif !defined(CATCH_CONFIG_PREFIX_MESSAGES) && !defined(CATCH_CONFIG_DISABLE) #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__ ) -#elif !defined(CATCH_CONFIG_PREFIX_ALL) && defined(CATCH_CONFIG_DISABLE) +#elif !defined(CATCH_CONFIG_PREFIX_MESSAGES) && defined(CATCH_CONFIG_DISABLE) #define INFO( msg ) (void)(0) #define UNSCOPED_INFO( msg ) (void)(0) diff --git a/src/catch2/catch_user_config.hpp.in b/src/catch2/catch_user_config.hpp.in index 11ab5a6d..10d61937 100644 --- a/src/catch2/catch_user_config.hpp.in +++ b/src/catch2/catch_user_config.hpp.in @@ -198,6 +198,7 @@ #cmakedefine CATCH_CONFIG_FAST_COMPILE #cmakedefine CATCH_CONFIG_NOSTDOUT #cmakedefine CATCH_CONFIG_PREFIX_ALL +#cmakedefine CATCH_CONFIG_PREFIX_MESSAGES #cmakedefine CATCH_CONFIG_WINDOWS_CRTDBG #cmakedefine CATCH_CONFIG_SHARED_LIBRARY diff --git a/src/catch2/internal/catch_config_prefix_messages.hpp b/src/catch2/internal/catch_config_prefix_messages.hpp new file mode 100644 index 00000000..be1e9a96 --- /dev/null +++ b/src/catch2/internal/catch_config_prefix_messages.hpp @@ -0,0 +1,29 @@ + +// Copyright Catch2 Authors +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// SPDX-License-Identifier: BSL-1.0 + +/** \file + * Wrapper for the CATCH_CONFIG_PREFIX_MESSAGES configuration option + * + * CATCH_CONFIG_PREFIX_ALL can be used to avoid clashes with other macros + * by prepending CATCH_. This may not be desirable if the only clashes are with + * logger macros such as INFO and WARN. In this cases + * CATCH_CONFIG_PREFIX_MESSAGES can be used to only prefix a small subset + * of relevant macros. + * + */ + +#ifndef CATCH_CONFIG_PREFIX_MESSAGES_HPP_INCLUDED +#define CATCH_CONFIG_PREFIX_MESSAGES_HPP_INCLUDED + +#include <catch2/catch_user_config.hpp> + +#if defined(CATCH_CONFIG_PREFIX_ALL) && !defined(CATCH_CONFIG_PREFIX_MESSAGES) + #define CATCH_CONFIG_PREFIX_MESSAGES +#endif + +#endif // CATCH_CONFIG_PREFIX_MESSAGES_HPP_INCLUDED |