Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMartin Hořeňovský2022-03-27 23:35:41 +0200
committerMartin Hořeňovský2022-03-28 13:10:13 +0200
commit1a8a793178d50b74b0f9a0adb3eec937b61039a9 (patch)
tree2a8cadf3fa4478f1a11548485a4a0389d4920d2d
parenta4e4e82474f894d56cbe86e13a2d23bb1b46744d (diff)
downloadcatch3-1a8a793178d50b74b0f9a0adb3eec937b61039a9.tar.gz
Refactor colour handling to prepare for per-reporter colour modes
This includes always compiling the ANSI and None colour implementations, as they don't need to touch any platform specific APIs, and removing their respective compile-time configuration options. Because the Win32 colour implementation requires Win32-specific APIs, it is still hidden behind a compile-time toggle, `CATCH_CONFIG_COLOUR_WIN32` (renamed from `..._COLOUR_WINDOWS`). The commandline options for colours were also changed. The option now uses different name, and allows to select between different implementations, rather than changing whether the compiled-in colour implementation is used through "yes/no/default" options.
-rw-r--r--BUILD.bazel4
-rw-r--r--CMake/CatchConfigOptions.cmake4
-rw-r--r--docs/command-line.md26
-rw-r--r--docs/configuration.md17
-rw-r--r--docs/release-notes.md7
-rw-r--r--src/catch2/catch_config.cpp2
-rw-r--r--src/catch2/catch_config.hpp4
-rw-r--r--src/catch2/catch_session.cpp5
-rw-r--r--src/catch2/catch_user_config.hpp.in9
-rw-r--r--src/catch2/interfaces/catch_interfaces_config.hpp15
-rw-r--r--src/catch2/internal/catch_commandline.cpp54
-rw-r--r--src/catch2/internal/catch_compiler_capabilities.hpp13
-rw-r--r--src/catch2/internal/catch_console_colour.cpp110
-rw-r--r--src/catch2/internal/catch_console_colour.hpp8
-rw-r--r--src/catch2/reporters/catch_reporter_common_base.cpp13
-rw-r--r--src/catch2/reporters/catch_reporter_common_base.hpp12
-rw-r--r--tests/CMakeLists.txt11
-rw-r--r--tests/SelfTest/Baselines/compact.sw.approved.txt16
-rw-r--r--tests/SelfTest/Baselines/compact.sw.multi.approved.txt16
-rw-r--r--tests/SelfTest/Baselines/console.sw.approved.txt20
-rw-r--r--tests/SelfTest/Baselines/console.sw.multi.approved.txt20
-rw-r--r--tests/SelfTest/Baselines/tap.sw.approved.txt16
-rw-r--r--tests/SelfTest/Baselines/tap.sw.multi.approved.txt16
-rw-r--r--tests/SelfTest/Baselines/xml.sw.approved.txt18
-rw-r--r--tests/SelfTest/Baselines/xml.sw.multi.approved.txt18
-rw-r--r--tests/SelfTest/IntrospectiveTests/CmdLine.tests.cpp34
-rw-r--r--tests/SelfTest/IntrospectiveTests/Reporters.tests.cpp5
27 files changed, 291 insertions, 202 deletions
diff --git a/BUILD.bazel b/BUILD.bazel
index 9b7d608d..604c5fb8 100644
--- a/BUILD.bazel
+++ b/BUILD.bazel
@@ -8,9 +8,7 @@ expand_template(
out = "catch2/catch_user_config.hpp",
substitutions = {
"#cmakedefine CATCH_CONFIG_ANDROID_LOGWRITE": "",
- "#cmakedefine CATCH_CONFIG_COLOUR_ANSI": "",
- "#cmakedefine CATCH_CONFIG_COLOUR_NONE": "",
- "#cmakedefine CATCH_CONFIG_COLOUR_WINDOWS": "",
+ "#cmakedefine CATCH_CONFIG_COLOUR_WIN32": "",
"#cmakedefine CATCH_CONFIG_COUNTER": "",
"#cmakedefine CATCH_CONFIG_CPP11_TO_STRING": "",
"#cmakedefine CATCH_CONFIG_CPP17_BYTE": "",
diff --git a/CMake/CatchConfigOptions.cmake b/CMake/CatchConfigOptions.cmake
index 54cf0ab9..78491525 100644
--- a/CMake/CatchConfigOptions.cmake
+++ b/CMake/CatchConfigOptions.cmake
@@ -26,6 +26,7 @@ endmacro()
set(_OverridableOptions
"ANDROID_LOGWRITE"
+ "COLOUR_WIN32"
"COUNTER"
"CPP11_TO_STRING"
"CPP17_BYTE"
@@ -45,9 +46,6 @@ foreach(OptionName ${_OverridableOptions})
endforeach()
set(_OtherConfigOptions
- "COLOUR_ANSI"
- "COLOUR_NONE"
- "COLOUR_WINDOWS"
"DISABLE_EXCEPTIONS"
"DISABLE_EXCEPTIONS_CUSTOM_HANDLER"
"DISABLE"
diff --git a/docs/command-line.md b/docs/command-line.md
index 7ace0530..29e6a365 100644
--- a/docs/command-line.md
+++ b/docs/command-line.md
@@ -67,7 +67,7 @@ Click one of the following links to take you straight to that option - or scroll
<a href="#benchmark-confidence-interval"> ` --benchmark-confidence-interval`</a><br />
<a href="#benchmark-no-analysis"> ` --benchmark-no-analysis`</a><br />
<a href="#benchmark-warmup-time"> ` --benchmark-warmup-time`</a><br />
-<a href="#use-colour"> ` --use-colour`</a><br />
+<a href="#colour-mode"> ` --colour-mode`</a><br />
<a href="#test-sharding"> ` --shard-count`</a><br />
<a href="#test-sharding"> ` --shard-index`</a><br />
<a href=#no-tests-override> ` --allow-running-no-tests`</a><br />
@@ -457,16 +457,26 @@ filename it is found in, with any extension stripped, prefixed with the `#` char
So, for example, tests within the file `~\Dev\MyProject\Ferrets.cpp` would be tagged `[#Ferrets]`.
-<a id="use-colour"></a>
+<a id="colour-mode"></a>
## Override output colouring
-<pre>--use-colour &lt;yes|no|auto&gt;</pre>
+<pre>--colour-mode &lt;ansi|win32|none|default&gt;</pre>
-Catch colours output for terminals, but omits colouring when it detects that
-output is being sent to a pipe. This is done to avoid interfering with automated
-processing of output.
+Catch2 support two different ways of colouring terminal output, and by
+default it attempts to make a good guess on which implementation to use
+(and whether to even use it, e.g. Catch2 tries to avoid writing colour
+codes when writing the results into a file).
+
+`--colour-mode` allows the user to explicitly select what happens.
+
+* `--colour-mode ansi` tells Catch2 to always use ANSI colour codes, even
+when writing to a file
+* `--colour-mode win32` tells Catch2 to use colour implementation based
+ on Win32 terminal API
+* `--colour-mode none` tells Catch2 to disable colours completely
+* `--colour-mode default` lets Catch2 decide
+
+`--colour-mode default` is the default setting.
-`--use-colour yes` forces coloured output, `--use-colour no` disables coloured
-output. The default behaviour is `--use-colour auto`.
<a id="test-sharding"></a>
## Test Sharding
diff --git a/docs/configuration.md b/docs/configuration.md
index a7db4b13..5105f6d9 100644
--- a/docs/configuration.md
+++ b/docs/configuration.md
@@ -31,19 +31,18 @@ To keep test code clean and uncluttered Catch uses short macro names (e.g. ```TE
## Terminal colour
- CATCH_CONFIG_COLOUR_NONE // completely disables all text colouring
- CATCH_CONFIG_COLOUR_WINDOWS // forces the Win32 console API to be used
- CATCH_CONFIG_COLOUR_ANSI // forces ANSI colour codes to be used
+ CATCH_CONFIG_COLOUR_WIN32 // Force enables compiling colouring impl based on Win32 console API
+ CATCH_CONFIG_NO_COLOUR_WIN32 // Force disables ...
-Yes, I am English, so I will continue to spell "colour" with a 'u'.
+Yes, Catch2 uses the british spelling of colour.
-When sending output to the terminal, if it detects that it can, Catch will use colourised text. On Windows the Win32 API, ```SetConsoleTextAttribute```, is used. On POSIX systems ANSI colour escape codes are inserted into the stream.
+Catch2 attempts to autodetect whether the Win32 console colouring API,
+`SetConsoleTextAttribute`, is available, and if it is available it compiles
+in a console colouring implementation that uses it.
-For finer control you can define one of the above identifiers (these are mutually exclusive - but that is not checked so may behave unexpectedly if you mix them):
+This option can be used to override Catch2's autodetection and force the
+compilation either ON or OFF.
-Note that when ANSI colour codes are used "unistd.h" must be includable - along with a definition of ```isatty()```
-
-Typically you should place the ```#define``` before #including "catch.hpp" in your main source file - but if you prefer you can define it for your whole project by whatever your IDE or build system provides for you to do so.
## Console width
diff --git a/docs/release-notes.md b/docs/release-notes.md
index 60f38b77..ca64106e 100644
--- a/docs/release-notes.md
+++ b/docs/release-notes.md
@@ -179,6 +179,13 @@ v3 releases.
* To support this, the `-r`, `--reporter` flag now also accepts optional output destination
* For full overview of the semantics of using multiple reporters, look into the reporter documentation
* To enable the new syntax, reporter names can no longer contain `::`.
+* Console colour support has been rewritten and significantly improved
+ * The colour implementation based on ANSI colour codes is always available
+ * Colour implementations respect their associated stream
+ * previously e.g. Win32 impl would change console colour even if Catch2 was writing to a file
+ * The colour API is resilient against changing evaluation order of expressions
+ * The associated CLI flag and compile-time configuration options have changed
+ * For details see the docs for command-line and compile-time Catch2 configuration
### Fixes
diff --git a/src/catch2/catch_config.cpp b/src/catch2/catch_config.cpp
index 8541d223..4c8b3319 100644
--- a/src/catch2/catch_config.cpp
+++ b/src/catch2/catch_config.cpp
@@ -138,7 +138,7 @@ namespace Catch {
uint32_t Config::rngSeed() const { return m_data.rngSeed; }
unsigned int Config::shardCount() const { return m_data.shardCount; }
unsigned int Config::shardIndex() const { return m_data.shardIndex; }
- UseColour Config::useColour() const { return m_data.useColour; }
+ ColourMode Config::colourMode() const { return m_data.colourMode; }
bool Config::shouldDebugBreak() const { return m_data.shouldDebugBreak; }
int Config::abortAfter() const { return m_data.abortAfter; }
bool Config::showInvisibles() const { return m_data.showInvisibles; }
diff --git a/src/catch2/catch_config.hpp b/src/catch2/catch_config.hpp
index 2a71537d..91ce4e64 100644
--- a/src/catch2/catch_config.hpp
+++ b/src/catch2/catch_config.hpp
@@ -66,7 +66,7 @@ namespace Catch {
ShowDurations showDurations = ShowDurations::DefaultForReporter;
double minDuration = -1;
TestRunOrder runOrder = TestRunOrder::Declared;
- UseColour useColour = UseColour::Auto;
+ ColourMode colourMode = ColourMode::PlatformDefault;
WaitForKeypress::When waitForKeypress = WaitForKeypress::Never;
std::string defaultOutputFilename;
@@ -114,7 +114,7 @@ namespace Catch {
uint32_t rngSeed() const override;
unsigned int shardCount() const override;
unsigned int shardIndex() const override;
- UseColour useColour() const override;
+ ColourMode colourMode() const override;
bool shouldDebugBreak() const override;
int abortAfter() const override;
bool showInvisibles() const override;
diff --git a/src/catch2/catch_session.cpp b/src/catch2/catch_session.cpp
index c685e48b..6af52685 100644
--- a/src/catch2/catch_session.cpp
+++ b/src/catch2/catch_session.cpp
@@ -152,7 +152,8 @@ namespace Catch {
m_startupExceptions = true;
auto errStream = makeStream( "%stderr" );
- auto colourImpl = makeColourImpl( &config(), errStream.get() );
+ auto colourImpl = makeColourImpl(
+ ColourMode::PlatformDefault, errStream.get() );
auto guard = colourImpl->guardColour( Colour::Red );
errStream->stream() << "Errors occurred during startup!" << '\n';
// iterate over all exceptions and notify user
@@ -197,7 +198,7 @@ namespace Catch {
config();
getCurrentMutableContext().setConfig(m_config.get());
auto errStream = makeStream( "%stderr" );
- auto colour = makeColourImpl( &config(), errStream.get() );
+ auto colour = makeColourImpl( ColourMode::PlatformDefault, errStream.get() );
errStream->stream()
<< colour->guardColour( Colour::Red )
diff --git a/src/catch2/catch_user_config.hpp.in b/src/catch2/catch_user_config.hpp.in
index b3a518f9..911e2dc4 100644
--- a/src/catch2/catch_user_config.hpp.in
+++ b/src/catch2/catch_user_config.hpp.in
@@ -32,7 +32,13 @@
# error Cannot force ANDROID_LOGWRITE to both ON and OFF
#endif
+#cmakedefine CATCH_CONFIG_COLOUR_WIN32
+#cmakedefine CATCH_CONFIG_NO_COLOUR_WIN32
+#if defined( CATCH_CONFIG_COLOUR_WIN32 ) && \
+ defined( CATCH_CONFIG_NO_COLOUR_WIN32 )
+# error Cannot force COLOUR_WIN32 to be ON and OFF
+#endif
#cmakedefine CATCH_CONFIG_COUNTER
#cmakedefine CATCH_CONFIG_NO_COUNTER
@@ -159,9 +165,6 @@
// ------
-#cmakedefine CATCH_CONFIG_COLOUR_ANSI
-#cmakedefine CATCH_CONFIG_COLOUR_NONE
-#cmakedefine CATCH_CONFIG_COLOUR_WINDOWS
#cmakedefine CATCH_CONFIG_DISABLE_EXCEPTIONS
#cmakedefine CATCH_CONFIG_DISABLE_EXCEPTIONS_CUSTOM_HANDLER
#cmakedefine CATCH_CONFIG_DISABLE
diff --git a/src/catch2/interfaces/catch_interfaces_config.hpp b/src/catch2/interfaces/catch_interfaces_config.hpp
index d98f7b44..fb3b2977 100644
--- a/src/catch2/interfaces/catch_interfaces_config.hpp
+++ b/src/catch2/interfaces/catch_interfaces_config.hpp
@@ -42,10 +42,15 @@ namespace Catch {
LexicographicallySorted,
Randomized
};
- enum class UseColour {
- Auto,
- Yes,
- No
+ enum class ColourMode : std::uint8_t {
+ //! Let Catch2 pick implementation based on platform detection
+ PlatformDefault,
+ //! Use ANSI colour code escapes
+ ANSI,
+ //! Use Win32 console colour API
+ Win32,
+ //! Don't use any colour
+ None
};
struct WaitForKeypress { enum When {
Never,
@@ -79,7 +84,7 @@ namespace Catch {
virtual uint32_t rngSeed() const = 0;
virtual unsigned int shardCount() const = 0;
virtual unsigned int shardIndex() const = 0;
- virtual UseColour useColour() const = 0;
+ virtual ColourMode colourMode() const = 0;
virtual std::vector<std::string> const& getSectionsToRun() const = 0;
virtual Verbosity verbosity() const = 0;
diff --git a/src/catch2/internal/catch_commandline.cpp b/src/catch2/internal/catch_commandline.cpp
index 540adc55..6363e47a 100644
--- a/src/catch2/internal/catch_commandline.cpp
+++ b/src/catch2/internal/catch_commandline.cpp
@@ -13,6 +13,7 @@
#include <catch2/interfaces/catch_interfaces_registry_hub.hpp>
#include <catch2/interfaces/catch_interfaces_reporter_registry.hpp>
#include <catch2/interfaces/catch_interfaces_reporter.hpp>
+#include <catch2/internal/catch_console_colour.hpp>
#include <algorithm>
#include <fstream>
@@ -95,19 +96,44 @@ namespace Catch {
return ParserResult::runtimeError("Could not parse '" + seed + "' as seed");
}
};
- auto const setColourUsage = [&]( std::string const& useColour ) {
- auto mode = toLower( useColour );
+ auto const setColourMode = [&]( std::string const&
+ colourMode ) {
+ auto mode = toLower( colourMode );
- if( mode == "yes" )
- config.useColour = UseColour::Yes;
- else if( mode == "no" )
- config.useColour = UseColour::No;
- else if( mode == "auto" )
- config.useColour = UseColour::Auto;
- else
- return ParserResult::runtimeError( "colour mode must be one of: auto, yes or no. '" + useColour + "' not recognised" );
- return ParserResult::ok( ParseResultType::Matched );
- };
+ if ( mode == "default" ) {
+ if ( !isColourImplAvailable( ColourMode::PlatformDefault ) ) {
+ return ParserResult::runtimeError(
+ "colour mode 'default' is not supported in this "
+ "binary" );
+ }
+ config.colourMode = ColourMode::PlatformDefault;
+ } else if ( mode == "ansi" ) {
+ if ( !isColourImplAvailable( ColourMode::ANSI ) ) {
+ return ParserResult::runtimeError(
+ "colour mode 'ansi' is not supported in this binary" );
+ }
+ config.colourMode = ColourMode::ANSI;
+ } else if ( mode == "win32" ) {
+ if ( !isColourImplAvailable( ColourMode::Win32 ) ) {
+ return ParserResult::runtimeError(
+ "colour mode 'win32' is not supported in this "
+ "binary" );
+ }
+ config.colourMode = ColourMode::Win32;
+ } else if ( mode == "none" ) {
+ if ( !isColourImplAvailable( ColourMode::None ) ) {
+ return ParserResult::runtimeError(
+ "colour mode 'none' is not supported in this binary" );
+ }
+ config.colourMode = ColourMode::None;
+ } else {
+ return ParserResult::runtimeError(
+ "colour mode must be one of: default, ansi, win32, "
+ "or none. '" +
+ colourMode + "' not recognised" );
+ }
+ return ParserResult::ok( ParseResultType::Matched );
+ };
auto const setWaitForKeypress = [&]( std::string const& keypress ) {
auto keypressLc = toLower( keypress );
if (keypressLc == "never")
@@ -298,8 +324,8 @@ namespace Catch {
| Opt( setRngSeed, "'time'|'random-device'|number" )
["--rng-seed"]
( "set a specific seed for random numbers" )
- | Opt( setColourUsage, "yes|no|auto" )
- ["--use-colour"]
+ | Opt( setColourMode, "ansi|win32|none|default" )
+ ["--colour-mode"]
( "should output be colourised" )
| Opt( config.libIdentify )
["--libidentify"]
diff --git a/src/catch2/internal/catch_compiler_capabilities.hpp b/src/catch2/internal/catch_compiler_capabilities.hpp
index a72bc0b2..5c5c8f64 100644
--- a/src/catch2/internal/catch_compiler_capabilities.hpp
+++ b/src/catch2/internal/catch_compiler_capabilities.hpp
@@ -116,7 +116,6 @@
#ifdef __OS400__
# define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS
-# define CATCH_CONFIG_COLOUR_NONE
#endif
////////////////////////////////////////////////////////////////////////////////
@@ -164,7 +163,7 @@
// Universal Windows platform does not support SEH
// Or console colours (or console at all...)
# if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP)
-# define CATCH_CONFIG_COLOUR_NONE
+# define CATCH_INTERNAL_CONFIG_NO_COLOUR_WIN32
# else
# define CATCH_INTERNAL_CONFIG_WINDOWS_SEH
# endif
@@ -206,7 +205,7 @@
#if defined(UNDER_RTSS) || defined(RTX64_BUILD)
#define CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH
#define CATCH_INTERNAL_CONFIG_NO_ASYNC
- #define CATCH_CONFIG_COLOUR_NONE
+ #define CATCH_INTERNAL_CONFIG_NO_COLOUR_WIN32
#endif
#if !defined(_GLIBCXX_USE_C99_MATH_TR1)
@@ -358,4 +357,12 @@
#define CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
#endif
+#if defined( CATCH_PLATFORM_WINDOWS ) && \
+ !defined( CATCH_CONFIG_COLOUR_WIN32 ) && \
+ !defined( CATCH_CONFIG_NO_COLOUR_WIN32 ) && \
+ !defined( CATCH_INTERNAL_CONFIG_NO_COLOUR_WIN32 )
+# define CATCH_CONFIG_COLOUR_WIN32
+#endif
+
+
#endif // CATCH_COMPILER_CAPABILITIES_HPP_INCLUDED
diff --git a/src/catch2/internal/catch_console_colour.cpp b/src/catch2/internal/catch_console_colour.cpp
index b7b4b4fb..67f0d98a 100644
--- a/src/catch2/internal/catch_console_colour.cpp
+++ b/src/catch2/internal/catch_console_colour.cpp
@@ -20,6 +20,7 @@
#include <catch2/internal/catch_platform.hpp>
#include <catch2/internal/catch_debugger.hpp>
#include <catch2/internal/catch_windows_h_proxy.hpp>
+#include <catch2/internal/catch_compiler_capabilities.hpp>
#include <ostream>
@@ -31,20 +32,6 @@ namespace Catch {
return ColourGuard(colourCode, this );
}
- namespace {
- //! A do-nothing implementation of colour, used as fallback for unknown
- //! platforms, and when the user asks to deactivate all colours.
- class NoColourImpl : public ColourImpl {
- public:
- NoColourImpl( IStream const* stream ): ColourImpl( stream ) {}
- static bool useColourOnPlatform() { return true; }
-
- private:
- void use( Colour::Code ) const override {}
- };
-
- } // namespace
-
void ColourImpl::ColourGuard::engageImpl( std::ostream& stream ) {
assert( &stream == &m_colourImpl->m_stream->stream() &&
"Engaging colour guard for different stream than used by the "
@@ -92,18 +79,24 @@ namespace Catch {
return CATCH_MOVE(*this);
}
-} // namespace Catch
+ namespace {
+ //! A do-nothing implementation of colour, used as fallback for unknown
+ //! platforms, and when the user asks to deactivate all colours.
+ class NoColourImpl : public ColourImpl {
+ public:
+ NoColourImpl( IStream const* stream ): ColourImpl( stream ) {}
+ static bool useColourOnPlatform() { return true; }
-#if !defined( CATCH_CONFIG_COLOUR_NONE ) && !defined( CATCH_CONFIG_COLOUR_WINDOWS ) && !defined( CATCH_CONFIG_COLOUR_ANSI )
-# ifdef CATCH_PLATFORM_WINDOWS
-# define CATCH_CONFIG_COLOUR_WINDOWS
-# else
-# define CATCH_CONFIG_COLOUR_ANSI
-# endif
-#endif
+ private:
+ void use( Colour::Code ) const override {}
+ };
+ } // namespace
-#if defined ( CATCH_CONFIG_COLOUR_WINDOWS ) /////////////////////////////////////////
+} // namespace Catch
+
+
+#if defined ( CATCH_CONFIG_COLOUR_WIN32 ) /////////////////////////////////////////
namespace Catch {
namespace {
@@ -174,13 +167,9 @@ namespace {
namespace Catch {
namespace {
- // use POSIX/ ANSI console terminal codes
- // Thanks to Adam Strzelecki for original contribution
- // (http://github.com/nanoant)
- // https://github.com/philsquared/Catch/pull/131
- class PosixColourImpl : public ColourImpl {
+ class ANSIColourImpl : public ColourImpl {
public:
- PosixColourImpl( IStream const* stream ): ColourImpl( stream ) {}
+ ANSIColourImpl( IStream const* stream ): ColourImpl( stream ) {}
static bool useColourOnPlatform(IStream const& stream) {
// This is kinda messy due to trying to support a bunch of
@@ -239,41 +228,50 @@ namespace {
namespace Catch {
- Detail::unique_ptr<ColourImpl> makeColourImpl(IConfig const* config, IStream const* stream) {
- UseColour colourMode = config ? config->useColour() : UseColour::Auto;
-
- bool createPlatformInstance = false;
- if ( colourMode == UseColour::No ) {
- createPlatformInstance = false;
+ Detail::unique_ptr<ColourImpl> makeColourImpl( ColourMode implSelection,
+ IStream const* stream ) {
+ if ( implSelection == ColourMode::None ) {
+ return Detail::make_unique<NoColourImpl>( stream );
}
-
- if ( colourMode == UseColour::Yes ) {
- createPlatformInstance = true;
+ if ( implSelection == ColourMode::ANSI ) {
+ return Detail::make_unique<ANSIColourImpl>( stream );
}
+#if defined( CATCH_CONFIG_COLOUR_WIN32 )
+ if ( implSelection == ColourMode::Win32 ) {
+ return Detail::make_unique<Win32ColourImpl>( stream );
+ }
+#endif
- if ( colourMode == UseColour::Auto ) {
- createPlatformInstance =
-#if defined( CATCH_CONFIG_COLOUR_ANSI )
- PosixColourImpl::useColourOnPlatform( *stream )
-#elif defined( CATCH_CONFIG_COLOUR_WINDOWS )
- Win32ColourImpl::useColourOnPlatform( *stream )
-#else
- false
+ // todo: check win32 eligibility under ifdef, otherwise ansi
+ if ( implSelection == ColourMode::PlatformDefault) {
+#if defined (CATCH_CONFIG_COLOUR_WIN32)
+ if ( Win32ColourImpl::useColourOnPlatform( *stream ) ) {
+ return Detail::make_unique<Win32ColourImpl>( stream );
+ } else {
+ return Detail::make_unique<NoColourImpl>( stream );
+ }
#endif
- ;
+ if ( ANSIColourImpl::useColourOnPlatform( *stream ) ) {
+ return Detail::make_unique<ANSIColourImpl>( stream );
+ }
+ return Detail::make_unique<NoColourImpl>( stream );
}
- if ( createPlatformInstance ) {
- return
-#if defined( CATCH_CONFIG_COLOUR_ANSI )
- Detail::make_unique<PosixColourImpl>(stream);
-#elif defined( CATCH_CONFIG_COLOUR_WINDOWS )
- Detail::make_unique<Win32ColourImpl>(stream);
-#else
- Detail::make_unique<NoColourImpl>(stream);
+ CATCH_ERROR( "Could not create colour impl for selection " << static_cast<int>(implSelection) );
+ }
+
+ bool isColourImplAvailable( ColourMode colourSelection ) {
+ switch ( colourSelection ) {
+#if defined( CATCH_CONFIG_COLOUR_WIN32 )
+ case ColourMode::Win32:
#endif
+ case ColourMode::ANSI:
+ case ColourMode::None:
+ case ColourMode::PlatformDefault:
+ return true;
+ default:
+ return false;
}
- return Detail::make_unique<NoColourImpl>(stream);
}
diff --git a/src/catch2/internal/catch_console_colour.hpp b/src/catch2/internal/catch_console_colour.hpp
index 7b8f5b7a..7f91a5fc 100644
--- a/src/catch2/internal/catch_console_colour.hpp
+++ b/src/catch2/internal/catch_console_colour.hpp
@@ -11,9 +11,11 @@
#include <catch2/internal/catch_unique_ptr.hpp>
#include <iosfwd>
+#include <cstdint>
namespace Catch {
+ enum class ColourMode : std::uint8_t;
struct IConfig;
class IStream;
@@ -128,7 +130,11 @@ namespace Catch {
};
//! Provides ColourImpl based on global config and target compilation platform
- Detail::unique_ptr<ColourImpl> makeColourImpl( IConfig const* config, IStream const* stream );
+ Detail::unique_ptr<ColourImpl> makeColourImpl( ColourMode colourSelection,
+ IStream const* stream );
+
+ //! Checks if specific colour impl has been compiled into the binary
+ bool isColourImplAvailable( ColourMode colourSelection );
} // end namespace Catch
diff --git a/src/catch2/reporters/catch_reporter_common_base.cpp b/src/catch2/reporters/catch_reporter_common_base.cpp
index d49c2edb..85092db8 100644
--- a/src/catch2/reporters/catch_reporter_common_base.cpp
+++ b/src/catch2/reporters/catch_reporter_common_base.cpp
@@ -9,10 +9,21 @@
#include <catch2/reporters/catch_reporter_common_base.hpp>
#include <catch2/reporters/catch_reporter_helpers.hpp>
+#include <catch2/internal/catch_console_colour.hpp>
+#include <catch2/internal/catch_stream.hpp>
+
namespace Catch {
+ ReporterBase::ReporterBase( ReporterConfig const& config ):
+ IEventListener( config.fullConfig() ),
+ m_wrapped_stream( config.stream() ),
+ m_stream( m_wrapped_stream->stream() ),
+ m_colour( makeColourImpl( m_config->colourMode(), m_wrapped_stream ) ) {}
+
+ ReporterBase::~ReporterBase() = default;
- void ReporterBase::listReporters(std::vector<ReporterDescription> const& descriptions) {
+ void ReporterBase::listReporters(
+ std::vector<ReporterDescription> const& descriptions ) {
defaultListReporters(m_stream, descriptions, m_config->verbosity());
}
diff --git a/src/catch2/reporters/catch_reporter_common_base.hpp b/src/catch2/reporters/catch_reporter_common_base.hpp
index b69e5311..ba7ab116 100644
--- a/src/catch2/reporters/catch_reporter_common_base.hpp
+++ b/src/catch2/reporters/catch_reporter_common_base.hpp