mirror of
https://github.com/catchorg/Catch2.git
synced 2024-12-22 19:33:29 +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;
|
||||
}
|
||||
|
||||
IStream const* Config::getReporterOutputStream(std::size_t reporterIdx) const {
|
||||
return m_reporterStreams.at(reporterIdx).get();
|
||||
IStream* Config::getReporterOutputStream(std::size_t reporterIdx) const {
|
||||
return const_cast<IStream*>(m_reporterStreams.at(reporterIdx).get());
|
||||
}
|
||||
|
||||
TestSpec const& Config::testSpec() const { return m_testSpec; }
|
||||
|
@ -81,7 +81,7 @@ namespace Catch {
|
||||
bool listReporters() 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& getSectionsToRun() const override;
|
||||
@ -118,7 +118,7 @@ namespace Catch {
|
||||
private:
|
||||
ConfigData m_data;
|
||||
|
||||
std::vector<Detail::unique_ptr<IStream const>> m_reporterStreams;
|
||||
std::vector<Detail::unique_ptr<IStream>> m_reporterStreams;
|
||||
TestSpec m_testSpec;
|
||||
bool m_hasTestFilters = false;
|
||||
};
|
||||
|
@ -23,7 +23,7 @@ namespace Catch {
|
||||
|
||||
ReporterConfig::ReporterConfig(
|
||||
IConfig const* _fullConfig,
|
||||
IStream const* _stream,
|
||||
IStream* _stream,
|
||||
ColourMode colourMode,
|
||||
std::map<std::string, std::string> customOptions ):
|
||||
m_stream( _stream ),
|
||||
@ -31,7 +31,7 @@ namespace Catch {
|
||||
m_colourMode( colourMode ),
|
||||
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; }
|
||||
ColourMode ReporterConfig::colourMode() const { return m_colourMode; }
|
||||
|
||||
|
@ -36,17 +36,17 @@ namespace Catch {
|
||||
|
||||
struct ReporterConfig {
|
||||
ReporterConfig( IConfig const* _fullConfig,
|
||||
IStream const* _stream,
|
||||
IStream* _stream,
|
||||
ColourMode colourMode,
|
||||
std::map<std::string, std::string> customOptions );
|
||||
|
||||
IStream const* stream() const;
|
||||
IStream* stream() const;
|
||||
IConfig const* fullConfig() const;
|
||||
ColourMode colourMode() const;
|
||||
std::map<std::string, std::string> const& customOptions() const;
|
||||
|
||||
private:
|
||||
IStream const* m_stream;
|
||||
IStream* m_stream;
|
||||
IConfig const* m_fullConfig;
|
||||
ColourMode m_colourMode;
|
||||
std::map<std::string, std::string> m_customOptions;
|
||||
|
@ -84,7 +84,7 @@ namespace Catch {
|
||||
//! platforms, and when the user asks to deactivate all colours.
|
||||
class NoColourImpl : public ColourImpl {
|
||||
public:
|
||||
NoColourImpl( IStream const* stream ): ColourImpl( stream ) {}
|
||||
NoColourImpl( IStream* stream ): ColourImpl( stream ) {}
|
||||
static bool useColourOnPlatform() { return true; }
|
||||
|
||||
private:
|
||||
@ -103,7 +103,7 @@ namespace {
|
||||
|
||||
class Win32ColourImpl : public ColourImpl {
|
||||
public:
|
||||
Win32ColourImpl(IStream const* stream):
|
||||
Win32ColourImpl(IStream* stream):
|
||||
ColourImpl(stream) {
|
||||
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
|
||||
GetConsoleScreenBufferInfo( GetStdHandle( STD_OUTPUT_HANDLE ),
|
||||
@ -169,7 +169,7 @@ namespace {
|
||||
|
||||
class ANSIColourImpl : public ColourImpl {
|
||||
public:
|
||||
ANSIColourImpl( IStream const* stream ): ColourImpl( stream ) {}
|
||||
ANSIColourImpl( IStream* stream ): ColourImpl( stream ) {}
|
||||
|
||||
static bool useColourOnPlatform(IStream const& stream) {
|
||||
// This is kinda messy due to trying to support a bunch of
|
||||
@ -229,7 +229,7 @@ namespace {
|
||||
namespace Catch {
|
||||
|
||||
Detail::unique_ptr<ColourImpl> makeColourImpl( ColourMode implSelection,
|
||||
IStream const* stream ) {
|
||||
IStream* stream ) {
|
||||
if ( implSelection == ColourMode::None ) {
|
||||
return Detail::make_unique<NoColourImpl>( stream );
|
||||
}
|
||||
|
@ -60,9 +60,9 @@ namespace Catch {
|
||||
class ColourImpl {
|
||||
protected:
|
||||
//! The associated stream of this ColourImpl instance
|
||||
IStream const* m_stream;
|
||||
IStream* m_stream;
|
||||
public:
|
||||
ColourImpl( IStream const* stream ): m_stream( stream ) {}
|
||||
ColourImpl( IStream* stream ): m_stream( stream ) {}
|
||||
|
||||
//! RAII wrapper around writing specific colour of text using specific
|
||||
//! colour impl into a stream.
|
||||
@ -131,7 +131,7 @@ namespace Catch {
|
||||
|
||||
//! Provides ColourImpl based on global config and target compilation platform
|
||||
Detail::unique_ptr<ColourImpl> makeColourImpl( ColourMode colourSelection,
|
||||
IStream const* stream );
|
||||
IStream* stream );
|
||||
|
||||
//! Checks if specific colour impl has been compiled into the binary
|
||||
bool isColourImplAvailable( ColourMode colourSelection );
|
||||
|
@ -74,7 +74,7 @@ namespace Detail {
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class FileStream : public IStream {
|
||||
mutable std::ofstream m_ofs;
|
||||
std::ofstream m_ofs;
|
||||
public:
|
||||
FileStream( std::string const& filename ) {
|
||||
m_ofs.open( filename.c_str() );
|
||||
@ -82,7 +82,7 @@ namespace Detail {
|
||||
}
|
||||
~FileStream() override = default;
|
||||
public: // IStream
|
||||
std::ostream& stream() const override {
|
||||
std::ostream& stream() override {
|
||||
return m_ofs;
|
||||
}
|
||||
};
|
||||
@ -90,7 +90,7 @@ namespace Detail {
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class CoutStream : public IStream {
|
||||
mutable std::ostream m_os;
|
||||
std::ostream m_os;
|
||||
public:
|
||||
// Store the streambuf from cout up-front because
|
||||
// cout may get redirected when running tests
|
||||
@ -98,12 +98,12 @@ namespace Detail {
|
||||
~CoutStream() override = default;
|
||||
|
||||
public: // IStream
|
||||
std::ostream& stream() const override { return m_os; }
|
||||
std::ostream& stream() override { return m_os; }
|
||||
bool isConsole() const override { return true; }
|
||||
};
|
||||
|
||||
class CerrStream : public IStream {
|
||||
mutable std::ostream m_os;
|
||||
std::ostream m_os;
|
||||
|
||||
public:
|
||||
// Store the streambuf from cerr up-front because
|
||||
@ -112,7 +112,7 @@ namespace Detail {
|
||||
~CerrStream() override = default;
|
||||
|
||||
public: // IStream
|
||||
std::ostream& stream() const override { return m_os; }
|
||||
std::ostream& stream() override { return m_os; }
|
||||
bool isConsole() const override { return true; }
|
||||
};
|
||||
|
||||
@ -120,7 +120,7 @@ namespace Detail {
|
||||
|
||||
class DebugOutStream : public IStream {
|
||||
Detail::unique_ptr<StreamBufImpl<OutputDebugWriter>> m_streamBuf;
|
||||
mutable std::ostream m_os;
|
||||
std::ostream m_os;
|
||||
public:
|
||||
DebugOutStream()
|
||||
: m_streamBuf( Detail::make_unique<StreamBufImpl<OutputDebugWriter>>() ),
|
||||
@ -130,7 +130,7 @@ namespace Detail {
|
||||
~DebugOutStream() override = default;
|
||||
|
||||
public: // IStream
|
||||
std::ostream& stream() const override { return m_os; }
|
||||
std::ostream& stream() override { return m_os; }
|
||||
};
|
||||
|
||||
} // 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 == "-" ) {
|
||||
return Detail::make_unique<Detail::CoutStream>();
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ namespace Catch {
|
||||
class IStream {
|
||||
public:
|
||||
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)
|
||||
*
|
||||
@ -51,7 +51,7 @@ namespace Catch {
|
||||
*
|
||||
* \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 {
|
||||
std::size_t m_index;
|
||||
|
@ -29,7 +29,7 @@ namespace Catch {
|
||||
class ReporterBase : public IEventListener {
|
||||
protected:
|
||||
//! 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
|
||||
//! number of indirect calls needed to write output.
|
||||
std::ostream& m_stream;
|
||||
|
@ -21,9 +21,9 @@ namespace {
|
||||
};
|
||||
|
||||
class TestStringStream : public Catch::IStream {
|
||||
mutable std::stringstream m_stream;
|
||||
std::stringstream m_stream;
|
||||
public:
|
||||
std::ostream& stream() const override {
|
||||
std::ostream& stream() override {
|
||||
return m_stream;
|
||||
}
|
||||
|
||||
|
@ -29,10 +29,10 @@
|
||||
namespace {
|
||||
class StringIStream : public Catch::IStream {
|
||||
public:
|
||||
std::ostream& stream() const override { return sstr; }
|
||||
std::ostream& stream() override { return sstr; }
|
||||
std::string str() const { return sstr.str(); }
|
||||
private:
|
||||
mutable std::stringstream sstr;
|
||||
std::stringstream sstr;
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user