From a57b025c9c07df56a749d340a19db4d70a5ac9bb Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Fri, 17 Feb 2012 09:28:21 +0000 Subject: [PATCH] Don't redirect stout for basic reporter --- include/catch_runner.hpp | 1 + include/internal/catch_interfaces_reporter.h | 3 +++ include/internal/catch_runner_impl.hpp | 13 ++++++++++--- include/reporters/catch_reporter_basic.hpp | 8 ++++++++ include/reporters/catch_reporter_junit.hpp | 8 ++++++++ include/reporters/catch_reporter_xml.hpp | 8 ++++++++ 6 files changed, 38 insertions(+), 3 deletions(-) diff --git a/include/catch_runner.hpp b/include/catch_runner.hpp index c4ccb519..76e5e9f0 100644 --- a/include/catch_runner.hpp +++ b/include/catch_runner.hpp @@ -78,6 +78,7 @@ namespace Catch config.getReporter()->EndGroup( *it, runner.getSuccessCount()-prevSuccess, runner.getFailureCount()-prevFail ); } } + return static_cast( runner.getFailureCount() ); } diff --git a/include/internal/catch_interfaces_reporter.h b/include/internal/catch_interfaces_reporter.h index 0861e127..57ded854 100644 --- a/include/internal/catch_interfaces_reporter.h +++ b/include/internal/catch_interfaces_reporter.h @@ -47,6 +47,9 @@ namespace Catch virtual ~IReporter (){} + virtual bool shouldRedirectStdout + () const = 0; + virtual void StartTesting () = 0; diff --git a/include/internal/catch_runner_impl.hpp b/include/internal/catch_runner_impl.hpp index 00bd0a4f..d72a844f 100644 --- a/include/internal/catch_runner_impl.hpp +++ b/include/internal/catch_runner_impl.hpp @@ -585,9 +585,16 @@ namespace Catch try { m_runningTest->reset(); - StreamRedirect coutRedir( std::cout, redirectedCout ); - StreamRedirect cerrRedir( std::cerr, redirectedCerr ); - m_runningTest->getTestCaseInfo().invoke(); + if( m_reporter->shouldRedirectStdout() ) + { + StreamRedirect coutRedir( std::cout, redirectedCout ); + StreamRedirect cerrRedir( std::cerr, redirectedCerr ); + m_runningTest->getTestCaseInfo().invoke(); + } + else + { + m_runningTest->getTestCaseInfo().invoke(); + } m_runningTest->ranToCompletion(); } catch( TestFailureException& ) diff --git a/include/reporters/catch_reporter_basic.hpp b/include/reporters/catch_reporter_basic.hpp index c55f4f01..25b6be8e 100644 --- a/include/reporters/catch_reporter_basic.hpp +++ b/include/reporters/catch_reporter_basic.hpp @@ -79,6 +79,14 @@ namespace Catch private: // IReporter + /////////////////////////////////////////////////////////////////////////// + virtual bool shouldRedirectStdout + () + const + { + return false; + } + /////////////////////////////////////////////////////////////////////////// virtual void StartTesting () diff --git a/include/reporters/catch_reporter_junit.hpp b/include/reporters/catch_reporter_junit.hpp index 8be63a94..c317ef92 100644 --- a/include/reporters/catch_reporter_junit.hpp +++ b/include/reporters/catch_reporter_junit.hpp @@ -82,6 +82,14 @@ namespace Catch private: // IReporter + /////////////////////////////////////////////////////////////////////////// + virtual bool shouldRedirectStdout + () + const + { + return true; + } + /////////////////////////////////////////////////////////////////////////// virtual void StartTesting() { diff --git a/include/reporters/catch_reporter_xml.hpp b/include/reporters/catch_reporter_xml.hpp index 792ab929..a57b7fe3 100644 --- a/include/reporters/catch_reporter_xml.hpp +++ b/include/reporters/catch_reporter_xml.hpp @@ -40,6 +40,14 @@ namespace Catch private: // IReporter + /////////////////////////////////////////////////////////////////////////// + virtual bool shouldRedirectStdout + () + const + { + return true; + } + /////////////////////////////////////////////////////////////////////////// virtual void StartTesting ()