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

summaryrefslogtreecommitdiffhomepage
path: root/include/internal
diff options
context:
space:
mode:
authorMartin Hořeňovský2017-08-10 11:34:26 +0200
committerMartin Hořeňovský2017-08-10 11:34:26 +0200
commitaa42dd92d104e894e2b54d29a3defdf4b00eec21 (patch)
tree4bdf430c746a2c98e6092705760d3f78c5421436 /include/internal
parente658bacb04ef5c14c1dcb192c9e5c99cef390582 (diff)
parent7e4038d8488596e850a11c8fe236b59bca605444 (diff)
downloadcatch3-aa42dd92d104e894e2b54d29a3defdf4b00eec21.tar.gz
Merge branch 'master' into dev-modernize
Diffstat (limited to 'include/internal')
-rw-r--r--include/internal/catch_run_context.cpp16
-rw-r--r--include/internal/catch_run_context.hpp14
-rw-r--r--include/internal/catch_stream.h1
-rw-r--r--include/internal/catch_stream.hpp3
-rw-r--r--include/internal/catch_test_registry.hpp8
5 files changed, 36 insertions, 6 deletions
diff --git a/include/internal/catch_run_context.cpp b/include/internal/catch_run_context.cpp
index b54742ff..d25b958a 100644
--- a/include/internal/catch_run_context.cpp
+++ b/include/internal/catch_run_context.cpp
@@ -18,6 +18,19 @@ namespace Catch {
m_stream.rdbuf(m_prevBuf);
}
+ StdErrRedirect::StdErrRedirect(std::string & targetString)
+ :m_cerrBuf(cerr().rdbuf()), m_clogBuf(clog().rdbuf()),
+ m_targetString(targetString) {
+ cerr().rdbuf(m_oss.rdbuf());
+ clog().rdbuf(m_oss.rdbuf());
+ }
+
+ StdErrRedirect::~StdErrRedirect() {
+ m_targetString += m_oss.str();
+ cerr().rdbuf(m_cerrBuf);
+ clog().rdbuf(m_clogBuf);
+ }
+
RunContext::RunContext(IConfigPtr const& _config, IStreamingReporterPtr&& reporter)
: m_runInfo(_config->name()),
m_context(getCurrentMutableContext()),
@@ -256,7 +269,7 @@ namespace Catch {
timer.start();
if (m_reporter->getPreferences().shouldRedirectStdOut) {
StreamRedirect coutRedir(cout(), redirectedCout);
- StreamRedirect cerrRedir(cerr(), redirectedCerr);
+ StdErrRedirect errRedir(redirectedCerr);
invokeActiveTestCase();
} else {
invokeActiveTestCase();
@@ -318,5 +331,4 @@ namespace Catch {
else
CATCH_INTERNAL_ERROR("No result capture instance");
}
-
} \ No newline at end of file
diff --git a/include/internal/catch_run_context.hpp b/include/internal/catch_run_context.hpp
index ee923e88..de24ec95 100644
--- a/include/internal/catch_run_context.hpp
+++ b/include/internal/catch_run_context.hpp
@@ -40,6 +40,20 @@ namespace Catch {
std::string& m_targetString;
};
+ // StdErr has two constituent streams in C++, std::cerr and std::clog
+ // This means that we need to redirect 2 streams into 1 to keep proper
+ // order of writes and cannot use StreamRedirect on its own
+ class StdErrRedirect {
+ public:
+ StdErrRedirect(std::string& targetString);
+ ~StdErrRedirect();
+ private:
+ std::streambuf* m_cerrBuf;
+ std::streambuf* m_clogBuf;
+ std::ostringstream m_oss;
+ std::string& m_targetString;
+ };
+
///////////////////////////////////////////////////////////////////////////
class RunContext : public IResultCapture, public IRunner {
diff --git a/include/internal/catch_stream.h b/include/internal/catch_stream.h
index 8f2fb5a6..488e8b20 100644
--- a/include/internal/catch_stream.h
+++ b/include/internal/catch_stream.h
@@ -20,6 +20,7 @@ namespace Catch {
std::ostream& cout();
std::ostream& cerr();
+ std::ostream& clog();
struct IStream {
diff --git a/include/internal/catch_stream.hpp b/include/internal/catch_stream.hpp
index 3b7bbe60..dbcda110 100644
--- a/include/internal/catch_stream.hpp
+++ b/include/internal/catch_stream.hpp
@@ -101,6 +101,9 @@ namespace Catch {
std::ostream& cerr() {
return std::cerr;
}
+ std::ostream& clog() {
+ return std::clog;
+ }
#endif
}
diff --git a/include/internal/catch_test_registry.hpp b/include/internal/catch_test_registry.hpp
index 1cd5fa40..07334c34 100644
--- a/include/internal/catch_test_registry.hpp
+++ b/include/internal/catch_test_registry.hpp
@@ -51,7 +51,7 @@ struct AutoReg : NonCopyable {
#define INTERNAL_CATCH_TESTCASE2( TestName, ... ) \
static void TestName(); \
CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS \
- namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( Catch::makeTestInvoker( &TestName ), CATCH_INTERNAL_LINEINFO, "", Catch::NameAndTags{ __VA_ARGS__ } ); } \
+ namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( Catch::makeTestInvoker( &TestName ), CATCH_INTERNAL_LINEINFO, "", Catch::NameAndTags{ __VA_ARGS__ } ); } /* NOLINT */ \
CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS \
static void TestName()
#define INTERNAL_CATCH_TESTCASE( ... ) \
@@ -60,7 +60,7 @@ struct AutoReg : NonCopyable {
///////////////////////////////////////////////////////////////////////////////
#define INTERNAL_CATCH_METHOD_AS_TEST_CASE( QualifiedMethod, ... ) \
CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS \
- namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( Catch::makeTestInvoker( &QualifiedMethod ), CATCH_INTERNAL_LINEINFO, "&" #QualifiedMethod, Catch::NameAndTags{ __VA_ARGS__ } ); } \
+ namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( Catch::makeTestInvoker( &QualifiedMethod ), CATCH_INTERNAL_LINEINFO, "&" #QualifiedMethod, Catch::NameAndTags{ __VA_ARGS__ } ); } /* NOLINT */ \
CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS
///////////////////////////////////////////////////////////////////////////////
@@ -70,7 +70,7 @@ struct AutoReg : NonCopyable {
struct TestName : ClassName{ \
void test(); \
}; \
- Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar ) ( Catch::makeTestInvoker( &TestName::test ), CATCH_INTERNAL_LINEINFO, #ClassName, Catch::NameAndTags{ __VA_ARGS__ } ); \
+ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar ) ( Catch::makeTestInvoker( &TestName::test ), CATCH_INTERNAL_LINEINFO, #ClassName, Catch::NameAndTags{ __VA_ARGS__ } ); /* NOLINT */ \
} \
CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS \
void TestName::test()
@@ -80,7 +80,7 @@ struct AutoReg : NonCopyable {
///////////////////////////////////////////////////////////////////////////////
#define INTERNAL_CATCH_REGISTER_TESTCASE( Function, ... ) \
CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS \
- Catch::AutoReg( Catch::makeTestInvoker( Function ), CATCH_INTERNAL_LINEINFO, "", Catch::NameAndTags{ __VA_ARGS__ } ); \
+ Catch::AutoReg( Catch::makeTestInvoker( Function ), CATCH_INTERNAL_LINEINFO, "", Catch::NameAndTags{ __VA_ARGS__ } ); /* NOLINT */ \
CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS