diff --git a/Test/Test.xcodeproj/project.pbxproj b/Test/Test.xcodeproj/project.pbxproj index 7ef73d2b..3bc72b5e 100644 --- a/Test/Test.xcodeproj/project.pbxproj +++ b/Test/Test.xcodeproj/project.pbxproj @@ -44,6 +44,9 @@ 4AA7EA9112A438C7005A0B97 /* MiscTests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MiscTests.cpp; sourceTree = ""; }; 4AD6775912D71DA0005AAF59 /* catch_test_case_registry_impl.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_test_case_registry_impl.hpp; path = ../internal/catch_test_case_registry_impl.hpp; sourceTree = SOURCE_ROOT; }; 4AD677B212D7A53E005AAF59 /* catch_interfaces_testcase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = catch_interfaces_testcase.h; path = ../internal/catch_interfaces_testcase.h; sourceTree = SOURCE_ROOT; }; + 4AD6781D12D7A88E005AAF59 /* catch_interfaces_capture.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = catch_interfaces_capture.h; path = ../internal/catch_interfaces_capture.h; sourceTree = SOURCE_ROOT; }; + 4AD6781F12D7A952005AAF59 /* catch_result_type.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = catch_result_type.h; path = ../internal/catch_result_type.h; sourceTree = SOURCE_ROOT; }; + 4AD6783212D7ABB3005AAF59 /* catch_interfaces_runner.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = catch_interfaces_runner.h; path = ../internal/catch_interfaces_runner.h; sourceTree = SOURCE_ROOT; }; 4AFC341512809A36003A0C29 /* catch_capture.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_capture.hpp; path = ../internal/catch_capture.hpp; sourceTree = SOURCE_ROOT; }; 4AFC341612809A36003A0C29 /* catch_common.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = catch_common.h; path = ../internal/catch_common.h; sourceTree = SOURCE_ROOT; }; 4AFC341712809A36003A0C29 /* catch_test_registry.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_test_registry.hpp; path = ../internal/catch_test_registry.hpp; sourceTree = SOURCE_ROOT; }; @@ -114,6 +117,8 @@ 4AFC341712809A36003A0C29 /* catch_test_registry.hpp */, 4AFC341B12809A36003A0C29 /* catch_test_case_info.hpp */, 4AD677B212D7A53E005AAF59 /* catch_interfaces_testcase.h */, + 4AD6781D12D7A88E005AAF59 /* catch_interfaces_capture.h */, + 4AD6781F12D7A952005AAF59 /* catch_result_type.h */, ); name = "TestCase registration"; sourceTree = ""; @@ -124,6 +129,7 @@ 4A3BFFF0128DD23C005609E3 /* catch_config.hpp */, 4AFC341912809A36003A0C29 /* catch_resultinfo.hpp */, 4AFC341A12809A36003A0C29 /* catch_runner_impl.hpp */, + 4AD6783212D7ABB3005AAF59 /* catch_interfaces_runner.h */, ); name = "Running & Results"; sourceTree = ""; diff --git a/internal/catch_capture.hpp b/internal/catch_capture.hpp index e5d77598..8238788a 100644 --- a/internal/catch_capture.hpp +++ b/internal/catch_capture.hpp @@ -13,6 +13,8 @@ #define TWOBLUECUBES_CATCH_CAPTURE_HPP_INCLUDED #include "catch_resultinfo.hpp" +#include "catch_result_type.h" +#include "catch_interfaces_capture.h" #include "catch_debugger.hpp" #include #include @@ -190,79 +192,17 @@ private: }; -struct ResultAction -{ - enum Value - { - None, - Failed = 1, // Failure - but no debug break if Debug bit not set - DebugFailed = 3 // Indicates that the debugger should break, if possible - }; -}; - -class TestCaseInfo; -class ScopedInfo; - -struct IResultListener -{ - virtual ~IResultListener(){} - virtual void testEnded( const ResultInfo& result ) = 0; - virtual bool sectionStarted( const std::string& name, const std::string& description, std::size_t& successes, std::size_t& failures ) = 0; - virtual void sectionEnded( const std::string& name, std::size_t successes, std::size_t failures ) = 0; - virtual void pushScopedInfo( ScopedInfo* scopedInfo ) = 0; - virtual void popScopedInfo( ScopedInfo* scopedInfo ) = 0; - virtual bool shouldDebugBreak() const = 0; - - virtual ResultAction::Value acceptResult( bool result ) = 0; - virtual ResultAction::Value acceptResult( ResultWas::OfType result ) = 0; - virtual void acceptExpression( const MutableResultInfo& resultInfo ) = 0; - virtual void acceptMessage( const std::string& msg ) = 0; - -}; - -class ResultsCapture -{ -private: - ResultsCapture() - : m_listener( 0 ) - { - } - - static ResultsCapture& instance() - { - static ResultsCapture instance; - return instance; - } - -public: - - static IResultListener* setListener( IResultListener* listener ) - { - IResultListener* prevListener = instance().m_listener; - instance().m_listener = listener; - return prevListener; - } - static IResultListener& getListener() - { - return *instance().m_listener; - } - -private: - IResultListener* m_listener; - -}; - class ScopedInfo { public: ScopedInfo() { - ResultsCapture::getListener().pushScopedInfo( this ); + Hub::getResultCapture().pushScopedInfo( this ); } ~ScopedInfo() { - ResultsCapture::getListener().popScopedInfo( this ); + Hub::getResultCapture().popScopedInfo( this ); } ScopedInfo& operator << ( const char* str ) @@ -333,7 +273,7 @@ inline bool isTrue( bool value ) } // end namespace Catch #define INTERNAL_CATCH_ACCEPT_RESULT( result, stopOnFailure ) \ - if( Catch::ResultAction::Value action = Catch::ResultsCapture::getListener().acceptResult( result ) ) \ + if( Catch::ResultAction::Value action = Catch::Hub::getResultCapture().acceptResult( result ) ) \ { \ if( action == Catch::ResultAction::DebugFailed ) DebugBreak(); \ if( Catch::isTrue( stopOnFailure ) ) throw Catch::TestFailureException(); \ @@ -341,12 +281,12 @@ inline bool isTrue( bool value ) #define INTERNAL_CATCH_TEST( expr, isNot, stopOnFailure, macroName ) \ { \ - Catch::ResultsCapture::getListener().acceptExpression( Catch::ResultBuilder( #expr, isNot, __FILE__, __LINE__, macroName )->*expr ); \ + Catch::Hub::getResultCapture().acceptExpression( Catch::ResultBuilder( #expr, isNot, __FILE__, __LINE__, macroName )->*expr ); \ INTERNAL_CATCH_ACCEPT_RESULT( expr, stopOnFailure ) \ } #define INTERNAL_CATCH_THROWS( expr, exceptionType, nothrow, stopOnFailure, macroName ) \ - Catch::ResultsCapture::getListener().acceptExpression( Catch::ResultBuilder( #expr, false, __FILE__, __LINE__, macroName ) ); \ + Catch::Hub::getResultCapture().acceptExpression( Catch::ResultBuilder( #expr, false, __FILE__, __LINE__, macroName ) ); \ try \ { \ expr; \ @@ -368,8 +308,8 @@ catch( ... ) \ { \ std::ostringstream INTERNAL_CATCH_UNIQUE_NAME( strm ); \ INTERNAL_CATCH_UNIQUE_NAME( strm ) << reason; \ - Catch::ResultsCapture::getListener().acceptExpression( Catch::MutableResultInfo( "", false, __FILE__, __LINE__, macroName ) ); \ - Catch::ResultsCapture::getListener().acceptMessage( INTERNAL_CATCH_UNIQUE_NAME( strm ).str() ); \ + Catch::Hub::getResultCapture().acceptExpression( Catch::MutableResultInfo( "", false, __FILE__, __LINE__, macroName ) ); \ + Catch::Hub::getResultCapture().acceptMessage( INTERNAL_CATCH_UNIQUE_NAME( strm ).str() ); \ INTERNAL_CATCH_ACCEPT_RESULT( resultType, stopOnFailure ) \ } diff --git a/internal/catch_hub.h b/internal/catch_hub.h index 9d7696cc..71212c8e 100644 --- a/internal/catch_hub.h +++ b/internal/catch_hub.h @@ -1,6 +1,6 @@ /* * catch_hub.h - * Test + * Catch * * Created by Phil on 31/12/2010. * Copyright 2010 Two Blue Cubes Ltd. All rights reserved. @@ -20,18 +20,9 @@ namespace Catch { struct TestCaseInfo; - struct IResultListener; - struct ITestCaseRegistry - { - public: - - virtual void registerTest - ( const TestCaseInfo& testInfo - ) = 0; - - virtual const std::vector& getAllTests - () const = 0; - }; + struct IResultCapture; + struct ITestCaseRegistry; + struct IRunner; class Hub { @@ -40,13 +31,19 @@ namespace Catch public: - static IResultListener& getListener(); + static void setRunner( IRunner* runner ); + static void setResultCapture( IResultCapture* resultCapture ); + + static IResultCapture& getResultCapture(); static IReporterRegistry& getReporterRegistry(); static ITestCaseRegistry& getTestCaseRegistry(); + static IRunner& getRunner(); private: std::auto_ptr m_reporterRegistry; std::auto_ptr m_testCaseRegistry; + IRunner* m_runner; + IResultCapture* m_resultCapture; }; } diff --git a/internal/catch_hub_impl.hpp b/internal/catch_hub_impl.hpp index 3888a14c..8d0f81fd 100644 --- a/internal/catch_hub_impl.hpp +++ b/internal/catch_hub_impl.hpp @@ -1,6 +1,6 @@ /* * catch_hub_impl.hpp - * Test + * Catch * * Created by Phil on 31/12/2010. * Copyright 2010 Two Blue Cubes Ltd. All rights reserved. @@ -12,6 +12,7 @@ #include "catch_hub.h" #include "catch_reporter_registry.hpp" #include "catch_test_case_registry_impl.hpp" +#include "catch_runner_impl.hpp" namespace Catch { @@ -22,7 +23,7 @@ namespace Catch m_testCaseRegistry( new TestRegistry ) { } - + /////////////////////////////////////////////////////////////////////////// Hub& Hub::me () @@ -31,6 +32,31 @@ namespace Catch return hub; } + /////////////////////////////////////////////////////////////////////////// + void Hub::setRunner( IRunner* runner ) + { + me().m_runner = runner; + } + /////////////////////////////////////////////////////////////////////////// + void Hub::setResultCapture( IResultCapture* resultCapture ) + { + me().m_resultCapture = resultCapture; + } + + /////////////////////////////////////////////////////////////////////////// + IResultCapture& Hub::getResultCapture + () + { + return *me().m_resultCapture; + } + + /////////////////////////////////////////////////////////////////////////// + IRunner& Hub::getRunner + () + { + return *me().m_runner; + } + /////////////////////////////////////////////////////////////////////////// IReporterRegistry& Hub::getReporterRegistry () diff --git a/internal/catch_interfaces_capture.h b/internal/catch_interfaces_capture.h new file mode 100644 index 00000000..31f92ba8 --- /dev/null +++ b/internal/catch_interfaces_capture.h @@ -0,0 +1,41 @@ +/* + * catch_interfaces_capture.h + * Catch + * + * Created by Phil on 07/01/2011. + * Copyright 2011 Two Blue Cubes Ltd. All rights reserved. + * + * Distributed under the Boost Software License, Version 1.0. (See accompanying + * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + * + */ +#ifndef TWOBLUECUBES_CATCH_INTERFACES_CAPTURE_H_INCLUDED +#define TWOBLUECUBES_CATCH_INTERFACES_CAPTURE_H_INCLUDED + +#include +#include "catch_result_type.h" + +namespace Catch +{ + class TestCaseInfo; + class ScopedInfo; + class MutableResultInfo; + + struct IResultCapture + { + virtual ~IResultCapture(){} + virtual void testEnded( const ResultInfo& result ) = 0; + virtual bool sectionStarted( const std::string& name, const std::string& description, std::size_t& successes, std::size_t& failures ) = 0; + virtual void sectionEnded( const std::string& name, std::size_t successes, std::size_t failures ) = 0; + virtual void pushScopedInfo( ScopedInfo* scopedInfo ) = 0; + virtual void popScopedInfo( ScopedInfo* scopedInfo ) = 0; + virtual bool shouldDebugBreak() const = 0; + + virtual ResultAction::Value acceptResult( bool result ) = 0; + virtual ResultAction::Value acceptResult( ResultWas::OfType result ) = 0; + virtual void acceptExpression( const MutableResultInfo& resultInfo ) = 0; + virtual void acceptMessage( const std::string& msg ) = 0; + }; +} + +#endif // TWOBLUECUBES_CATCH_INTERFACES_CAPTURE_H_INCLUDED diff --git a/internal/catch_interfaces_runner.h b/internal/catch_interfaces_runner.h new file mode 100644 index 00000000..1037f51a --- /dev/null +++ b/internal/catch_interfaces_runner.h @@ -0,0 +1,29 @@ +/* + * catch_interfaces_runner.h + * Catch + * + * Created by Phil on 07/01/2011. + * Copyright 2011 Two Blue Cubes Ltd. All rights reserved. + * + * Distributed under the Boost Software License, Version 1.0. (See accompanying + * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + * + */ +#ifndef TWOBLUECUBES_INTERNAL_CATCH_INTERFACES_RUNNER_H_INCLUDED +#define TWOBLUECUBES_INTERNAL_CATCH_INTERFACES_RUNNER_H_INCLUDED + +#include + +namespace Catch +{ + struct IRunner + { + virtual void runAll() = 0; + virtual std::size_t runMatching( const std::string& rawTestSpec ) = 0; + virtual std::size_t getSuccessCount() const = 0; + virtual std:: size_t getFailureCount() const = 0; + + }; +} + +#endif // TWOBLUECUBES_INTERNAL_CATCH_INTERFACES_RUNNER_H_INCLUDED diff --git a/internal/catch_interfaces_testcase.h b/internal/catch_interfaces_testcase.h index 5c64dcf6..368274d1 100644 --- a/internal/catch_interfaces_testcase.h +++ b/internal/catch_interfaces_testcase.h @@ -1,6 +1,6 @@ /* * catch_interfaces_testcase.h - * Test + * Catch * * Created by Phil on 07/01/2011. * Copyright 2011 Two Blue Cubes Ltd. All rights reserved. @@ -13,6 +13,8 @@ #ifndef TWOBLUECUBES_CATCH_INTERFACES_TESTCASE_H_INCLUDED #define TWOBLUECUBES_CATCH_INTERFACES_TESTCASE_H_INCLUDED +#include + namespace Catch { struct ITestCase @@ -35,6 +37,16 @@ namespace Catch ( const ITestCase& other ) const = 0; }; + + class TestCaseInfo; + struct ITestCaseRegistry + { + virtual void registerTest( const TestCaseInfo& testInfo ) = 0; + virtual const std::vector& getAllTests() const = 0; + }; } + + + #endif // TWOBLUECUBES_CATCH_INTERFACES_TESTCASE_H_INCLUDED \ No newline at end of file diff --git a/internal/catch_result_type.h b/internal/catch_result_type.h new file mode 100644 index 00000000..4df93880 --- /dev/null +++ b/internal/catch_result_type.h @@ -0,0 +1,51 @@ +/* + * catch_result_type.h + * Catch + * + * Created by Phil on 07/01/2011. + * Copyright 2011 Two Blue Cubes Ltd. All rights reserved. + * + * Distributed under the Boost Software License, Version 1.0. (See accompanying + * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + * + */ + +#ifndef TWOBLUECUBES_CATCH_RESULT_TYPE_H_INCLUDED +#define TWOBLUECUBES_CATCH_RESULT_TYPE_H_INCLUDED + +namespace Catch +{ + +struct ResultWas{ enum OfType + { + Unknown = -1, + Ok = 0, + Info = 1, + Warning = 2, + + FailureBit = 0x10, + + ExpressionFailed = FailureBit | 1, + ExplicitFailure = FailureBit | 2, + + Exception = 0x110, + + ThrewException = Exception | 1, + DidntThrowException = Exception | 2 + + }; }; + + struct ResultAction + { + enum Value + { + None, + Failed = 1, // Failure - but no debug break if Debug bit not set + DebugFailed = 3 // Indicates that the debugger should break, if possible + }; + }; + +} + + +#endif // TWOBLUECUBES_CATCH_RESULT_TYPE_H_INCLUDED diff --git a/internal/catch_resultinfo.hpp b/internal/catch_resultinfo.hpp index 75c54421..c58c6d2b 100644 --- a/internal/catch_resultinfo.hpp +++ b/internal/catch_resultinfo.hpp @@ -13,28 +13,10 @@ #define TWOBLUECUBES_CATCH_RESULT_INFO_HPP_INCLUDED #include +#include "catch_result_type.h" namespace Catch { - struct ResultWas{ enum OfType - { - Unknown = -1, - Ok = 0, - Info = 1, - Warning = 2, - - FailureBit = 0x10, - - ExpressionFailed = FailureBit | 1, - ExplicitFailure = FailureBit | 2, - - Exception = 0x110, - - ThrewException = Exception | 1, - DidntThrowException = Exception | 2 - - }; }; - class ResultInfo { public: diff --git a/internal/catch_runner_impl.hpp b/internal/catch_runner_impl.hpp index f973aecd..8230cbc6 100644 --- a/internal/catch_runner_impl.hpp +++ b/internal/catch_runner_impl.hpp @@ -12,6 +12,7 @@ #ifndef TWOBLUECUBES_INTERNAL_CATCH_RUNNER_HPP_INCLUDED #define TWOBLUECUBES_INTERNAL_CATCH_RUNNER_HPP_INCLUDED +#include "catch_interfaces_runner.h" #include "catch_interfaces_reporter.h" #include "catch_config.hpp" #include "catch_test_registry.hpp" @@ -70,7 +71,7 @@ namespace Catch std::string& m_targetString; }; - class Runner : public IResultListener + class Runner : public IResultCapture, public IRunner { Runner( const Runner& ); void operator =( const Runner& ); @@ -82,15 +83,19 @@ namespace Catch m_failures( 0 ), m_reporter( m_config.getReporter() ) { + Hub::setRunner( this ); + Hub::setResultCapture( this ); m_reporter->StartTesting(); } ~Runner() { m_reporter->EndTesting( m_successes, m_failures ); + Hub::setRunner( NULL ); + Hub::setResultCapture( NULL ); } - void runAll() + virtual void runAll() { std::vector allTests = Hub::getTestCaseRegistry().getAllTests(); for( std::size_t i=0; i < allTests.size(); ++i ) @@ -99,7 +104,7 @@ namespace Catch } } - std::size_t runMatching( const std::string& rawTestSpec ) + virtual std::size_t runMatching( const std::string& rawTestSpec ) { TestSpec testSpec( rawTestSpec ); @@ -118,7 +123,6 @@ namespace Catch void runTest( const TestCaseInfo& testInfo ) { - IResultListener* prevListener = ResultsCapture::setListener( this ); m_reporter->StartTestCase( testInfo ); std::string redirectedCout; @@ -146,19 +150,19 @@ namespace Catch } m_info.clear(); m_reporter->EndTestCase( testInfo, redirectedCout, redirectedCerr ); - ResultsCapture::setListener( prevListener ); } - std::size_t getSuccessCount() const + virtual std::size_t getSuccessCount() const { return m_successes; } - std:: size_t getFailureCount() const + + virtual std:: size_t getFailureCount() const { return m_failures; } - private: // IResultListener + private: // IResultCapture virtual ResultAction::Value acceptResult( bool result ) { diff --git a/internal/catch_section.hpp b/internal/catch_section.hpp index dc8fba9e..b7de86cb 100644 --- a/internal/catch_section.hpp +++ b/internal/catch_section.hpp @@ -24,13 +24,13 @@ namespace Catch public: Section( const std::string& name, const std::string& description ) : m_name( name ), - m_sectionIncluded( ResultsCapture::getListener().sectionStarted( name, description, m_successes, m_failures ) ) + m_sectionIncluded( Hub::getResultCapture().sectionStarted( name, description, m_successes, m_failures ) ) { } ~Section() { - ResultsCapture::getListener().sectionEnded( m_name, m_successes, m_failures ); + Hub::getResultCapture().sectionEnded( m_name, m_successes, m_failures ); } // This indicates whether the section should be executed or not diff --git a/internal/catch_test_case_registry_impl.hpp b/internal/catch_test_case_registry_impl.hpp index b95d1172..71c65cb8 100644 --- a/internal/catch_test_case_registry_impl.hpp +++ b/internal/catch_test_case_registry_impl.hpp @@ -98,10 +98,10 @@ namespace Catch /////////////////////////////////////////////////////////////////////////// void AutoReg::registerTestCase ( - ITestCase* testCase, - const char* name, - const char* description - ) + ITestCase* testCase, + const char* name, + const char* description + ) { Hub::getTestCaseRegistry().registerTest( TestCaseInfo( testCase, name, description ) ); }