Split out Catch::cout/cerr/clog into their own file

This commit is contained in:
Martin Hořeňovský 2022-04-16 14:12:56 +02:00
parent b520257676
commit 05e85c5652
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
14 changed files with 66 additions and 19 deletions

View File

@ -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

View File

@ -91,6 +91,7 @@
#include <catch2/internal/catch_singletons.hpp>
#include <catch2/internal/catch_source_line_info.hpp>
#include <catch2/internal/catch_startup_exception_registry.hpp>
#include <catch2/internal/catch_stdstreams.hpp>
#include <catch2/internal/catch_stream.hpp>
#include <catch2/internal/catch_stream_end_stop.hpp>
#include <catch2/internal/catch_string_manip.hpp>

View File

@ -11,7 +11,6 @@
#include <catch2/internal/catch_list.hpp>
#include <catch2/internal/catch_context.hpp>
#include <catch2/internal/catch_run_context.hpp>
#include <catch2/internal/catch_stream.hpp>
#include <catch2/catch_test_spec.hpp>
#include <catch2/catch_version.hpp>
#include <catch2/interfaces/catch_interfaces_reporter.hpp>
@ -23,6 +22,7 @@
#include <catch2/interfaces/catch_interfaces_reporter_registry.hpp>
#include <catch2/interfaces/catch_interfaces_reporter_factory.hpp>
#include <catch2/internal/catch_move_and_forward.hpp>
#include <catch2/internal/catch_stdstreams.hpp>
#include <algorithm>
#include <cassert>

View File

@ -5,13 +5,15 @@
// https://www.boost.org/LICENSE_1_0.txt)
// SPDX-License-Identifier: BSL-1.0
#include <catch2/internal/catch_debug_console.hpp>
#include <catch2/internal/catch_config_android_logwrite.hpp>
#include <catch2/internal/catch_stream.hpp>
#include <catch2/internal/catch_platform.hpp>
#include <catch2/internal/catch_windows_h_proxy.hpp>
#include <iosfwd>
#include <catch2/catch_user_config.hpp>
#include <catch2/internal/catch_stdstreams.hpp>
#if defined(CATCH_CONFIG_ANDROID_LOGWRITE)
#include <android/log.h>

View File

@ -9,6 +9,7 @@
#include <catch2/internal/catch_errno_guard.hpp>
#include <catch2/internal/catch_stream.hpp>
#include <catch2/internal/catch_platform.hpp>
#include <catch2/internal/catch_stdstreams.hpp>
#if defined(CATCH_PLATFORM_MAC) || defined(CATCH_PLATFORM_IPHONE)

View File

@ -6,6 +6,7 @@
// SPDX-License-Identifier: BSL-1.0
#include <catch2/internal/catch_enforce.hpp>
#include <catch2/internal/catch_stdstreams.hpp>
#include <stdexcept>

View File

@ -30,6 +30,7 @@
#include <catch2/internal/catch_enforce.hpp>
#include <catch2/interfaces/catch_interfaces_capture.hpp>
#include <catch2/internal/catch_windows_h_proxy.hpp>
#include <catch2/internal/catch_stdstreams.hpp>
#include <algorithm>

View File

@ -7,6 +7,7 @@
// SPDX-License-Identifier: BSL-1.0
#include <catch2/internal/catch_output_redirect.hpp>
#include <catch2/internal/catch_enforce.hpp>
#include <catch2/internal/catch_stdstreams.hpp>
#include <cstdio>
#include <cstring>

View File

@ -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 <catch2/internal/catch_stdstreams.hpp>
#include <catch2/catch_user_config.hpp>
#include <iostream>
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

View File

@ -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 <iosfwd>
namespace Catch {
std::ostream& cout();
std::ostream& cerr();
std::ostream& clog();
} // namespace Catch
#endif

View File

@ -11,9 +11,9 @@
#include <catch2/internal/catch_stringref.hpp>
#include <catch2/internal/catch_singletons.hpp>
#include <catch2/internal/catch_unique_ptr.hpp>
#include <catch2/internal/catch_stdstreams.hpp>
#include <cstdio>
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
@ -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
}

View File

@ -18,10 +18,6 @@
namespace Catch {
std::ostream& cout();
std::ostream& cerr();
std::ostream& clog();
class IStream {
public:
virtual ~IStream(); // = default

View File

@ -9,7 +9,9 @@
#include <catch2/catch_config.hpp>
#include <catch2/internal/catch_move_and_forward.hpp>
#include <catch2/internal/catch_stream.hpp>
#include <catch2/internal/catch_stdstreams.hpp>
#include <ostream>
namespace Catch {
void MultiReporter::updatePreferences(IEventListener const& reporterish) {

View File

@ -8,10 +8,12 @@
#include <catch2/catch_test_macros.hpp>
#include <iostream>
namespace Catch {
[[noreturn]]
void throw_exception(std::exception const& e) {
Catch::cerr() << "====== CUSTOM HANDLER ====== run terminates because an exception was thrown.\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.