mirror of
				https://github.com/catchorg/Catch2.git
				synced 2025-10-31 20:27:11 +01:00 
			
		
		
		
	First cut of StaticRegistries - separate from Context
This commit is contained in:
		| @@ -19,30 +19,6 @@ namespace Catch { | ||||
|  | ||||
| struct TestFailureException{}; | ||||
|  | ||||
| class NotImplementedException : public std::exception | ||||
| { | ||||
| public: | ||||
|     NotImplementedException( const SourceLineInfo& lineInfo ) | ||||
|     :   m_lineInfo( lineInfo ) { | ||||
|         std::ostringstream oss; | ||||
|         oss << lineInfo << "function "; | ||||
|         if( !lineInfo.function.empty() ) | ||||
|             oss << lineInfo.function << " "; | ||||
|         oss << "not implemented"; | ||||
|         m_what = oss.str(); | ||||
|     } | ||||
|      | ||||
|     virtual ~NotImplementedException() throw() {} | ||||
|      | ||||
|     virtual const char* what() const throw() { | ||||
|         return m_what.c_str(); | ||||
|     } | ||||
|      | ||||
| private: | ||||
|     std::string m_what; | ||||
|     SourceLineInfo m_lineInfo; | ||||
| }; | ||||
|  | ||||
| class ScopedInfo { | ||||
| public: | ||||
|     ScopedInfo() : m_oss() { | ||||
| @@ -88,7 +64,7 @@ inline bool isTrue( bool value ){ return value; } | ||||
|     } catch( Catch::TestFailureException& ) { \ | ||||
|         throw; \ | ||||
|     } catch( ... ) { \ | ||||
|         INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr ) << Catch::getCurrentContext().getExceptionTranslatorRegistry().translateActiveException() ).setResultType( Catch::ResultWas::ThrewException ), false, expr ); \ | ||||
|         INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr ) << Catch::getStatics().getExceptionTranslatorRegistry().translateActiveException() ).setResultType( Catch::ResultWas::ThrewException ), false, expr ); \ | ||||
|         throw; \ | ||||
|     } } while( Catch::isTrue( false ) ) | ||||
|  | ||||
| @@ -109,7 +85,7 @@ inline bool isTrue( bool value ){ return value; } | ||||
|         INTERNAL_CATCH_ACCEPT_EXPR( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr ).setResultType( Catch::ResultWas::Ok ), stopOnFailure, false ); \ | ||||
|     } \ | ||||
|     catch( ... ) { \ | ||||
|         INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr ) << Catch::getCurrentContext().getExceptionTranslatorRegistry().translateActiveException() ).setResultType( Catch::ResultWas::ThrewException ), stopOnFailure, false ); \ | ||||
|         INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr ) << Catch::getStatics().getExceptionTranslatorRegistry().translateActiveException() ).setResultType( Catch::ResultWas::ThrewException ), stopOnFailure, false ); \ | ||||
|     } | ||||
|  | ||||
| /////////////////////////////////////////////////////////////////////////////// | ||||
| @@ -131,7 +107,7 @@ inline bool isTrue( bool value ){ return value; } | ||||
| #define INTERNAL_CATCH_THROWS_AS( expr, exceptionType, stopOnFailure, macroName ) \ | ||||
|     INTERNAL_CATCH_THROWS( expr, exceptionType, stopOnFailure, macroName ) \ | ||||
|     catch( ... ) { \ | ||||
|         INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr ) << Catch::getCurrentContext().getExceptionTranslatorRegistry().translateActiveException() ).setResultType( Catch::ResultWas::ThrewException ), stopOnFailure, false ); \ | ||||
|         INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr ) << Catch::getStatics().getExceptionTranslatorRegistry() ).setResultType( Catch::ResultWas::ThrewException ), stopOnFailure, false ); \ | ||||
|     } | ||||
|  | ||||
| /////////////////////////////////////////////////////////////////////////////// | ||||
| @@ -150,11 +126,8 @@ inline bool isTrue( bool value ){ return value; } | ||||
|     } catch( Catch::TestFailureException& ) { \ | ||||
|         throw; \ | ||||
|     } catch( ... ) { \ | ||||
|         INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName, #arg " " #matcher ) << Catch::getCurrentContext().getExceptionTranslatorRegistry().translateActiveException() ).setResultType( Catch::ResultWas::ThrewException ), false, false ); \ | ||||
|         INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName, #arg " " #matcher ) << Catch::getStatics().getExceptionTranslatorRegistry().translateActiveException() ).setResultType( Catch::ResultWas::ThrewException ), false, false ); \ | ||||
|         throw; \ | ||||
|     }}while( Catch::isTrue( false ) ) | ||||
|  | ||||
| /////////////////////////////////////////////////////////////////////////////// | ||||
| #define CATCH_NOT_IMPLEMENTED throw Catch::NotImplementedException( CATCH_INTERNAL_LINEINFO ) | ||||
|  | ||||
| #endif // TWOBLUECUBES_CATCH_CAPTURE_HPP_INCLUDED | ||||
|   | ||||
| @@ -19,9 +19,7 @@ namespace Catch { | ||||
|  | ||||
|     class TestCaseInfo; | ||||
|     struct IResultCapture; | ||||
|     struct ITestCaseRegistry; | ||||
|     struct IRunner; | ||||
|     struct IExceptionTranslatorRegistry; | ||||
|     class GeneratorsForTest; | ||||
|  | ||||
|     class StreamBufBase : public std::streambuf{}; | ||||
| @@ -32,9 +30,6 @@ namespace Catch { | ||||
|          | ||||
|         virtual IResultCapture& getResultCapture() = 0; | ||||
|         virtual IRunner& getRunner() = 0; | ||||
|         virtual IReporterRegistry& getReporterRegistry() = 0; | ||||
|         virtual ITestCaseRegistry& getTestCaseRegistry() = 0; | ||||
|         virtual IExceptionTranslatorRegistry& getExceptionTranslatorRegistry() = 0; | ||||
|         virtual size_t getGeneratorIndex( const std::string& fileInfo, size_t totalSize ) = 0; | ||||
|         virtual bool advanceGeneratorsForCurrentTest() = 0; | ||||
|         virtual const IConfig* getConfig() const = 0; | ||||
| @@ -59,9 +54,6 @@ namespace Catch { | ||||
|     public: // IContext | ||||
|         virtual IResultCapture& getResultCapture(); | ||||
|         virtual IRunner& getRunner(); | ||||
|         virtual IReporterRegistry& getReporterRegistry(); | ||||
|         virtual ITestCaseRegistry& getTestCaseRegistry(); | ||||
|         virtual IExceptionTranslatorRegistry& getExceptionTranslatorRegistry(); | ||||
|         virtual size_t getGeneratorIndex( const std::string& fileInfo, size_t totalSize ); | ||||
|         virtual bool advanceGeneratorsForCurrentTest(); | ||||
|         virtual const IConfig* getConfig() const; | ||||
| @@ -82,9 +74,6 @@ namespace Catch { | ||||
|         GeneratorsForTest& getGeneratorsForCurrentTest(); | ||||
|  | ||||
|     private:         | ||||
|         std::auto_ptr<IReporterRegistry> m_reporterRegistry; | ||||
|         std::auto_ptr<ITestCaseRegistry> m_testCaseRegistry; | ||||
|         std::auto_ptr<IExceptionTranslatorRegistry> m_exceptionTranslatorRegistry; | ||||
|         IRunner* m_runner; | ||||
|         IResultCapture* m_resultCapture; | ||||
|         const IConfig* m_config; | ||||
|   | ||||
| @@ -5,14 +5,11 @@ | ||||
|  *  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) | ||||
|  */ | ||||
| #include "catch_test_case_registry_impl.hpp" | ||||
| #include "catch_runner_impl.hpp" | ||||
| #include "catch_generators_impl.hpp" | ||||
| #include "catch_console_colour_impl.hpp" | ||||
|  | ||||
| #include "catch_exception_translator_registry.hpp" | ||||
| #include "catch_context.h" | ||||
| #include "catch_reporter_registry.hpp" | ||||
| #include "catch_stream.hpp" | ||||
|  | ||||
| namespace Catch { | ||||
| @@ -30,10 +27,7 @@ namespace Catch { | ||||
|     } | ||||
|   | ||||
|     Context::Context() | ||||
|     :   m_reporterRegistry( new ReporterRegistry ), | ||||
|         m_testCaseRegistry( new TestRegistry ), | ||||
|         m_exceptionTranslatorRegistry( new ExceptionTranslatorRegistry ), | ||||
|         m_config( NULL ) | ||||
|     :   m_config( NULL ) | ||||
|     {} | ||||
|  | ||||
|     void Context::cleanUp() { | ||||
| @@ -64,18 +58,6 @@ namespace Catch { | ||||
|         return *m_runner; | ||||
|     } | ||||
|      | ||||
|     IReporterRegistry& Context::getReporterRegistry() { | ||||
|         return *m_reporterRegistry.get(); | ||||
|     } | ||||
|  | ||||
|     ITestCaseRegistry& Context::getTestCaseRegistry() { | ||||
|         return *m_testCaseRegistry.get(); | ||||
|     } | ||||
|      | ||||
|     IExceptionTranslatorRegistry& Context::getExceptionTranslatorRegistry() { | ||||
|         return *m_exceptionTranslatorRegistry.get(); | ||||
|     } | ||||
|      | ||||
|     std::streambuf* Context::createStreamBuf( const std::string& streamName ) { | ||||
|         if( streamName == "stdout" ) return std::cout.rdbuf(); | ||||
|         if( streamName == "stderr" ) return std::cerr.rdbuf(); | ||||
|   | ||||
| @@ -17,12 +17,12 @@ | ||||
| namespace Catch { | ||||
|  | ||||
|     class ExceptionTranslatorRegistry : public IExceptionTranslatorRegistry { | ||||
|  | ||||
|     public: | ||||
|         ~ExceptionTranslatorRegistry() { | ||||
|             deleteAll( m_translators ); | ||||
|         } | ||||
|  | ||||
|         virtual void registerTranslator( IExceptionTranslator* translator ) { | ||||
|         virtual void registerTranslator( const IExceptionTranslator* translator ) { | ||||
|             m_translators.push_back( translator ); | ||||
|         } | ||||
|          | ||||
| @@ -54,7 +54,7 @@ namespace Catch { | ||||
|             } | ||||
|         } | ||||
|          | ||||
|         std::string tryTranslators( std::vector<IExceptionTranslator*>::const_iterator it ) const { | ||||
|         std::string tryTranslators( std::vector<const IExceptionTranslator*>::const_iterator it ) const { | ||||
|             if( it == m_translators.end() ) | ||||
|                 return "Unknown exception"; | ||||
|              | ||||
| @@ -67,7 +67,7 @@ namespace Catch { | ||||
|         } | ||||
|          | ||||
|     private: | ||||
|         std::vector<IExceptionTranslator*> m_translators; | ||||
|         std::vector<const IExceptionTranslator*> m_translators; | ||||
|     }; | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -1,14 +1,11 @@ | ||||
| // | ||||
| //  catch_impl.hpp | ||||
| //  CatchSelfTest | ||||
| // | ||||
| //  Created by Phil Nash on 05/08/2012. | ||||
| // | ||||
| // | ||||
| /* | ||||
|  *  Created by Phil on 5/8/2012. | ||||
|  *  Copyright 2012 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 CatchSelfTest_catch_impl_hpp | ||||
| #define CatchSelfTest_catch_impl_hpp | ||||
|  | ||||
|  | ||||
|  | ||||
| #endif | ||||
| #include "catch_static_registries_impl.hpp" | ||||
| #include "catch_notimplemented_exception.hpp" | ||||
| // !TBD... migrate all impl headers here | ||||
|   | ||||
| @@ -9,6 +9,7 @@ | ||||
| #define TWOBLUECUBES_CATCH_INTERFACES_EXCEPTIONS_H_INCLUDED | ||||
|  | ||||
| #include <string> | ||||
| #include "catch_interfaces_static_registries.h" | ||||
|                                                | ||||
| namespace Catch { | ||||
|      | ||||
| @@ -22,7 +23,6 @@ namespace Catch { | ||||
|     struct IExceptionTranslatorRegistry { | ||||
|         virtual ~IExceptionTranslatorRegistry(){} | ||||
|          | ||||
|         virtual void registerTranslator( IExceptionTranslator* translator ) = 0; | ||||
|         virtual std::string translateActiveException() const = 0; | ||||
|     }; | ||||
|  | ||||
| @@ -51,7 +51,7 @@ namespace Catch { | ||||
|     public: | ||||
|         template<typename T> | ||||
|         ExceptionTranslatorRegistrar( std::string(*translateFunction)( T& ) ) { | ||||
|             getCurrentContext().getExceptionTranslatorRegistry().registerTranslator | ||||
|             getStaticRegistries().registerTranslator | ||||
|                 ( new ExceptionTranslator<T>( translateFunction ) ); | ||||
|         } | ||||
|     }; | ||||
|   | ||||
| @@ -62,7 +62,6 @@ namespace Catch | ||||
|  | ||||
|         virtual ~IReporterRegistry() {} | ||||
|         virtual IReporter* create( const std::string& name, const ReporterConfig& config ) const = 0;         | ||||
|         virtual void registerReporter( const std::string& name, IReporterFactory* factory ) = 0;         | ||||
|         virtual const FactoryMap& getFactories() const = 0; | ||||
|     }; | ||||
|      | ||||
|   | ||||
| @@ -1,14 +1,46 @@ | ||||
| // | ||||
| //  catch_static_registries.h | ||||
| //  CatchSelfTest | ||||
| // | ||||
| //  Created by Phil Nash on 05/08/2012. | ||||
| // | ||||
| // | ||||
| /* | ||||
|  *  Created by Phil on 5/8/2012. | ||||
|  *  Copyright 2012 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_STATIC_REGISTRIES_H_INCLUDED | ||||
| #define TWOBLUECUBES_CATCH_STATIC_REGISTRIES_H_INCLUDED | ||||
|  | ||||
| #ifndef CatchSelfTest_catch_static_registries_h | ||||
| #define CatchSelfTest_catch_static_registries_h | ||||
| #include "catch_interfaces_reporter.h" | ||||
| #include "catch_interfaces_config.h" | ||||
|  | ||||
| #include <memory> | ||||
| #include <vector> | ||||
| #include <stdlib.h> | ||||
|  | ||||
| namespace Catch { | ||||
|  | ||||
| #endif | ||||
|     class TestCaseInfo; | ||||
|     struct IResultCapture; | ||||
|     struct ITestCaseRegistry; | ||||
|     struct IExceptionTranslatorRegistry; | ||||
|     struct IExceptionTranslator; | ||||
|  | ||||
|     struct IStatics { | ||||
|         virtual ~IStatics(){} | ||||
|  | ||||
|         virtual const IReporterRegistry& getReporterRegistry() const = 0; | ||||
|         virtual const ITestCaseRegistry& getTestCaseRegistry() const = 0; | ||||
|         virtual IExceptionTranslatorRegistry& getExceptionTranslatorRegistry() = 0; | ||||
|     }; | ||||
|  | ||||
|     struct IStaticRegistries { | ||||
|         virtual ~IStaticRegistries(){} | ||||
|         virtual void registerReporter( const std::string& name, IReporterFactory* factory ) = 0; | ||||
|         virtual void registerTest( const TestCaseInfo& testInfo ) = 0; | ||||
|         virtual void registerTranslator( const IExceptionTranslator* translator ) = 0; | ||||
|     }; | ||||
|  | ||||
|     IStatics& getStatics(); | ||||
|     IStaticRegistries& getStaticRegistries(); | ||||
|     void cleanUp(); | ||||
| } | ||||
|  | ||||
| #endif // TWOBLUECUBES_CATCH_STATIC_REGISTRIES_H_INCLUDED | ||||
|   | ||||
| @@ -23,9 +23,8 @@ namespace Catch { | ||||
|  | ||||
|     struct ITestCaseRegistry { | ||||
|         virtual ~ITestCaseRegistry(){} | ||||
|         virtual void registerTest( const TestCaseInfo& testInfo ) = 0;         | ||||
|         virtual const std::vector<TestCaseInfo>& getAllTests() const = 0; | ||||
|         virtual std::vector<TestCaseInfo> getMatchingTestCases( const std::string& rawTestSpec ) = 0; | ||||
|         virtual std::vector<TestCaseInfo> getMatchingTestCases( const std::string& rawTestSpec ) const = 0; | ||||
|     }; | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -14,11 +14,10 @@ | ||||
| namespace Catch { | ||||
|     inline int List( Config& config ) { | ||||
|          | ||||
|         IContext& context = getCurrentContext(); | ||||
|         if( config.listWhat() & List::Reports ) { | ||||
|             std::cout << "Available reports:\n"; | ||||
|             IReporterRegistry::FactoryMap::const_iterator it = context.getReporterRegistry().getFactories().begin(); | ||||
|             IReporterRegistry::FactoryMap::const_iterator itEnd = context.getReporterRegistry().getFactories().end(); | ||||
|             IReporterRegistry::FactoryMap::const_iterator it = getStatics().getReporterRegistry().getFactories().begin(); | ||||
|             IReporterRegistry::FactoryMap::const_iterator itEnd = getStatics().getReporterRegistry().getFactories().end(); | ||||
|             for(; it != itEnd; ++it ) { | ||||
|                 // !TBD: consider listAs() | ||||
|                 std::cout << "\t" << it->first << "\n\t\t'" << it->second->getDescription() << "'\n"; | ||||
| @@ -28,8 +27,8 @@ namespace Catch { | ||||
|          | ||||
|         if( config.listWhat() & List::Tests ) { | ||||
|             std::cout << "Available tests:\n"; | ||||
|             std::vector<TestCaseInfo>::const_iterator it = context.getTestCaseRegistry().getAllTests().begin(); | ||||
|             std::vector<TestCaseInfo>::const_iterator itEnd = context.getTestCaseRegistry().getAllTests().end(); | ||||
|             std::vector<TestCaseInfo>::const_iterator it = getStatics().getTestCaseRegistry().getAllTests().begin(); | ||||
|             std::vector<TestCaseInfo>::const_iterator itEnd = getStatics().getTestCaseRegistry().getAllTests().end(); | ||||
|             for(; it != itEnd; ++it ) { | ||||
|                 // !TBD: consider listAs() | ||||
|                 std::cout << "\t" << it->getName() << "\n\t\t '" << it->getDescription() << "'\n"; | ||||
|   | ||||
| @@ -1,14 +1,35 @@ | ||||
| // | ||||
| //  catch_notimplemented_exception.h | ||||
| //  CatchSelfTest | ||||
| // | ||||
| //  Created by Phil Nash on 05/08/2012. | ||||
| // | ||||
| // | ||||
| /* | ||||
|  *  Created by Phil on 5/8/2012. | ||||
|  *  Copyright 2012 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_NOTIMPLEMENTED_EXCEPTION_H_INCLUDED | ||||
| #define TWOBLUECUBES_CATCH_NOTIMPLEMENTED_EXCEPTION_H_INCLUDED | ||||
|  | ||||
| #ifndef CatchSelfTest_catch_notimplemented_exception_h | ||||
| #define CatchSelfTest_catch_notimplemented_exception_h | ||||
| #include "catch_common.h" | ||||
| #include <ostream> | ||||
|  | ||||
| namespace Catch { | ||||
|  | ||||
|     class NotImplementedException : public std::exception | ||||
|     { | ||||
|     public: | ||||
|         NotImplementedException( const SourceLineInfo& lineInfo ); | ||||
|  | ||||
| #endif | ||||
|         virtual ~NotImplementedException() throw() {} | ||||
|  | ||||
|         virtual const char* what() const throw(); | ||||
|  | ||||
|     private: | ||||
|         std::string m_what; | ||||
|         SourceLineInfo m_lineInfo; | ||||
|     }; | ||||
|  | ||||
| } // end namespace Catch | ||||
|  | ||||
| /////////////////////////////////////////////////////////////////////////////// | ||||
| #define CATCH_NOT_IMPLEMENTED throw Catch::NotImplementedException( CATCH_INTERNAL_LINEINFO ) | ||||
|  | ||||
| #endif // TWOBLUECUBES_CATCH_NOTIMPLEMENTED_EXCEPTION_H_INCLUDED | ||||
|   | ||||
| @@ -1,14 +1,32 @@ | ||||
| // | ||||
| //  catch_notimplemented_exception.hpp | ||||
| //  CatchSelfTest | ||||
| // | ||||
| //  Created by Phil Nash on 05/08/2012. | ||||
| // | ||||
| // | ||||
| /* | ||||
|  *  Created by Phil on 5/8/2012. | ||||
|  *  Copyright 2012 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_NOTIMPLEMENTED_EXCEPTION_HPP_INCLUDED | ||||
| #define TWOBLUECUBES_CATCH_NOTIMPLEMENTED_EXCEPTION_HPP_INCLUDED | ||||
|  | ||||
| #ifndef CatchSelfTest_catch_notimplemented_exception_hpp | ||||
| #define CatchSelfTest_catch_notimplemented_exception_hpp | ||||
| #include "catch_notimplemented_exception.h" | ||||
| #include <ostream> | ||||
|  | ||||
| namespace Catch { | ||||
|  | ||||
|     NotImplementedException::NotImplementedException( const SourceLineInfo& lineInfo ) | ||||
|     :   m_lineInfo( lineInfo ) { | ||||
|         std::ostringstream oss; | ||||
|         oss << lineInfo << "function "; | ||||
|         if( !lineInfo.function.empty() ) | ||||
|             oss << lineInfo.function << " "; | ||||
|         oss << "not implemented"; | ||||
|         m_what = oss.str(); | ||||
|     } | ||||
|  | ||||
| #endif | ||||
|     const char* NotImplementedException::what() const throw() { | ||||
|         return m_what.c_str(); | ||||
|     } | ||||
|      | ||||
| } // end namespace Catch | ||||
|  | ||||
| #endif // TWOBLUECUBES_CATCH_NOTIMPLEMENTED_EXCEPTION_H_INCLUDED | ||||
|   | ||||
| @@ -106,7 +106,7 @@ namespace Catch { | ||||
|                         std::string name = Detail::getAnnotation( cls, "Name", testCaseName ); | ||||
|                         std::string desc = Detail::getAnnotation( cls, "Description", testCaseName ); | ||||
|                          | ||||
|                         getCurrentContext().getTestCaseRegistry().registerTest( TestCaseInfo( new OcMethod( cls, selector ), name.c_str(), desc.c_str(), SourceLineInfo() ) ); | ||||
|                         getStaticRegisteries().registerTest( TestCaseInfo( new OcMethod( cls, selector ), name.c_str(), desc.c_str(), SourceLineInfo() ) ); | ||||
|                         noTestMethods++; | ||||
|                     } | ||||
|                 } | ||||
|   | ||||
| @@ -8,7 +8,7 @@ | ||||
| #ifndef TWOBLUECUBES_CATCH_REPORTER_REGISTRARS_HPP_INCLUDED | ||||
| #define TWOBLUECUBES_CATCH_REPORTER_REGISTRARS_HPP_INCLUDED | ||||
|  | ||||
| #include "catch_context.h" | ||||
| #include "catch_interfaces_static_registries.h" | ||||
|  | ||||
| namespace Catch {     | ||||
|  | ||||
| @@ -29,7 +29,7 @@ namespace Catch { | ||||
|     public: | ||||
|  | ||||
|         ReporterRegistrar( const std::string& name ) { | ||||
|             getCurrentContext().getReporterRegistry().registerReporter( name, new ReporterFactory() ); | ||||
|             getStaticRegistries().registerReporter( name, new ReporterFactory() ); | ||||
|         } | ||||
|     };  | ||||
| } | ||||
|   | ||||
| @@ -80,7 +80,7 @@ namespace Catch { | ||||
|          | ||||
|         virtual void runAll( bool runHiddenTests = false ) { | ||||
|             m_reporter->StartGroup( "" ); | ||||
|             const std::vector<TestCaseInfo>& allTests = getCurrentContext().getTestCaseRegistry().getAllTests(); | ||||
|             const std::vector<TestCaseInfo>& allTests = getStatics().getTestCaseRegistry().getAllTests(); | ||||
|             for( std::size_t i=0; i < allTests.size(); ++i ) { | ||||
|                 if( runHiddenTests || !allTests[i].isHidden() ) { | ||||
|                     if( aborting() ) { | ||||
| @@ -100,7 +100,7 @@ namespace Catch { | ||||
|  | ||||
|             TestSpec testSpec( rawTestSpec ); | ||||
|              | ||||
|             const std::vector<TestCaseInfo>& allTests = getCurrentContext().getTestCaseRegistry().getAllTests(); | ||||
|             const std::vector<TestCaseInfo>& allTests = getStatics().getTestCaseRegistry().getAllTests(); | ||||
|             std::size_t testsRun = 0; | ||||
|             for( std::size_t i=0; i < allTests.size(); ++i ) { | ||||
|                 if( testSpec.matches( allTests[i].getName() ) ) { | ||||
| @@ -282,7 +282,7 @@ namespace Catch { | ||||
|                 // This just means the test was aborted due to failure | ||||
|             } | ||||
|             catch(...) { | ||||
|                 acceptMessage( getCurrentContext().getExceptionTranslatorRegistry().translateActiveException() ); | ||||
|                 acceptMessage( getStatics().getExceptionTranslatorRegistry().translateActiveException() ); | ||||
|                 acceptResult( ResultWas::ThrewException ); | ||||
|             } | ||||
|             m_info.clear(); | ||||
|   | ||||
| @@ -1,14 +1,73 @@ | ||||
| // | ||||
| //  catch_static_registries.hpp | ||||
| //  CatchSelfTest | ||||
| // | ||||
| //  Created by Phil Nash on 05/08/2012. | ||||
| // | ||||
| // | ||||
| /* | ||||
|  *  Created by Phil on 5/8/2012. | ||||
|  *  Copyright 2012 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) | ||||
|  */ | ||||
| #include "catch_interfaces_static_registries.h" | ||||
|  | ||||
| #ifndef CatchSelfTest_catch_static_registries_hpp | ||||
| #define CatchSelfTest_catch_static_registries_hpp | ||||
| #include "catch_test_case_registry_impl.hpp" | ||||
| #include "catch_reporter_registry.hpp" | ||||
| #include "catch_exception_translator_registry.hpp" | ||||
|  | ||||
| namespace Catch { | ||||
|  | ||||
|     namespace { | ||||
|          | ||||
|         class StaticRegistries : public IStatics, public IStaticRegistries { | ||||
|  | ||||
| #endif | ||||
|             StaticRegistries( const StaticRegistries& ); | ||||
|             void operator=( const StaticRegistries& ); | ||||
|  | ||||
|         public: // IStatics | ||||
|             StaticRegistries() { | ||||
|             } | ||||
|             virtual const IReporterRegistry& getReporterRegistry() const { | ||||
|                 return m_reporterRegistry; | ||||
|             } | ||||
|             virtual const ITestCaseRegistry& getTestCaseRegistry() const { | ||||
|                 return m_testCaseRegistry; | ||||
|             } | ||||
|             virtual IExceptionTranslatorRegistry& getExceptionTranslatorRegistry() { | ||||
|                 return m_exceptionTranslatorRegistry; | ||||
|             } | ||||
|  | ||||
|         public: // IStaticRegistries | ||||
|             virtual void registerReporter( const std::string& name, IReporterFactory* factory ) { | ||||
|                 m_reporterRegistry.registerReporter( name, factory ); | ||||
|             } | ||||
|             virtual void registerTest( const TestCaseInfo& testInfo ) { | ||||
|                 m_testCaseRegistry.registerTest( testInfo ); | ||||
|             } | ||||
|             virtual void registerTranslator( const IExceptionTranslator* translator ) { | ||||
|                 m_exceptionTranslatorRegistry.registerTranslator( translator ); | ||||
|             } | ||||
|  | ||||
|         private: | ||||
|             TestRegistry m_testCaseRegistry; | ||||
|             ReporterRegistry m_reporterRegistry; | ||||
|             ExceptionTranslatorRegistry m_exceptionTranslatorRegistry; | ||||
|         }; | ||||
|  | ||||
|         inline StaticRegistries*& getTheStaticRegistries() { | ||||
|             static StaticRegistries* registries = NULL; | ||||
|             if( !registries ) | ||||
|                 registries = new StaticRegistries(); | ||||
|             return registries; | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     IStatics& getStatics() { | ||||
|         return *getTheStaticRegistries(); | ||||
|     } | ||||
|     IStaticRegistries& getStaticRegistries() { | ||||
|         return *getTheStaticRegistries(); | ||||
|     } | ||||
|     void cleanUp() { | ||||
|         delete getTheStaticRegistries(); | ||||
|         getTheStaticRegistries() = NULL; | ||||
|         Context::cleanUp(); | ||||
|     } | ||||
|  | ||||
| } // end namespace Catch | ||||
|   | ||||
| @@ -44,7 +44,7 @@ namespace Catch { | ||||
|             return m_functionsInOrder; | ||||
|         } | ||||
|  | ||||
|         virtual std::vector<TestCaseInfo> getMatchingTestCases( const std::string& rawTestSpec ) { | ||||
|         virtual std::vector<TestCaseInfo> getMatchingTestCases( const std::string& rawTestSpec ) const { | ||||
|             TestSpec testSpec( rawTestSpec ); | ||||
|              | ||||
|             std::vector<TestCaseInfo> testList; | ||||
| @@ -109,7 +109,7 @@ namespace Catch { | ||||
|                                     const char* name,  | ||||
|                                     const char* description, | ||||
|                                     const SourceLineInfo& lineInfo ) { | ||||
|         getCurrentContext().getTestCaseRegistry().registerTest( TestCaseInfo( testCase, name, description, lineInfo ) ); | ||||
|         getStaticRegistries().registerTest( TestCaseInfo( testCase, name, description, lineInfo ) ); | ||||
|     } | ||||
|      | ||||
| } // end namespace Catch | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Phil Nash
					Phil Nash