From ce319b79e5e7c3351d01707807fa4d9c67ab7e16 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Tue, 30 Nov 2010 06:48:21 +0000 Subject: [PATCH] stdout/ stderr capturing --- Test/MiscTests.cpp | 10 +++++++-- catch_reporter_basic.hpp | 8 ++++++- catch_reporter_xml.hpp | 2 +- internal/catch_common.h | 3 ++- internal/catch_reporter_registry.hpp | 2 +- internal/catch_runner_impl.hpp | 33 ++++++++++++++++++++++++++-- 6 files changed, 50 insertions(+), 8 deletions(-) diff --git a/Test/MiscTests.cpp b/Test/MiscTests.cpp index ea004cc8..5ec21d31 100644 --- a/Test/MiscTests.cpp +++ b/Test/MiscTests.cpp @@ -22,10 +22,16 @@ TEST_CASE( "succeeding/Misc/Sections", "random SECTION tests" ) EXPECT( a != b ); EXPECT( b != a ); } - + SECTION( "s2", "not equal" ) { EXPECT_NOT( a == b); } - } + +TEST_CASE( "succeeding/Misc/stdout,stderr", "Sends stuff to stdout and stderr" ) +{ + std::cout << "Some information"; + + std::cerr << "An error"; +} \ No newline at end of file diff --git a/catch_reporter_basic.hpp b/catch_reporter_basic.hpp index 3026f70a..4a656fb0 100644 --- a/catch_reporter_basic.hpp +++ b/catch_reporter_basic.hpp @@ -153,8 +153,14 @@ namespace Catch } /////////////////////////////////////////////////////////////////////////// - virtual void EndTestCase( const TestCaseInfo& testInfo ) + virtual void EndTestCase( const TestCaseInfo& testInfo, const std::string& stdOut, const std::string& stdErr ) { + if( !stdOut.empty() ) + m_config.stream() << "[stdout: " << stdOut << "]\n"; + + if( !stdErr.empty() ) + m_config.stream() << "[stderr: " << stdErr << "]\n"; + m_config.stream() << "[Finished: " << testInfo.getName() << "]" << std::endl; } diff --git a/catch_reporter_xml.hpp b/catch_reporter_xml.hpp index c9953da2..f5e1cd18 100644 --- a/catch_reporter_xml.hpp +++ b/catch_reporter_xml.hpp @@ -91,7 +91,7 @@ namespace Catch } /////////////////////////////////////////////////////////////////////////// - virtual void EndTestCase( const Catch::TestCaseInfo& ) + virtual void EndTestCase( const Catch::TestCaseInfo&, const std::string& stdOut, const std::string& stdErr ) { m_config.stream() << "\t