mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-25 23:06:10 +01:00
Make IStream::stream non-const
This way it makes much more sense from logically-const point of view, and also means that concrete implementations don't have to always have a `mutable` keyword on the stream member.
This commit is contained in:
parent
9934b7de13
commit
4f09f1120b
@ -108,8 +108,8 @@ namespace Catch {
|
|||||||
return m_data.reporterSpecifications;
|
return m_data.reporterSpecifications;
|
||||||
}
|
}
|
||||||
|
|
||||||
IStream const* Config::getReporterOutputStream(std::size_t reporterIdx) const {
|
IStream* Config::getReporterOutputStream(std::size_t reporterIdx) const {
|
||||||
return m_reporterStreams.at(reporterIdx).get();
|
return const_cast<IStream*>(m_reporterStreams.at(reporterIdx).get());
|
||||||
}
|
}
|
||||||
|
|
||||||
TestSpec const& Config::testSpec() const { return m_testSpec; }
|
TestSpec const& Config::testSpec() const { return m_testSpec; }
|
||||||
|
@ -81,7 +81,7 @@ namespace Catch {
|
|||||||
bool listReporters() const;
|
bool listReporters() const;
|
||||||
|
|
||||||
std::vector<ReporterSpec> const& getReporterSpecs() const;
|
std::vector<ReporterSpec> const& getReporterSpecs() const;
|
||||||
IStream const* getReporterOutputStream(std::size_t reporterIdx) const;
|
IStream* getReporterOutputStream(std::size_t reporterIdx) const;
|
||||||
|
|
||||||
std::vector<std::string> const& getTestsOrTags() const override;
|
std::vector<std::string> const& getTestsOrTags() const override;
|
||||||
std::vector<std::string> const& getSectionsToRun() const override;
|
std::vector<std::string> const& getSectionsToRun() const override;
|
||||||
@ -118,7 +118,7 @@ namespace Catch {
|
|||||||
private:
|
private:
|
||||||
ConfigData m_data;
|
ConfigData m_data;
|
||||||
|
|
||||||
std::vector<Detail::unique_ptr<IStream const>> m_reporterStreams;
|
std::vector<Detail::unique_ptr<IStream>> m_reporterStreams;
|
||||||
TestSpec m_testSpec;
|
TestSpec m_testSpec;
|
||||||
bool m_hasTestFilters = false;
|
bool m_hasTestFilters = false;
|
||||||
};
|
};
|
||||||
|
@ -23,7 +23,7 @@ namespace Catch {
|
|||||||
|
|
||||||
ReporterConfig::ReporterConfig(
|
ReporterConfig::ReporterConfig(
|
||||||
IConfig const* _fullConfig,
|
IConfig const* _fullConfig,
|
||||||
IStream const* _stream,
|
IStream* _stream,
|
||||||
ColourMode colourMode,
|
ColourMode colourMode,
|
||||||
std::map<std::string, std::string> customOptions ):
|
std::map<std::string, std::string> customOptions ):
|
||||||
m_stream( _stream ),
|
m_stream( _stream ),
|
||||||
@ -31,7 +31,7 @@ namespace Catch {
|
|||||||
m_colourMode( colourMode ),
|
m_colourMode( colourMode ),
|
||||||
m_customOptions( CATCH_MOVE( customOptions ) ) {}
|
m_customOptions( CATCH_MOVE( customOptions ) ) {}
|
||||||
|
|
||||||
IStream const* ReporterConfig::stream() const { return m_stream; }
|
IStream* ReporterConfig::stream() const { return m_stream; }
|
||||||
IConfig const * ReporterConfig::fullConfig() const { return m_fullConfig; }
|
IConfig const * ReporterConfig::fullConfig() const { return m_fullConfig; }
|
||||||
ColourMode ReporterConfig::colourMode() const { return m_colourMode; }
|
ColourMode ReporterConfig::colourMode() const { return m_colourMode; }
|
||||||
|
|
||||||
|
@ -36,17 +36,17 @@ namespace Catch {
|
|||||||
|
|
||||||
struct ReporterConfig {
|
struct ReporterConfig {
|
||||||
ReporterConfig( IConfig const* _fullConfig,
|
ReporterConfig( IConfig const* _fullConfig,
|
||||||
IStream const* _stream,
|
IStream* _stream,
|
||||||
ColourMode colourMode,
|
ColourMode colourMode,
|
||||||
std::map<std::string, std::string> customOptions );
|
std::map<std::string, std::string> customOptions );
|
||||||
|
|
||||||
IStream const* stream() const;
|
IStream* stream() const;
|
||||||
IConfig const* fullConfig() const;
|
IConfig const* fullConfig() const;
|
||||||
ColourMode colourMode() const;
|
ColourMode colourMode() const;
|
||||||
std::map<std::string, std::string> const& customOptions() const;
|
std::map<std::string, std::string> const& customOptions() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
IStream const* m_stream;
|
IStream* m_stream;
|
||||||
IConfig const* m_fullConfig;
|
IConfig const* m_fullConfig;
|
||||||
ColourMode m_colourMode;
|
ColourMode m_colourMode;
|
||||||
std::map<std::string, std::string> m_customOptions;
|
std::map<std::string, std::string> m_customOptions;
|
||||||
|
@ -84,7 +84,7 @@ namespace Catch {
|
|||||||
//! platforms, and when the user asks to deactivate all colours.
|
//! platforms, and when the user asks to deactivate all colours.
|
||||||
class NoColourImpl : public ColourImpl {
|
class NoColourImpl : public ColourImpl {
|
||||||
public:
|
public:
|
||||||
NoColourImpl( IStream const* stream ): ColourImpl( stream ) {}
|
NoColourImpl( IStream* stream ): ColourImpl( stream ) {}
|
||||||
static bool useColourOnPlatform() { return true; }
|
static bool useColourOnPlatform() { return true; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -103,7 +103,7 @@ namespace {
|
|||||||
|
|
||||||
class Win32ColourImpl : public ColourImpl {
|
class Win32ColourImpl : public ColourImpl {
|
||||||
public:
|
public:
|
||||||
Win32ColourImpl(IStream const* stream):
|
Win32ColourImpl(IStream* stream):
|
||||||
ColourImpl(stream) {
|
ColourImpl(stream) {
|
||||||
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
|
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
|
||||||
GetConsoleScreenBufferInfo( GetStdHandle( STD_OUTPUT_HANDLE ),
|
GetConsoleScreenBufferInfo( GetStdHandle( STD_OUTPUT_HANDLE ),
|
||||||
@ -169,7 +169,7 @@ namespace {
|
|||||||
|
|
||||||
class ANSIColourImpl : public ColourImpl {
|
class ANSIColourImpl : public ColourImpl {
|
||||||
public:
|
public:
|
||||||
ANSIColourImpl( IStream const* stream ): ColourImpl( stream ) {}
|
ANSIColourImpl( IStream* stream ): ColourImpl( stream ) {}
|
||||||
|
|
||||||
static bool useColourOnPlatform(IStream const& stream) {
|
static bool useColourOnPlatform(IStream const& stream) {
|
||||||
// This is kinda messy due to trying to support a bunch of
|
// This is kinda messy due to trying to support a bunch of
|
||||||
@ -229,7 +229,7 @@ namespace {
|
|||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
Detail::unique_ptr<ColourImpl> makeColourImpl( ColourMode implSelection,
|
Detail::unique_ptr<ColourImpl> makeColourImpl( ColourMode implSelection,
|
||||||
IStream const* stream ) {
|
IStream* stream ) {
|
||||||
if ( implSelection == ColourMode::None ) {
|
if ( implSelection == ColourMode::None ) {
|
||||||
return Detail::make_unique<NoColourImpl>( stream );
|
return Detail::make_unique<NoColourImpl>( stream );
|
||||||
}
|
}
|
||||||
|
@ -60,9 +60,9 @@ namespace Catch {
|
|||||||
class ColourImpl {
|
class ColourImpl {
|
||||||
protected:
|
protected:
|
||||||
//! The associated stream of this ColourImpl instance
|
//! The associated stream of this ColourImpl instance
|
||||||
IStream const* m_stream;
|
IStream* m_stream;
|
||||||
public:
|
public:
|
||||||
ColourImpl( IStream const* stream ): m_stream( stream ) {}
|
ColourImpl( IStream* stream ): m_stream( stream ) {}
|
||||||
|
|
||||||
//! RAII wrapper around writing specific colour of text using specific
|
//! RAII wrapper around writing specific colour of text using specific
|
||||||
//! colour impl into a stream.
|
//! colour impl into a stream.
|
||||||
@ -131,7 +131,7 @@ namespace Catch {
|
|||||||
|
|
||||||
//! Provides ColourImpl based on global config and target compilation platform
|
//! Provides ColourImpl based on global config and target compilation platform
|
||||||
Detail::unique_ptr<ColourImpl> makeColourImpl( ColourMode colourSelection,
|
Detail::unique_ptr<ColourImpl> makeColourImpl( ColourMode colourSelection,
|
||||||
IStream const* stream );
|
IStream* stream );
|
||||||
|
|
||||||
//! Checks if specific colour impl has been compiled into the binary
|
//! Checks if specific colour impl has been compiled into the binary
|
||||||
bool isColourImplAvailable( ColourMode colourSelection );
|
bool isColourImplAvailable( ColourMode colourSelection );
|
||||||
|
@ -74,7 +74,7 @@ namespace Detail {
|
|||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
class FileStream : public IStream {
|
class FileStream : public IStream {
|
||||||
mutable std::ofstream m_ofs;
|
std::ofstream m_ofs;
|
||||||
public:
|
public:
|
||||||
FileStream( std::string const& filename ) {
|
FileStream( std::string const& filename ) {
|
||||||
m_ofs.open( filename.c_str() );
|
m_ofs.open( filename.c_str() );
|
||||||
@ -82,7 +82,7 @@ namespace Detail {
|
|||||||
}
|
}
|
||||||
~FileStream() override = default;
|
~FileStream() override = default;
|
||||||
public: // IStream
|
public: // IStream
|
||||||
std::ostream& stream() const override {
|
std::ostream& stream() override {
|
||||||
return m_ofs;
|
return m_ofs;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -90,7 +90,7 @@ namespace Detail {
|
|||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
class CoutStream : public IStream {
|
class CoutStream : public IStream {
|
||||||
mutable std::ostream m_os;
|
std::ostream m_os;
|
||||||
public:
|
public:
|
||||||
// Store the streambuf from cout up-front because
|
// Store the streambuf from cout up-front because
|
||||||
// cout may get redirected when running tests
|
// cout may get redirected when running tests
|
||||||
@ -98,12 +98,12 @@ namespace Detail {
|
|||||||
~CoutStream() override = default;
|
~CoutStream() override = default;
|
||||||
|
|
||||||
public: // IStream
|
public: // IStream
|
||||||
std::ostream& stream() const override { return m_os; }
|
std::ostream& stream() override { return m_os; }
|
||||||
bool isConsole() const override { return true; }
|
bool isConsole() const override { return true; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class CerrStream : public IStream {
|
class CerrStream : public IStream {
|
||||||
mutable std::ostream m_os;
|
std::ostream m_os;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Store the streambuf from cerr up-front because
|
// Store the streambuf from cerr up-front because
|
||||||
@ -112,7 +112,7 @@ namespace Detail {
|
|||||||
~CerrStream() override = default;
|
~CerrStream() override = default;
|
||||||
|
|
||||||
public: // IStream
|
public: // IStream
|
||||||
std::ostream& stream() const override { return m_os; }
|
std::ostream& stream() override { return m_os; }
|
||||||
bool isConsole() const override { return true; }
|
bool isConsole() const override { return true; }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -120,7 +120,7 @@ namespace Detail {
|
|||||||
|
|
||||||
class DebugOutStream : public IStream {
|
class DebugOutStream : public IStream {
|
||||||
Detail::unique_ptr<StreamBufImpl<OutputDebugWriter>> m_streamBuf;
|
Detail::unique_ptr<StreamBufImpl<OutputDebugWriter>> m_streamBuf;
|
||||||
mutable std::ostream m_os;
|
std::ostream m_os;
|
||||||
public:
|
public:
|
||||||
DebugOutStream()
|
DebugOutStream()
|
||||||
: m_streamBuf( Detail::make_unique<StreamBufImpl<OutputDebugWriter>>() ),
|
: m_streamBuf( Detail::make_unique<StreamBufImpl<OutputDebugWriter>>() ),
|
||||||
@ -130,7 +130,7 @@ namespace Detail {
|
|||||||
~DebugOutStream() override = default;
|
~DebugOutStream() override = default;
|
||||||
|
|
||||||
public: // IStream
|
public: // IStream
|
||||||
std::ostream& stream() const override { return m_os; }
|
std::ostream& stream() override { return m_os; }
|
||||||
};
|
};
|
||||||
|
|
||||||
} // unnamed namespace
|
} // unnamed namespace
|
||||||
@ -138,7 +138,7 @@ namespace Detail {
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
auto makeStream( std::string const& filename ) -> Detail::unique_ptr<IStream const> {
|
auto makeStream( std::string const& filename ) -> Detail::unique_ptr<IStream> {
|
||||||
if ( filename.empty() || filename == "-" ) {
|
if ( filename.empty() || filename == "-" ) {
|
||||||
return Detail::make_unique<Detail::CoutStream>();
|
return Detail::make_unique<Detail::CoutStream>();
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ namespace Catch {
|
|||||||
class IStream {
|
class IStream {
|
||||||
public:
|
public:
|
||||||
virtual ~IStream(); // = default
|
virtual ~IStream(); // = default
|
||||||
virtual std::ostream& stream() const = 0;
|
virtual std::ostream& stream() = 0;
|
||||||
/**
|
/**
|
||||||
* Best guess on whether the instance is writing to a console (e.g. via stdout/stderr)
|
* Best guess on whether the instance is writing to a console (e.g. via stdout/stderr)
|
||||||
*
|
*
|
||||||
@ -51,7 +51,7 @@ namespace Catch {
|
|||||||
*
|
*
|
||||||
* \throws if passed an unrecognized %-prefixed stream
|
* \throws if passed an unrecognized %-prefixed stream
|
||||||
*/
|
*/
|
||||||
auto makeStream( std::string const& filename ) -> Detail::unique_ptr<IStream const>;
|
auto makeStream( std::string const& filename ) -> Detail::unique_ptr<IStream>;
|
||||||
|
|
||||||
class ReusableStringStream : Detail::NonCopyable {
|
class ReusableStringStream : Detail::NonCopyable {
|
||||||
std::size_t m_index;
|
std::size_t m_index;
|
||||||
|
@ -29,7 +29,7 @@ namespace Catch {
|
|||||||
class ReporterBase : public IEventListener {
|
class ReporterBase : public IEventListener {
|
||||||
protected:
|
protected:
|
||||||
//! The stream wrapper as passed to us by outside code
|
//! The stream wrapper as passed to us by outside code
|
||||||
IStream const* m_wrapped_stream;
|
IStream* m_wrapped_stream;
|
||||||
//! Cached output stream from `m_wrapped_stream` to reduce
|
//! Cached output stream from `m_wrapped_stream` to reduce
|
||||||
//! number of indirect calls needed to write output.
|
//! number of indirect calls needed to write output.
|
||||||
std::ostream& m_stream;
|
std::ostream& m_stream;
|
||||||
|
@ -21,9 +21,9 @@ namespace {
|
|||||||
};
|
};
|
||||||
|
|
||||||
class TestStringStream : public Catch::IStream {
|
class TestStringStream : public Catch::IStream {
|
||||||
mutable std::stringstream m_stream;
|
std::stringstream m_stream;
|
||||||
public:
|
public:
|
||||||
std::ostream& stream() const override {
|
std::ostream& stream() override {
|
||||||
return m_stream;
|
return m_stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,10 +29,10 @@
|
|||||||
namespace {
|
namespace {
|
||||||
class StringIStream : public Catch::IStream {
|
class StringIStream : public Catch::IStream {
|
||||||
public:
|
public:
|
||||||
std::ostream& stream() const override { return sstr; }
|
std::ostream& stream() override { return sstr; }
|
||||||
std::string str() const { return sstr.str(); }
|
std::string str() const { return sstr.str(); }
|
||||||
private:
|
private:
|
||||||
mutable std::stringstream sstr;
|
std::stringstream sstr;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user