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

summaryrefslogtreecommitdiffhomepage
path: root/src/catch2
diff options
context:
space:
mode:
authorMartin Hořeňovský2022-03-07 10:42:26 +0100
committerMartin Hořeňovský2022-03-07 10:59:27 +0100
commit06f74a0f8e505a08fff58e63beeb88569d8629d6 (patch)
tree0dd30937f0282013a89b0684096c8a7c4803b091 /src/catch2
parent61d0f7a9afb88c12f8931f80321e58f2cfbc62db (diff)
downloadcatch3-06f74a0f8e505a08fff58e63beeb88569d8629d6.tar.gz
Add %stderr and %stdout as recognized magic stream names
Diffstat (limited to 'src/catch2')
-rw-r--r--src/catch2/internal/catch_stream.cpp28
1 files changed, 23 insertions, 5 deletions
diff --git a/src/catch2/internal/catch_stream.cpp b/src/catch2/internal/catch_stream.cpp
index 5ce6e255..a5aecf8e 100644
--- a/src/catch2/internal/catch_stream.cpp
+++ b/src/catch2/internal/catch_stream.cpp
@@ -102,6 +102,20 @@ namespace Detail {
bool isStdout() const override { return true; }
};
+ class CerrStream : public IStream {
+ mutable 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() const override { return m_os; }
+ bool isStdout() const override { return true; }
+ };
+
///////////////////////////////////////////////////////////////////////////
class DebugOutStream : public IStream {
@@ -128,14 +142,18 @@ namespace Detail {
if ( filename.empty() || filename == "-" ) {
return Detail::make_unique<Detail::CoutStream>();
}
- else if( filename[0] == '%' ) {
- if( filename == "%debug" )
+ if( filename[0] == '%' ) {
+ if ( filename == "%debug" ) {
return Detail::make_unique<Detail::DebugOutStream>();
- else
+ } else if ( filename == "%stderr" ) {
+ return Detail::make_unique<Detail::CerrStream>();
+ } else if ( filename == "%stdout" ) {
+ return Detail::make_unique<Detail::CoutStream>();
+ } else {
CATCH_ERROR( "Unrecognised stream: '" << filename << '\'' );
+ }
}
- else
- return Detail::make_unique<Detail::FileStream>( filename );
+ return Detail::make_unique<Detail::FileStream>( filename );
}