From 05e85c5652480b584287f406b2170f61b02d560c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Sat, 16 Apr 2022 14:12:56 +0200 Subject: [PATCH 1/3] Split out Catch::cout/cerr/clog into their own file --- src/CMakeLists.txt | 2 ++ src/catch2/catch_all.hpp | 1 + src/catch2/catch_session.cpp | 2 +- src/catch2/internal/catch_debug_console.cpp | 6 +++-- src/catch2/internal/catch_debugger.cpp | 1 + src/catch2/internal/catch_enforce.cpp | 1 + .../catch_fatal_condition_handler.cpp | 1 + src/catch2/internal/catch_output_redirect.cpp | 1 + src/catch2/internal/catch_stdstreams.cpp | 24 +++++++++++++++++++ src/catch2/internal/catch_stdstreams.hpp | 22 +++++++++++++++++ src/catch2/internal/catch_stream.cpp | 10 +------- src/catch2/internal/catch_stream.hpp | 4 ---- src/catch2/reporters/catch_reporter_multi.cpp | 4 +++- .../X04-DisabledExceptions-CustomHandler.cpp | 6 +++-- 14 files changed, 66 insertions(+), 19 deletions(-) create mode 100644 src/catch2/internal/catch_stdstreams.cpp create mode 100644 src/catch2/internal/catch_stdstreams.hpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5c724a46..fdf30a87 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -125,6 +125,7 @@ set(INTERNAL_HEADERS ${SOURCES_DIR}/internal/catch_result_type.hpp ${SOURCES_DIR}/internal/catch_run_context.hpp ${SOURCES_DIR}/internal/catch_section.hpp + ${SOURCES_DIR}/internal/catch_stdstreams.hpp ${SOURCES_DIR}/catch_section_info.hpp ${SOURCES_DIR}/catch_session.hpp ${SOURCES_DIR}/internal/catch_singletons.hpp @@ -198,6 +199,7 @@ set(IMPL_SOURCES ${SOURCES_DIR}/internal/catch_result_type.cpp ${SOURCES_DIR}/internal/catch_run_context.cpp ${SOURCES_DIR}/internal/catch_section.cpp + ${SOURCES_DIR}/internal/catch_stdstreams.cpp ${SOURCES_DIR}/catch_session.cpp ${SOURCES_DIR}/internal/catch_singletons.cpp ${SOURCES_DIR}/internal/catch_stream.cpp diff --git a/src/catch2/catch_all.hpp b/src/catch2/catch_all.hpp index 5367ef3e..ce3f49d3 100644 --- a/src/catch2/catch_all.hpp +++ b/src/catch2/catch_all.hpp @@ -91,6 +91,7 @@ #include #include #include +#include #include #include #include diff --git a/src/catch2/catch_session.cpp b/src/catch2/catch_session.cpp index e6ad93a1..c2047aa2 100644 --- a/src/catch2/catch_session.cpp +++ b/src/catch2/catch_session.cpp @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -23,6 +22,7 @@ #include #include #include +#include #include #include diff --git a/src/catch2/internal/catch_debug_console.cpp b/src/catch2/internal/catch_debug_console.cpp index d13cc0bb..ce351de0 100644 --- a/src/catch2/internal/catch_debug_console.cpp +++ b/src/catch2/internal/catch_debug_console.cpp @@ -5,13 +5,15 @@ // https://www.boost.org/LICENSE_1_0.txt) // SPDX-License-Identifier: BSL-1.0 + #include + #include #include #include #include - -#include +#include +#include #if defined(CATCH_CONFIG_ANDROID_LOGWRITE) #include diff --git a/src/catch2/internal/catch_debugger.cpp b/src/catch2/internal/catch_debugger.cpp index 3c80173a..57ade819 100644 --- a/src/catch2/internal/catch_debugger.cpp +++ b/src/catch2/internal/catch_debugger.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #if defined(CATCH_PLATFORM_MAC) || defined(CATCH_PLATFORM_IPHONE) diff --git a/src/catch2/internal/catch_enforce.cpp b/src/catch2/internal/catch_enforce.cpp index 3f4962cb..4bc47ce3 100644 --- a/src/catch2/internal/catch_enforce.cpp +++ b/src/catch2/internal/catch_enforce.cpp @@ -6,6 +6,7 @@ // SPDX-License-Identifier: BSL-1.0 #include +#include #include diff --git a/src/catch2/internal/catch_fatal_condition_handler.cpp b/src/catch2/internal/catch_fatal_condition_handler.cpp index 410b9b8f..3afd46f5 100644 --- a/src/catch2/internal/catch_fatal_condition_handler.cpp +++ b/src/catch2/internal/catch_fatal_condition_handler.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include diff --git a/src/catch2/internal/catch_output_redirect.cpp b/src/catch2/internal/catch_output_redirect.cpp index 49cfaa0d..ae060141 100644 --- a/src/catch2/internal/catch_output_redirect.cpp +++ b/src/catch2/internal/catch_output_redirect.cpp @@ -7,6 +7,7 @@ // SPDX-License-Identifier: BSL-1.0 #include #include +#include #include #include diff --git a/src/catch2/internal/catch_stdstreams.cpp b/src/catch2/internal/catch_stdstreams.cpp new file mode 100644 index 00000000..21a0e4e6 --- /dev/null +++ b/src/catch2/internal/catch_stdstreams.cpp @@ -0,0 +1,24 @@ + +// Copyright Catch2 Authors +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// SPDX-License-Identifier: BSL-1.0 + +#include + +#include + +#include + +namespace Catch { + +// If you #define this you must implement these functions +#if !defined( CATCH_CONFIG_NOSTDOUT ) + std::ostream& cout() { return std::cout; } + std::ostream& cerr() { return std::cerr; } + std::ostream& clog() { return std::clog; } +#endif + +} // namespace Catch diff --git a/src/catch2/internal/catch_stdstreams.hpp b/src/catch2/internal/catch_stdstreams.hpp new file mode 100644 index 00000000..39d8bd75 --- /dev/null +++ b/src/catch2/internal/catch_stdstreams.hpp @@ -0,0 +1,22 @@ + +// Copyright Catch2 Authors +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// SPDX-License-Identifier: BSL-1.0 + +#ifndef CATCH_STDSTREAMS_HPP_INCLUDED +#define CATCH_STDSTREAMS_HPP_INCLUDED + +#include + +namespace Catch { + + std::ostream& cout(); + std::ostream& cerr(); + std::ostream& clog(); + +} // namespace Catch + +#endif diff --git a/src/catch2/internal/catch_stream.cpp b/src/catch2/internal/catch_stream.cpp index 089a7583..64cfde0a 100644 --- a/src/catch2/internal/catch_stream.cpp +++ b/src/catch2/internal/catch_stream.cpp @@ -11,9 +11,9 @@ #include #include #include +#include #include -#include #include #include #include @@ -201,12 +201,4 @@ namespace Detail { } - /////////////////////////////////////////////////////////////////////////// - - -#ifndef CATCH_CONFIG_NOSTDOUT // If you #define this you must implement these functions - std::ostream& cout() { return std::cout; } - std::ostream& cerr() { return std::cerr; } - std::ostream& clog() { return std::clog; } -#endif } diff --git a/src/catch2/internal/catch_stream.hpp b/src/catch2/internal/catch_stream.hpp index eab7161c..d02dc4b1 100644 --- a/src/catch2/internal/catch_stream.hpp +++ b/src/catch2/internal/catch_stream.hpp @@ -18,10 +18,6 @@ namespace Catch { - std::ostream& cout(); - std::ostream& cerr(); - std::ostream& clog(); - class IStream { public: virtual ~IStream(); // = default diff --git a/src/catch2/reporters/catch_reporter_multi.cpp b/src/catch2/reporters/catch_reporter_multi.cpp index e8cf7bdf..e7ba7e5d 100644 --- a/src/catch2/reporters/catch_reporter_multi.cpp +++ b/src/catch2/reporters/catch_reporter_multi.cpp @@ -9,7 +9,9 @@ #include #include -#include +#include + +#include namespace Catch { void MultiReporter::updatePreferences(IEventListener const& reporterish) { diff --git a/tests/ExtraTests/X04-DisabledExceptions-CustomHandler.cpp b/tests/ExtraTests/X04-DisabledExceptions-CustomHandler.cpp index b506d8b8..725440ec 100644 --- a/tests/ExtraTests/X04-DisabledExceptions-CustomHandler.cpp +++ b/tests/ExtraTests/X04-DisabledExceptions-CustomHandler.cpp @@ -8,11 +8,13 @@ #include +#include + namespace Catch { [[noreturn]] void throw_exception(std::exception const& e) { - Catch::cerr() << "====== CUSTOM HANDLER ====== run terminates because an exception was thrown.\n" - << "The message was: " << e.what() << '\n'; + std::cerr << "====== CUSTOM HANDLER ====== run terminates because an exception was thrown.\n" + << "The message was: " << e.what() << '\n'; // Avoid abort and other exceptional exits -- there is no way // to tell CMake that abort is the desired outcome of a test. exit(1); From 98bb638fb2e3f1af7ef87bc483faff35076c6c51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Sat, 16 Apr 2022 14:43:40 +0200 Subject: [PATCH 2/3] Split out IStream out of catch_stream.hpp --- src/CMakeLists.txt | 2 + src/catch2/catch_all.hpp | 1 + src/catch2/catch_session.cpp | 1 + .../interfaces/catch_interfaces_reporter.cpp | 3 + .../interfaces/catch_interfaces_reporter.hpp | 4 + src/catch2/internal/catch_console_colour.cpp | 2 +- src/catch2/internal/catch_istream.cpp | 158 ++++++++++++++++++ src/catch2/internal/catch_istream.hpp | 54 ++++++ src/catch2/internal/catch_stream.cpp | 142 ---------------- src/catch2/internal/catch_stream.hpp | 32 ---- .../reporters/catch_reporter_common_base.cpp | 2 +- .../IntrospectiveTests/ColourImpl.tests.cpp | 1 + .../IntrospectiveTests/Reporters.tests.cpp | 2 +- .../IntrospectiveTests/Stream.tests.cpp | 2 +- 14 files changed, 228 insertions(+), 178 deletions(-) create mode 100644 src/catch2/internal/catch_istream.cpp create mode 100644 src/catch2/internal/catch_istream.hpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fdf30a87..fb859db9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -76,6 +76,7 @@ set(INTERNAL_HEADERS ${SOURCES_DIR}/internal/catch_exception_translator_registry.hpp ${SOURCES_DIR}/internal/catch_fatal_condition_handler.hpp ${SOURCES_DIR}/internal/catch_floating_point_helpers.hpp + ${SOURCES_DIR}/internal/catch_istream.hpp ${SOURCES_DIR}/internal/catch_unique_name.hpp ${SOURCES_DIR}/internal/catch_sharding.hpp ${SOURCES_DIR}/generators/catch_generator_exception.hpp @@ -181,6 +182,7 @@ set(IMPL_SOURCES ${SOURCES_DIR}/internal/catch_exception_translator_registry.cpp ${SOURCES_DIR}/internal/catch_fatal_condition_handler.cpp ${SOURCES_DIR}/internal/catch_floating_point_helpers.cpp + ${SOURCES_DIR}/internal/catch_istream.cpp ${SOURCES_DIR}/generators/internal/catch_generators_combined_tu.cpp ${SOURCES_DIR}/interfaces/catch_interfaces_combined_tu.cpp ${SOURCES_DIR}/interfaces/catch_interfaces_reporter.cpp diff --git a/src/catch2/catch_all.hpp b/src/catch2/catch_all.hpp index ce3f49d3..101eb834 100644 --- a/src/catch2/catch_all.hpp +++ b/src/catch2/catch_all.hpp @@ -67,6 +67,7 @@ #include #include #include +#include #include #include #include diff --git a/src/catch2/catch_session.cpp b/src/catch2/catch_session.cpp index c2047aa2..df92559b 100644 --- a/src/catch2/catch_session.cpp +++ b/src/catch2/catch_session.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include diff --git a/src/catch2/interfaces/catch_interfaces_reporter.cpp b/src/catch2/interfaces/catch_interfaces_reporter.cpp index 9a6cbdc2..b1ad584c 100644 --- a/src/catch2/interfaces/catch_interfaces_reporter.cpp +++ b/src/catch2/interfaces/catch_interfaces_reporter.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -44,6 +45,8 @@ namespace Catch { return m_customOptions; } + ReporterConfig::~ReporterConfig() = default; + AssertionStats::AssertionStats( AssertionResult const& _assertionResult, std::vector const& _infoMessages, Totals const& _totals ) diff --git a/src/catch2/interfaces/catch_interfaces_reporter.hpp b/src/catch2/interfaces/catch_interfaces_reporter.hpp index 1e6c2590..1a2736f7 100644 --- a/src/catch2/interfaces/catch_interfaces_reporter.hpp +++ b/src/catch2/interfaces/catch_interfaces_reporter.hpp @@ -40,6 +40,10 @@ namespace Catch { ColourMode colourMode, std::map customOptions ); + ReporterConfig( ReporterConfig&& ) = default; + ReporterConfig& operator=( ReporterConfig&& ) = default; + ~ReporterConfig(); // = default + Detail::unique_ptr takeStream() &&; IConfig const* fullConfig() const; ColourMode colourMode() const; diff --git a/src/catch2/internal/catch_console_colour.cpp b/src/catch2/internal/catch_console_colour.cpp index 7f202490..f519fb86 100644 --- a/src/catch2/internal/catch_console_colour.cpp +++ b/src/catch2/internal/catch_console_colour.cpp @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/catch2/internal/catch_istream.cpp b/src/catch2/internal/catch_istream.cpp new file mode 100644 index 00000000..656813b3 --- /dev/null +++ b/src/catch2/internal/catch_istream.cpp @@ -0,0 +1,158 @@ + +// Copyright Catch2 Authors +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// SPDX-License-Identifier: BSL-1.0 + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +namespace Catch { + + Catch::IStream::~IStream() = default; + +namespace Detail { + namespace { + template + class StreamBufImpl : public std::streambuf { + char data[bufferSize]; + WriterF m_writer; + + public: + StreamBufImpl() { + setp( data, data + sizeof(data) ); + } + + ~StreamBufImpl() noexcept { + StreamBufImpl::sync(); + } + + private: + int overflow( int c ) override { + sync(); + + if( c != EOF ) { + if( pbase() == epptr() ) + m_writer( std::string( 1, static_cast( c ) ) ); + else + sputc( static_cast( c ) ); + } + return 0; + } + + int sync() override { + if( pbase() != pptr() ) { + m_writer( std::string( pbase(), static_cast( pptr() - pbase() ) ) ); + setp( pbase(), epptr() ); + } + return 0; + } + }; + + /////////////////////////////////////////////////////////////////////////// + + struct OutputDebugWriter { + + void operator()( std::string const& str ) { + if ( !str.empty() ) { + writeToDebugConsole( str ); + } + } + }; + + /////////////////////////////////////////////////////////////////////////// + + class FileStream : public IStream { + std::ofstream m_ofs; + public: + FileStream( std::string const& filename ) { + m_ofs.open( filename.c_str() ); + CATCH_ENFORCE( !m_ofs.fail(), "Unable to open file: '" << filename << '\'' ); + } + ~FileStream() override = default; + public: // IStream + std::ostream& stream() override { + return m_ofs; + } + }; + + /////////////////////////////////////////////////////////////////////////// + + class CoutStream : public IStream { + std::ostream m_os; + public: + // Store the streambuf from cout up-front because + // cout may get redirected when running tests + CoutStream() : m_os( Catch::cout().rdbuf() ) {} + ~CoutStream() override = default; + + public: // IStream + std::ostream& stream() override { return m_os; } + bool isConsole() const override { return true; } + }; + + class CerrStream : public IStream { + std::ostream m_os; + + public: + // Store the streambuf from cerr up-front because + // cout may get redirected when running tests + CerrStream(): m_os( Catch::cerr().rdbuf() ) {} + ~CerrStream() override = default; + + public: // IStream + std::ostream& stream() override { return m_os; } + bool isConsole() const override { return true; } + }; + + /////////////////////////////////////////////////////////////////////////// + + class DebugOutStream : public IStream { + Detail::unique_ptr> m_streamBuf; + std::ostream m_os; + public: + DebugOutStream() + : m_streamBuf( Detail::make_unique>() ), + m_os( m_streamBuf.get() ) + {} + + ~DebugOutStream() override = default; + + public: // IStream + std::ostream& stream() override { return m_os; } + }; + + } // unnamed namespace +} // namespace Detail + + /////////////////////////////////////////////////////////////////////////// + + auto makeStream( std::string const& filename ) -> Detail::unique_ptr { + if ( filename.empty() || filename == "-" ) { + return Detail::make_unique(); + } + if( filename[0] == '%' ) { + if ( filename == "%debug" ) { + return Detail::make_unique(); + } else if ( filename == "%stderr" ) { + return Detail::make_unique(); + } else if ( filename == "%stdout" ) { + return Detail::make_unique(); + } else { + CATCH_ERROR( "Unrecognised stream: '" << filename << '\'' ); + } + } + return Detail::make_unique( filename ); + } + +} diff --git a/src/catch2/internal/catch_istream.hpp b/src/catch2/internal/catch_istream.hpp new file mode 100644 index 00000000..629816c8 --- /dev/null +++ b/src/catch2/internal/catch_istream.hpp @@ -0,0 +1,54 @@ + +// Copyright Catch2 Authors +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// SPDX-License-Identifier: BSL-1.0 +#ifndef CATCH_ISTREAM_HPP_INCLUDED +#define CATCH_ISTREAM_HPP_INCLUDED + +#include +#include + +#include +#include +#include +#include + +namespace Catch { + + class IStream { + public: + virtual ~IStream(); // = default + virtual std::ostream& stream() = 0; + /** + * Best guess on whether the instance is writing to a console (e.g. via stdout/stderr) + * + * This is useful for e.g. Win32 colour support, because the Win32 + * API manipulates console directly, unlike POSIX escape codes, + * that can be written anywhere. + * + * Due to variety of ways to change where the stdout/stderr is + * _actually_ being written, users should always assume that + * the answer might be wrong. + */ + virtual bool isConsole() const { return false; } + }; + + /** + * Creates a stream wrapper that writes to specific file. + * + * Also recognizes 4 special filenames + * * `-` for stdout + * * `%stdout` for stdout + * * `%stderr` for stderr + * * `%debug` for platform specific debugging output + * + * \throws if passed an unrecognized %-prefixed stream + */ + auto makeStream( std::string const& filename ) -> Detail::unique_ptr; + +} + +#endif // CATCH_STREAM_HPP_INCLUDED diff --git a/src/catch2/internal/catch_stream.cpp b/src/catch2/internal/catch_stream.cpp index 64cfde0a..10eb4a9e 100644 --- a/src/catch2/internal/catch_stream.cpp +++ b/src/catch2/internal/catch_stream.cpp @@ -5,158 +5,16 @@ // https://www.boost.org/LICENSE_1_0.txt) // SPDX-License-Identifier: BSL-1.0 -#include #include -#include -#include #include #include -#include #include -#include #include #include namespace Catch { - Catch::IStream::~IStream() = default; - -namespace Detail { - namespace { - template - class StreamBufImpl : public std::streambuf { - char data[bufferSize]; - WriterF m_writer; - - public: - StreamBufImpl() { - setp( data, data + sizeof(data) ); - } - - ~StreamBufImpl() noexcept { - StreamBufImpl::sync(); - } - - private: - int overflow( int c ) override { - sync(); - - if( c != EOF ) { - if( pbase() == epptr() ) - m_writer( std::string( 1, static_cast( c ) ) ); - else - sputc( static_cast( c ) ); - } - return 0; - } - - int sync() override { - if( pbase() != pptr() ) { - m_writer( std::string( pbase(), static_cast( pptr() - pbase() ) ) ); - setp( pbase(), epptr() ); - } - return 0; - } - }; - - /////////////////////////////////////////////////////////////////////////// - - struct OutputDebugWriter { - - void operator()( std::string const& str ) { - if ( !str.empty() ) { - writeToDebugConsole( str ); - } - } - }; - - /////////////////////////////////////////////////////////////////////////// - - class FileStream : public IStream { - std::ofstream m_ofs; - public: - FileStream( std::string const& filename ) { - m_ofs.open( filename.c_str() ); - CATCH_ENFORCE( !m_ofs.fail(), "Unable to open file: '" << filename << '\'' ); - } - ~FileStream() override = default; - public: // IStream - std::ostream& stream() override { - return m_ofs; - } - }; - - /////////////////////////////////////////////////////////////////////////// - - class CoutStream : public IStream { - std::ostream m_os; - public: - // Store the streambuf from cout up-front because - // cout may get redirected when running tests - CoutStream() : m_os( Catch::cout().rdbuf() ) {} - ~CoutStream() override = default; - - public: // IStream - std::ostream& stream() override { return m_os; } - bool isConsole() const override { return true; } - }; - - class CerrStream : public IStream { - std::ostream m_os; - - public: - // Store the streambuf from cerr up-front because - // cout may get redirected when running tests - CerrStream(): m_os( Catch::cerr().rdbuf() ) {} - ~CerrStream() override = default; - - public: // IStream - std::ostream& stream() override { return m_os; } - bool isConsole() const override { return true; } - }; - - /////////////////////////////////////////////////////////////////////////// - - class DebugOutStream : public IStream { - Detail::unique_ptr> m_streamBuf; - std::ostream m_os; - public: - DebugOutStream() - : m_streamBuf( Detail::make_unique>() ), - m_os( m_streamBuf.get() ) - {} - - ~DebugOutStream() override = default; - - public: // IStream - std::ostream& stream() override { return m_os; } - }; - - } // unnamed namespace -} // namespace Detail - - /////////////////////////////////////////////////////////////////////////// - - auto makeStream( std::string const& filename ) -> Detail::unique_ptr { - if ( filename.empty() || filename == "-" ) { - return Detail::make_unique(); - } - if( filename[0] == '%' ) { - if ( filename == "%debug" ) { - return Detail::make_unique(); - } else if ( filename == "%stderr" ) { - return Detail::make_unique(); - } else if ( filename == "%stdout" ) { - return Detail::make_unique(); - } else { - CATCH_ERROR( "Unrecognised stream: '" << filename << '\'' ); - } - } - return Detail::make_unique( filename ); - } - - // This class encapsulates the idea of a pool of ostringstreams that can be reused. struct StringStreams { std::vector> m_streams; diff --git a/src/catch2/internal/catch_stream.hpp b/src/catch2/internal/catch_stream.hpp index d02dc4b1..104a2412 100644 --- a/src/catch2/internal/catch_stream.hpp +++ b/src/catch2/internal/catch_stream.hpp @@ -9,7 +9,6 @@ #define CATCH_STREAM_HPP_INCLUDED #include -#include #include #include @@ -18,37 +17,6 @@ namespace Catch { - class IStream { - public: - virtual ~IStream(); // = default - virtual std::ostream& stream() = 0; - /** - * Best guess on whether the instance is writing to a console (e.g. via stdout/stderr) - * - * This is useful for e.g. Win32 colour support, because the Win32 - * API manipulates console directly, unlike POSIX escape codes, - * that can be written anywhere. - * - * Due to variety of ways to change where the stdout/stderr is - * _actually_ being written, users should always assume that - * the answer might be wrong. - */ - virtual bool isConsole() const { return false; } - }; - - /** - * Creates a stream wrapper that writes to specific file. - * - * Also recognizes 4 special filenames - * * `-` for stdout - * * `%stdout` for stdout - * * `%stderr` for stderr - * * `%debug` for platform specific debugging output - * - * \throws if passed an unrecognized %-prefixed stream - */ - auto makeStream( std::string const& filename ) -> Detail::unique_ptr; - class ReusableStringStream : Detail::NonCopyable { std::size_t m_index; std::ostream* m_oss; diff --git a/src/catch2/reporters/catch_reporter_common_base.cpp b/src/catch2/reporters/catch_reporter_common_base.cpp index 68a24eef..f4736ab2 100644 --- a/src/catch2/reporters/catch_reporter_common_base.cpp +++ b/src/catch2/reporters/catch_reporter_common_base.cpp @@ -10,7 +10,7 @@ #include #include -#include +#include namespace Catch { diff --git a/tests/SelfTest/IntrospectiveTests/ColourImpl.tests.cpp b/tests/SelfTest/IntrospectiveTests/ColourImpl.tests.cpp index 716d6033..83501cae 100644 --- a/tests/SelfTest/IntrospectiveTests/ColourImpl.tests.cpp +++ b/tests/SelfTest/IntrospectiveTests/ColourImpl.tests.cpp @@ -8,6 +8,7 @@ #include #include +#include #include diff --git a/tests/SelfTest/IntrospectiveTests/Reporters.tests.cpp b/tests/SelfTest/IntrospectiveTests/Reporters.tests.cpp index e4554fca..5288709d 100644 --- a/tests/SelfTest/IntrospectiveTests/Reporters.tests.cpp +++ b/tests/SelfTest/IntrospectiveTests/Reporters.tests.cpp @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/tests/SelfTest/IntrospectiveTests/Stream.tests.cpp b/tests/SelfTest/IntrospectiveTests/Stream.tests.cpp index 9d647b0d..5ad92e8c 100644 --- a/tests/SelfTest/IntrospectiveTests/Stream.tests.cpp +++ b/tests/SelfTest/IntrospectiveTests/Stream.tests.cpp @@ -8,7 +8,7 @@ #include -#include +#include TEST_CASE( "Cout stream properly declares it writes to stdout", "[streams]" ) { REQUIRE( Catch::makeStream( "-" )->isConsole() ); From 7b93a2014cb417d277339e3d679cac64bfac237b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Sat, 16 Apr 2022 15:00:41 +0200 Subject: [PATCH 3/3] Rename catch_stream -> catch_reusable_string_stream After everything else was split out, this name much reflects the actual contents of the file(s). --- src/CMakeLists.txt | 4 ++-- src/catch2/catch_all.hpp | 2 +- src/catch2/catch_approx.cpp | 2 +- src/catch2/catch_assertion_result.cpp | 2 +- src/catch2/catch_config.cpp | 1 - src/catch2/catch_message.hpp | 2 +- src/catch2/catch_tostring.hpp | 2 +- src/catch2/internal/catch_debug_console.cpp | 3 ++- src/catch2/internal/catch_debugger.cpp | 1 - src/catch2/internal/catch_enforce.hpp | 2 +- src/catch2/internal/catch_enum_values_registry.cpp | 1 - src/catch2/internal/catch_output_redirect.hpp | 2 +- .../{catch_stream.cpp => catch_reusable_string_stream.cpp} | 2 +- .../{catch_stream.hpp => catch_reusable_string_stream.hpp} | 6 +++--- src/catch2/internal/catch_to_string.hpp | 2 +- src/catch2/internal/catch_xmlwriter.hpp | 2 +- src/catch2/matchers/internal/catch_matchers_combined_tu.cpp | 2 +- src/catch2/reporters/catch_reporter_combined_tu.cpp | 2 +- src/catch2/reporters/catch_reporter_console.cpp | 2 +- tests/SelfTest/IntrospectiveTests/Xml.tests.cpp | 2 +- 20 files changed, 21 insertions(+), 23 deletions(-) rename src/catch2/internal/{catch_stream.cpp => catch_reusable_string_stream.cpp} (97%) rename src/catch2/internal/{catch_stream.hpp => catch_reusable_string_stream.hpp} (91%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fb859db9..ba4ca435 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -131,7 +131,7 @@ set(INTERNAL_HEADERS ${SOURCES_DIR}/catch_session.hpp ${SOURCES_DIR}/internal/catch_singletons.hpp ${SOURCES_DIR}/internal/catch_startup_exception_registry.hpp - ${SOURCES_DIR}/internal/catch_stream.hpp + ${SOURCES_DIR}/internal/catch_reusable_string_stream.hpp ${SOURCES_DIR}/internal/catch_stream_end_stop.hpp ${SOURCES_DIR}/internal/catch_string_manip.hpp ${SOURCES_DIR}/internal/catch_stringref.hpp @@ -204,7 +204,7 @@ set(IMPL_SOURCES ${SOURCES_DIR}/internal/catch_stdstreams.cpp ${SOURCES_DIR}/catch_session.cpp ${SOURCES_DIR}/internal/catch_singletons.cpp - ${SOURCES_DIR}/internal/catch_stream.cpp + ${SOURCES_DIR}/internal/catch_reusable_string_stream.cpp ${SOURCES_DIR}/internal/catch_stringref.cpp ${SOURCES_DIR}/internal/catch_string_manip.cpp ${SOURCES_DIR}/internal/catch_tag_alias_registry.cpp diff --git a/src/catch2/catch_all.hpp b/src/catch2/catch_all.hpp index 101eb834..5c715e35 100644 --- a/src/catch2/catch_all.hpp +++ b/src/catch2/catch_all.hpp @@ -86,6 +86,7 @@ #include #include #include +#include #include #include #include @@ -93,7 +94,6 @@ #include #include #include -#include #include #include #include diff --git a/src/catch2/catch_approx.cpp b/src/catch2/catch_approx.cpp index 21652111..b477d6ed 100644 --- a/src/catch2/catch_approx.cpp +++ b/src/catch2/catch_approx.cpp @@ -7,7 +7,7 @@ // SPDX-License-Identifier: BSL-1.0 #include #include -#include +#include #include #include diff --git a/src/catch2/catch_assertion_result.cpp b/src/catch2/catch_assertion_result.cpp index 04e00d26..2912c8d3 100644 --- a/src/catch2/catch_assertion_result.cpp +++ b/src/catch2/catch_assertion_result.cpp @@ -6,7 +6,7 @@ // SPDX-License-Identifier: BSL-1.0 #include -#include +#include namespace Catch { diff --git a/src/catch2/catch_config.cpp b/src/catch2/catch_config.cpp index 7363ee70..9e56e9fe 100644 --- a/src/catch2/catch_config.cpp +++ b/src/catch2/catch_config.cpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include diff --git a/src/catch2/catch_message.hpp b/src/catch2/catch_message.hpp index 970ba438..dac7a21d 100644 --- a/src/catch2/catch_message.hpp +++ b/src/catch2/catch_message.hpp @@ -9,7 +9,7 @@ #define CATCH_MESSAGE_HPP_INCLUDED #include -#include +#include #include #include #include diff --git a/src/catch2/catch_tostring.hpp b/src/catch2/catch_tostring.hpp index 9182a119..964c8a66 100644 --- a/src/catch2/catch_tostring.hpp +++ b/src/catch2/catch_tostring.hpp @@ -17,7 +17,7 @@ #include #include -#include +#include #include #include diff --git a/src/catch2/internal/catch_debug_console.cpp b/src/catch2/internal/catch_debug_console.cpp index ce351de0..5564c6a8 100644 --- a/src/catch2/internal/catch_debug_console.cpp +++ b/src/catch2/internal/catch_debug_console.cpp @@ -9,12 +9,13 @@ #include #include -#include #include #include #include #include +#include + #if defined(CATCH_CONFIG_ANDROID_LOGWRITE) #include diff --git a/src/catch2/internal/catch_debugger.cpp b/src/catch2/internal/catch_debugger.cpp index 57ade819..349cf4ab 100644 --- a/src/catch2/internal/catch_debugger.cpp +++ b/src/catch2/internal/catch_debugger.cpp @@ -7,7 +7,6 @@ // SPDX-License-Identifier: BSL-1.0 #include #include -#include #include #include diff --git a/src/catch2/internal/catch_enforce.hpp b/src/catch2/internal/catch_enforce.hpp index 3f81ef1a..db52a0e2 100644 --- a/src/catch2/internal/catch_enforce.hpp +++ b/src/catch2/internal/catch_enforce.hpp @@ -10,7 +10,7 @@ #include #include -#include +#include #include diff --git a/src/catch2/internal/catch_enum_values_registry.cpp b/src/catch2/internal/catch_enum_values_registry.cpp index ef4baf9a..32d0a16d 100644 --- a/src/catch2/internal/catch_enum_values_registry.cpp +++ b/src/catch2/internal/catch_enum_values_registry.cpp @@ -7,7 +7,6 @@ // SPDX-License-Identifier: BSL-1.0 #include #include -#include #include diff --git a/src/catch2/internal/catch_output_redirect.hpp b/src/catch2/internal/catch_output_redirect.hpp index fd7234ef..d3463d99 100644 --- a/src/catch2/internal/catch_output_redirect.hpp +++ b/src/catch2/internal/catch_output_redirect.hpp @@ -9,7 +9,7 @@ #define CATCH_OUTPUT_REDIRECT_HPP_INCLUDED #include -#include +#include #include #include diff --git a/src/catch2/internal/catch_stream.cpp b/src/catch2/internal/catch_reusable_string_stream.cpp similarity index 97% rename from src/catch2/internal/catch_stream.cpp rename to src/catch2/internal/catch_reusable_string_stream.cpp index 10eb4a9e..9b082423 100644 --- a/src/catch2/internal/catch_stream.cpp +++ b/src/catch2/internal/catch_reusable_string_stream.cpp @@ -5,7 +5,7 @@ // https://www.boost.org/LICENSE_1_0.txt) // SPDX-License-Identifier: BSL-1.0 -#include +#include #include #include diff --git a/src/catch2/internal/catch_stream.hpp b/src/catch2/internal/catch_reusable_string_stream.hpp similarity index 91% rename from src/catch2/internal/catch_stream.hpp rename to src/catch2/internal/catch_reusable_string_stream.hpp index 104a2412..55cff727 100644 --- a/src/catch2/internal/catch_stream.hpp +++ b/src/catch2/internal/catch_reusable_string_stream.hpp @@ -5,8 +5,8 @@ // https://www.boost.org/LICENSE_1_0.txt) // SPDX-License-Identifier: BSL-1.0 -#ifndef CATCH_STREAM_HPP_INCLUDED -#define CATCH_STREAM_HPP_INCLUDED +#ifndef CATCH_REUSABLE_STRING_STREAM_HPP_INCLUDED +#define CATCH_REUSABLE_STRING_STREAM_HPP_INCLUDED #include @@ -54,4 +54,4 @@ namespace Catch { }; } -#endif // CATCH_STREAM_HPP_INCLUDED +#endif // CATCH_REUSABLE_STRING_STREAM_HPP_INCLUDED diff --git a/src/catch2/internal/catch_to_string.hpp b/src/catch2/internal/catch_to_string.hpp index d8ff35cf..15b24e19 100644 --- a/src/catch2/internal/catch_to_string.hpp +++ b/src/catch2/internal/catch_to_string.hpp @@ -11,7 +11,7 @@ #include #include -#include +#include namespace Catch { template diff --git a/src/catch2/internal/catch_xmlwriter.hpp b/src/catch2/internal/catch_xmlwriter.hpp index edeb64a2..55633937 100644 --- a/src/catch2/internal/catch_xmlwriter.hpp +++ b/src/catch2/internal/catch_xmlwriter.hpp @@ -8,7 +8,7 @@ #ifndef CATCH_XMLWRITER_HPP_INCLUDED #define CATCH_XMLWRITER_HPP_INCLUDED -#include +#include #include #include diff --git a/src/catch2/matchers/internal/catch_matchers_combined_tu.cpp b/src/catch2/matchers/internal/catch_matchers_combined_tu.cpp index de713b3b..6ec878b0 100644 --- a/src/catch2/matchers/internal/catch_matchers_combined_tu.cpp +++ b/src/catch2/matchers/internal/catch_matchers_combined_tu.cpp @@ -43,7 +43,7 @@ namespace Catch { // vvv formerly catch_matchers_container_properties.cpp vvv // ////////////////////////////////////////////////////////////// #include -#include +#include namespace Catch { namespace Matchers { diff --git a/src/catch2/reporters/catch_reporter_combined_tu.cpp b/src/catch2/reporters/catch_reporter_combined_tu.cpp index 23c738cd..77d2b52d 100644 --- a/src/catch2/reporters/catch_reporter_combined_tu.cpp +++ b/src/catch2/reporters/catch_reporter_combined_tu.cpp @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/catch2/reporters/catch_reporter_console.cpp b/src/catch2/reporters/catch_reporter_console.cpp index b8e64fb3..6b564b15 100644 --- a/src/catch2/reporters/catch_reporter_console.cpp +++ b/src/catch2/reporters/catch_reporter_console.cpp @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/tests/SelfTest/IntrospectiveTests/Xml.tests.cpp b/tests/SelfTest/IntrospectiveTests/Xml.tests.cpp index 678d8c87..226e737c 100644 --- a/tests/SelfTest/IntrospectiveTests/Xml.tests.cpp +++ b/tests/SelfTest/IntrospectiveTests/Xml.tests.cpp @@ -9,7 +9,7 @@ #include #include -#include +#include #include #include