From 3bad3d6956a4c6451e85629abc53d408e48ba382 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Wed, 9 Feb 2011 09:08:10 +0000 Subject: [PATCH] Refactored self-test - doesn't need so many supporting classes --- Test/TestMain.cpp | 9 +-- internal/catch_self_test.hpp | 135 ++++++++--------------------------- 2 files changed, 35 insertions(+), 109 deletions(-) diff --git a/Test/TestMain.cpp b/Test/TestMain.cpp index 0e84c8f3..3bf7c311 100644 --- a/Test/TestMain.cpp +++ b/Test/TestMain.cpp @@ -21,10 +21,11 @@ TEST_CASE( "selftest/main", "Runs all Catch self tests and checks their results" EmbeddedRunner runner; runner.runMatching( "./succeeding/*" ); - CHECK( runner.getReporter().getSucceeded() == 196 ); - CHECK( runner.getReporter().getFailed() == 0 ); + INFO( runner.getOutput() ); + CHECK( runner.getSuccessCount() == 196 ); + CHECK( runner.getFailureCount() == 0 ); runner.runMatching( "./failing/*" ); - CHECK( runner.getReporter().getSucceeded() == 0 ); - CHECK( runner.getReporter().getFailed() == 53 ); + CHECK( runner.getSuccessCount() == 0 ); + CHECK( runner.getFailureCount() == 53 ); } diff --git a/internal/catch_self_test.hpp b/internal/catch_self_test.hpp index d9b04b00..1aba2785 100644 --- a/internal/catch_self_test.hpp +++ b/internal/catch_self_test.hpp @@ -17,107 +17,7 @@ namespace Catch { - class SelfTestReporter : public IReporter - { - public: - /////////////////////////////////////////////////////////////////////////// - SelfTestReporter - () - : m_succeeded( 0 ), - m_failed( 0 ) - { - } - - /////////////////////////////////////////////////////////////////////////// - static std::string getDescription - () - { - return "Captures results for self test purposes"; - } - - /////////////////////////////////////////////////////////////////////////// - size_t getSucceeded - () - const - { - return m_succeeded; - } - - /////////////////////////////////////////////////////////////////////////// - size_t getFailed - () - const - { - return m_failed; - } - - /////////////////////////////////////////////////////////////////////////// - void reset() - { - m_succeeded = 0; - m_failed = 0; - } - - private: // IReporter - - /////////////////////////////////////////////////////////////////////////// - virtual void StartTesting - () - {} - - /////////////////////////////////////////////////////////////////////////// - virtual void EndTesting - ( - std::size_t succeeded, - std::size_t failed - ) - { - m_succeeded = succeeded; - m_failed = failed; - } - - /////////////////////////////////////////////////////////////////////////// - // Deliberately unimplemented: - virtual void StartGroup( const std::string& ){} - virtual void EndGroup( const std::string&, std::size_t, std::size_t ){} - virtual void StartTestCase( const TestCaseInfo& ){} - virtual void StartSection( const std::string&, const std::string ){} - virtual void EndSection( const std::string&, std::size_t, std::size_t ){} - virtual void Result( const ResultInfo& ){} - virtual void EndTestCase( const TestCaseInfo&, std::size_t, std::size_t, const std::string&, const std::string& ){} - - private: - size_t m_succeeded; - size_t m_failed; - }; - - - class SelfTestConfig : public Config - { - public: - /////////////////////////////////////////////////////////////////////////// - SelfTestConfig - () - : m_reporter( new SelfTestReporter() ) - { - // reporter will be deleted by the base config class - setReporter( m_reporter ); - setStreamBuf( m_oss.rdbuf() ); - } - /////////////////////////////////////////////////////////////////////////// - SelfTestReporter& getReporter - () - { - return *m_reporter; - } - - private: - std::ostringstream m_oss; - SelfTestReporter* m_reporter; - - }; - class EmbeddedRunner { public: @@ -133,22 +33,47 @@ namespace Catch const std::string& rawTestSpec ) { + std::ostringstream oss; + Config config; + config.setStreamBuf( oss.rdbuf() ); + config.setReporter( "basic" ); + std::size_t result; - Runner runner( m_config ); - m_config.getReporter().reset(); + Runner runner( config ); result = runner.runMatching( rawTestSpec ); + m_successes = runner.getSuccessCount(); + m_failures = runner.getFailureCount(); + m_output = oss.str(); return result; } /////////////////////////////////////////////////////////////////////////// - SelfTestReporter& getReporter + std::string getOutput () { - return m_config.getReporter(); + return m_output; } + /////////////////////////////////////////////////////////////////////////// + std::size_t getSuccessCount + () + const + { + return m_successes; + } + + /////////////////////////////////////////////////////////////////////////// + std:: size_t getFailureCount + () + const + { + return m_failures; + } + private: - SelfTestConfig m_config; + std::size_t m_successes; + std::size_t m_failures; + std::string m_output; }; }