Fix output redirection in failing tests (#1525)

Fixes #1514
This commit is contained in:
SimonChh 2019-03-02 15:18:48 -05:00 committed by Martin Hořeňovský
parent 5bf6e47381
commit 7d2451f119
3 changed files with 25 additions and 5 deletions

View File

@ -49,6 +49,15 @@ namespace Catch {
{} {}
auto RedirectedStdErr::str() const -> std::string { return m_rss.str(); } auto RedirectedStdErr::str() const -> std::string { return m_rss.str(); }
RedirectedStreams::RedirectedStreams(std::string& redirectedCout, std::string& redirectedCerr)
: m_redirectedCout(redirectedCout),
m_redirectedCerr(redirectedCerr)
{}
RedirectedStreams::~RedirectedStreams() {
m_redirectedCout += m_redirectedStdOut.str();
m_redirectedCerr += m_redirectedStdErr.str();
}
#if defined(CATCH_CONFIG_NEW_CAPTURE) #if defined(CATCH_CONFIG_NEW_CAPTURE)

View File

@ -46,6 +46,21 @@ namespace Catch {
auto str() const -> std::string; auto str() const -> std::string;
}; };
class RedirectedStreams {
public:
RedirectedStreams(RedirectedStreams const&) = delete;
RedirectedStreams& operator=(RedirectedStreams const&) = delete;
RedirectedStreams(RedirectedStreams&&) = delete;
RedirectedStreams& operator=(RedirectedStreams&&) = delete;
RedirectedStreams(std::string& redirectedCout, std::string& redirectedCerr);
~RedirectedStreams();
private:
std::string& m_redirectedCout;
std::string& m_redirectedCerr;
RedirectedStdOut m_redirectedStdOut;
RedirectedStdErr m_redirectedStdErr;
};
#if defined(CATCH_CONFIG_NEW_CAPTURE) #if defined(CATCH_CONFIG_NEW_CAPTURE)

View File

@ -67,7 +67,6 @@ namespace Catch {
GeneratorTracker::~GeneratorTracker() {} GeneratorTracker::~GeneratorTracker() {}
} }
RunContext::RunContext(IConfigPtr const& _config, IStreamingReporterPtr&& reporter) RunContext::RunContext(IConfigPtr const& _config, IStreamingReporterPtr&& reporter)
: m_runInfo(_config->name()), : m_runInfo(_config->name()),
m_context(getCurrentMutableContext()), m_context(getCurrentMutableContext()),
@ -323,13 +322,10 @@ namespace Catch {
CATCH_TRY { CATCH_TRY {
if (m_reporter->getPreferences().shouldRedirectStdOut) { if (m_reporter->getPreferences().shouldRedirectStdOut) {
#if !defined(CATCH_CONFIG_EXPERIMENTAL_REDIRECT) #if !defined(CATCH_CONFIG_EXPERIMENTAL_REDIRECT)
RedirectedStdOut redirectedStdOut; RedirectedStreams redirectedStreams(redirectedCout, redirectedCerr);
RedirectedStdErr redirectedStdErr;
timer.start(); timer.start();
invokeActiveTestCase(); invokeActiveTestCase();
redirectedCout += redirectedStdOut.str();
redirectedCerr += redirectedStdErr.str();
#else #else
OutputRedirect r(redirectedCout, redirectedCerr); OutputRedirect r(redirectedCout, redirectedCerr);
timer.start(); timer.start();