From 44488f6331688209d3951a57e4d2af8dc0f27862 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Fri, 28 Jan 2011 18:56:26 +0000 Subject: [PATCH] Some formating clean-up --- internal/catch_generators_impl.hpp | 10 +++- internal/catch_hub.h | 4 +- internal/catch_resultinfo.hpp | 47 +++++++++++---- internal/catch_runner_impl.hpp | 68 ++++++++++++++++++---- internal/catch_section.hpp | 15 ++++- internal/catch_test_case_registry_impl.hpp | 57 ++++++++++++++---- 6 files changed, 160 insertions(+), 41 deletions(-) diff --git a/internal/catch_generators_impl.hpp b/internal/catch_generators_impl.hpp index e87aaf09..f737ab3a 100644 --- a/internal/catch_generators_impl.hpp +++ b/internal/catch_generators_impl.hpp @@ -21,9 +21,9 @@ namespace Catch { - struct GeneratorInfo { + /////////////////////////////////////////////////////////////////////// GeneratorInfo ( std::size_t size @@ -33,6 +33,7 @@ namespace Catch { } + /////////////////////////////////////////////////////////////////////// bool moveNext () { @@ -44,6 +45,7 @@ namespace Catch return true; } + /////////////////////////////////////////////////////////////////////// std::size_t getCurrentIndex () const @@ -55,16 +57,21 @@ namespace Catch std::size_t m_currentIndex; }; + /////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////// + class GeneratorsForTest { public: + /////////////////////////////////////////////////////////////////////// ~GeneratorsForTest () { deleteAll( m_generatorsInOrder ); } + /////////////////////////////////////////////////////////////////////// GeneratorInfo& getGeneratorInfo ( const std::string& fileInfo, @@ -82,6 +89,7 @@ namespace Catch return *it->second; } + /////////////////////////////////////////////////////////////////////// bool moveNext () { diff --git a/internal/catch_hub.h b/internal/catch_hub.h index bb091691..374b245b 100644 --- a/internal/catch_hub.h +++ b/internal/catch_hub.h @@ -65,12 +65,14 @@ namespace Catch ( const std::string& fileInfo, size_t totalSize ); + static bool advanceGeneratorsForCurrentTest - (); + (); private: GeneratorsForTest* findGeneratorsForCurrentTest (); + GeneratorsForTest& getGeneratorsForCurrentTest (); diff --git a/internal/catch_resultinfo.hpp b/internal/catch_resultinfo.hpp index 41676965..f7e7f96b 100644 --- a/internal/catch_resultinfo.hpp +++ b/internal/catch_resultinfo.hpp @@ -22,7 +22,8 @@ namespace Catch public: /////////////////////////////////////////////////////////////////////////// - ResultInfo() + ResultInfo + () : m_line( 0 ), m_result( ResultWas::Unknown ), m_isNot( false ), @@ -53,37 +54,49 @@ namespace Catch } /////////////////////////////////////////////////////////////////////////// - bool ok() const + bool ok + () + const { return ( m_result & ResultWas::FailureBit ) != ResultWas::FailureBit; } /////////////////////////////////////////////////////////////////////////// - ResultWas::OfType getResultType() const + ResultWas::OfType getResultType + () + const { return m_result; } /////////////////////////////////////////////////////////////////////////// - bool hasExpression() const + bool hasExpression + () + const { return !m_expr.empty(); } /////////////////////////////////////////////////////////////////////////// - bool hasMessage() const + bool hasMessage + () + const { return !m_message.empty(); } /////////////////////////////////////////////////////////////////////////// - std::string getExpression() const + std::string getExpression + () + const { return m_expr; } /////////////////////////////////////////////////////////////////////////// - std::string getExpandedExpression() const + std::string getExpandedExpression + () + const { if( !hasExpression() ) return ""; @@ -94,25 +107,33 @@ namespace Catch } /////////////////////////////////////////////////////////////////////////// - std::string getMessage() const + std::string getMessage + () + const { return m_message; } /////////////////////////////////////////////////////////////////////////// - std::string getFilename() const + std::string getFilename + () + const { return m_filename; } /////////////////////////////////////////////////////////////////////////// - std::size_t getLine() const + std::size_t getLine + () + const { return m_line; } /////////////////////////////////////////////////////////////////////////// - std::string getTestMacroName() const + std::string getTestMacroName + () + const { return m_macroName; } @@ -120,7 +141,9 @@ namespace Catch protected: /////////////////////////////////////////////////////////////////////////// - std::string getExpandedExpressionInternal() const + std::string getExpandedExpressionInternal + () + const { if( m_op == "" || m_isNot ) return m_lhs.empty() ? m_expr : m_op + m_lhs; diff --git a/internal/catch_runner_impl.hpp b/internal/catch_runner_impl.hpp index 8d454e52..12537472 100644 --- a/internal/catch_runner_impl.hpp +++ b/internal/catch_runner_impl.hpp @@ -24,7 +24,11 @@ namespace Catch class TestSpec { public: - TestSpec( const std::string& rawSpec ) + /////////////////////////////////////////////////////////////////////// + TestSpec + ( + const std::string& rawSpec + ) : m_rawSpec( rawSpec ), m_isWildcarded( false ) { @@ -35,7 +39,12 @@ namespace Catch } } - bool matches( const std::string& testName ) const + /////////////////////////////////////////////////////////////////////// + bool matches + ( + const std::string& testName + ) + const { if( !m_isWildcarded ) return m_rawSpec == testName; @@ -48,37 +57,60 @@ namespace Catch bool m_isWildcarded; }; + /////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////// + class RunningTest { public: - explicit RunningTest( const TestCaseInfo* info = NULL ) + /////////////////////////////////////////////////////////////////////// + explicit RunningTest + ( + const TestCaseInfo* info = NULL + ) : m_info( info ), m_sectionSeen( false ) { } - size_t sectionsSeenCount() const + /////////////////////////////////////////////////////////////////////// + size_t sectionsSeenCount + () + const { return m_sectionsSeen.size(); } - bool wasSectionSeen() const + /////////////////////////////////////////////////////////////////////// + bool wasSectionSeen + () + const { return m_sectionSeen; } - void resetSectionSeen() + + /////////////////////////////////////////////////////////////////////// + void resetSectionSeen + () { m_sectionSeen = false; } - bool addSection( const std::string& name ) + /////////////////////////////////////////////////////////////////////// + bool addSection + ( + const std::string& name + ) { if( m_sectionsSeen.find( name ) != m_sectionsSeen.end() ) return false; m_sectionsSeen.insert( name ); return m_sectionSeen = true; } - const TestCaseInfo& getTestCaseInfo() const + /////////////////////////////////////////////////////////////////////// + const TestCaseInfo& getTestCaseInfo + () + const { return *m_info; } @@ -90,18 +122,28 @@ namespace Catch }; + /////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////// + class StreamRedirect { public: - StreamRedirect( std::ostream& stream, std::string& targetString ) + /////////////////////////////////////////////////////////////////////// + StreamRedirect + ( + std::ostream& stream, + std::string& targetString + ) : m_stream( stream ), - m_prevBuf( stream.rdbuf() ), - m_targetString( targetString ) + m_prevBuf( stream.rdbuf() ), + m_targetString( targetString ) { stream.rdbuf( m_oss.rdbuf() ); } - ~StreamRedirect() + /////////////////////////////////////////////////////////////////////// + ~StreamRedirect + () { m_targetString = m_oss.str(); m_stream.rdbuf( m_prevBuf ); @@ -114,6 +156,8 @@ namespace Catch std::string& m_targetString; }; + /////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////// class Runner : public IResultCapture, public IRunner { diff --git a/internal/catch_section.hpp b/internal/catch_section.hpp index 67156d36..4cc63931 100644 --- a/internal/catch_section.hpp +++ b/internal/catch_section.hpp @@ -22,20 +22,29 @@ namespace Catch class Section { public: - Section( const std::string& name, const std::string& description ) + /////////////////////////////////////////////////////////////////////// + Section + ( + const std::string& name, + const std::string& description + ) : m_name( name ), m_sectionIncluded( Hub::getResultCapture().sectionStarted( name, description, m_successes, m_failures ) ) { } - ~Section() + /////////////////////////////////////////////////////////////////////// + ~Section + () { if( m_sectionIncluded ) Hub::getResultCapture().sectionEnded( m_name, m_successes, m_failures ); } + /////////////////////////////////////////////////////////////////////// // This indicates whether the section should be executed or not - operator bool() + operator bool + () { return m_sectionIncluded; } diff --git a/internal/catch_test_case_registry_impl.hpp b/internal/catch_test_case_registry_impl.hpp index 63686f81..29ff81ca 100644 --- a/internal/catch_test_case_registry_impl.hpp +++ b/internal/catch_test_case_registry_impl.hpp @@ -23,12 +23,18 @@ namespace Catch class TestRegistry : public ITestCaseRegistry { public: - TestRegistry() + /////////////////////////////////////////////////////////////////////////// + TestRegistry + () : m_unnamedCount( 0 ) { } - virtual void registerTest( const TestCaseInfo& testInfo ) + /////////////////////////////////////////////////////////////////////////// + virtual void registerTest + ( + const TestCaseInfo& testInfo + ) { if( testInfo.getName() == "" ) { @@ -43,7 +49,10 @@ namespace Catch } } - virtual const std::vector& getAllTests() const + /////////////////////////////////////////////////////////////////////////// + virtual const std::vector& getAllTests + () + const { return m_functionsInOrder; } @@ -54,30 +63,54 @@ namespace Catch std::vector m_functionsInOrder; size_t m_unnamedCount; }; + + /////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////// + struct FreeFunctionTestCase : ITestCase { - FreeFunctionTestCase( TestFunction fun ) + /////////////////////////////////////////////////////////////////////////// + FreeFunctionTestCase + ( + TestFunction fun + ) : fun( fun ) {} - virtual void invoke() const + /////////////////////////////////////////////////////////////////////////// + virtual void invoke + () + const { fun(); } - virtual ITestCase* clone() const + /////////////////////////////////////////////////////////////////////////// + virtual ITestCase* clone + () + const { return new FreeFunctionTestCase( fun ); } - virtual bool operator == ( const ITestCase& other ) const + /////////////////////////////////////////////////////////////////////////// + virtual bool operator == + ( + const ITestCase& other + ) + const { const FreeFunctionTestCase* ffOther = dynamic_cast ( &other ); return ffOther && fun == ffOther->fun; } - virtual bool operator < ( const ITestCase& other ) const + /////////////////////////////////////////////////////////////////////////// + virtual bool operator < + ( + const ITestCase& other + ) + const { const FreeFunctionTestCase* ffOther = dynamic_cast ( &other ); return ffOther && fun < ffOther->fun; @@ -93,10 +126,10 @@ namespace Catch /////////////////////////////////////////////////////////////////////////// AutoReg::AutoReg ( - TestFunction function, - const char* name, - const char* description - ) + TestFunction function, + const char* name, + const char* description + ) { registerTestCase( new FreeFunctionTestCase( function ), name, description ); }