diff options
| author | Phil Nash | 2012-05-16 15:09:17 +0100 |
|---|---|---|
| committer | Phil Nash | 2012-05-16 15:09:17 +0100 |
| commit | 89d2a3f911cd87a6bef96aceb1702e65eee73163 (patch) | |
| tree | c8fe34b423c2911d74e7516585bd116fc8fa70ce | |
| parent | 44fbbb07f0f2525d0a95cebaf230444e99c2b93f (diff) | |
| download | catch3-89d2a3f911cd87a6bef96aceb1702e65eee73163.tar.gz | |
Regenerated single include
| -rw-r--r-- | single_include/catch.hpp | 3056 |
1 files changed, 846 insertions, 2210 deletions
diff --git a/single_include/catch.hpp b/single_include/catch.hpp index 4bca13ce..c4d65ef6 100644 --- a/single_include/catch.hpp +++ b/single_include/catch.hpp @@ -31,8 +31,8 @@ #include <stdexcept> #include <algorithm> -namespace Catch -{ +namespace Catch { + class NonCopyable { NonCopyable( const NonCopyable& ); void operator = ( const NonCopyable& ); @@ -70,8 +70,8 @@ namespace Catch std::for_each( container.begin(), container.end(), function ); } - struct SourceLineInfo - { + struct SourceLineInfo { + SourceLineInfo() : line( 0 ){} SourceLineInfo( const std::string& _file, std::size_t _line ) : file( _file ), @@ -112,10 +112,9 @@ namespace Catch // #included from: catch_totals.hpp -namespace Catch -{ - struct Counts - { +namespace Catch { + + struct Counts { Counts() : passed( 0 ), failed( 0 ) {} Counts operator - ( const Counts& other ) const { @@ -133,8 +132,8 @@ namespace Catch std::size_t failed; }; - struct Totals - { + struct Totals { + Totals operator - ( const Totals& other ) const { Totals diff; diff.assertions = assertions - other.assertions; @@ -149,14 +148,13 @@ namespace Catch // #included from: catch_ptr.hpp -namespace Catch -{ +namespace Catch { + // An intrusive reference counting smart pointer. // T must implement addRef() and release() methods // typically implementing the IShared interface template<typename T> - class Ptr - { + class Ptr { public: Ptr() : m_p( NULL ){} Ptr( T* p ) : m_p( p ){ @@ -255,7 +253,7 @@ namespace Catch virtual void EndTesting( const Totals& totals ) = 0; virtual void StartGroup( const std::string& groupName ) = 0; virtual void EndGroup( const std::string& groupName, const Totals& totals ) = 0; - virtual void StartSection( const std::string& sectionName, const std::string description ) = 0; + virtual void StartSection( const std::string& sectionName, const std::string& description ) = 0; virtual void EndSection( const std::string& sectionName, const Counts& assertions ) = 0; virtual void StartTestCase( const TestCaseInfo& testInfo ) = 0; virtual void EndTestCase( const TestCaseInfo& testInfo, const Totals& totals, const std::string& stdOut, const std::string& stdErr ) = 0; @@ -277,8 +275,7 @@ namespace Catch virtual const FactoryMap& getFactories() const = 0; }; - inline std::string trim( const std::string& str ) - { + inline std::string trim( const std::string& str ) { std::string::size_type start = str.find_first_not_of( "\n\r\t " ); std::string::size_type end = str.find_last_not_of( "\n\r\t " ); @@ -290,8 +287,8 @@ namespace Catch #include <vector> #include <stdlib.h> -namespace Catch -{ +namespace Catch { + class TestCaseInfo; struct IResultCapture; struct ITestCaseRegistry; @@ -301,8 +298,8 @@ namespace Catch class StreamBufBase : public std::streambuf{}; - class Context - { + class Context { + Context(); Context( const Context& ); void operator=( const Context& ); @@ -342,56 +339,30 @@ namespace Catch #include <vector> -namespace Catch -{ - struct ITestCase - { - virtual ~ITestCase - () - {} - - virtual void invoke - () const = 0; - - virtual ITestCase* clone - () const = 0; - - virtual bool operator == - ( const ITestCase& other - ) const = 0; - - virtual bool operator < - ( const ITestCase& other - ) const = 0; +namespace Catch { + struct ITestCase { + virtual ~ITestCase(){} + virtual void invoke () const = 0; + virtual ITestCase* clone() const = 0; + virtual bool operator == ( const ITestCase& other ) const = 0; + virtual bool operator < ( const ITestCase& other ) const = 0; }; class TestCaseInfo; - 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; + 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; }; } -namespace Catch -{ +namespace Catch { template<typename C> -class MethodTestCase : public ITestCase -{ +class MethodTestCase : public ITestCase { + public: MethodTestCase( void (C::*method)() ) : m_method( method ) {} @@ -420,8 +391,8 @@ private: typedef void(*TestFunction)(); -struct AutoReg -{ +struct AutoReg { + AutoReg( TestFunction function, const char* name, const char* description, @@ -477,6 +448,8 @@ private: // #included from: internal/catch_capture.hpp +// #included from: catch_expression_builder.hpp + // #included from: catch_expression.hpp // #included from: catch_resultinfo_builder.hpp @@ -485,10 +458,9 @@ private: #include <sstream> -namespace Catch -{ -namespace Detail -{ +namespace Catch { +namespace Detail { + struct NonStreamable { template<typename T> NonStreamable( const T& ){} }; @@ -603,50 +575,41 @@ inline std::string toString( std::nullptr_t null ) { #include <string> // #included from: catch_result_type.h -namespace Catch -{ +namespace Catch { -struct ResultWas{ enum OfType - { - Unknown = -1, - Ok = 0, - Info = 1, - Warning = 2, +struct ResultWas { enum OfType { + Unknown = -1, + Ok = 0, + Info = 1, + Warning = 2, - FailureBit = 0x10, + FailureBit = 0x10, - ExpressionFailed = FailureBit | 1, - ExplicitFailure = FailureBit | 2, + ExpressionFailed = FailureBit | 1, + ExplicitFailure = FailureBit | 2, - Exception = 0x100 | FailureBit, + Exception = 0x100 | FailureBit, - ThrewException = Exception | 1, - DidntThrowException = Exception | 2 + 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 - }; - }; +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 + +}; }; } -namespace Catch -{ - class ResultInfo - { - public: +namespace Catch { - /////////////////////////////////////////////////////////////////////////// - ResultInfo - () + class ResultInfo { + public: + ResultInfo() : m_macroName(), m_expr(), m_lhs(), @@ -657,16 +620,12 @@ namespace Catch m_isNot( false ) {} - /////////////////////////////////////////////////////////////////////////// - ResultInfo - ( - const char* expr, - ResultWas::OfType result, - bool isNot, - const SourceLineInfo& lineInfo, - const char* macroName, - const char* message - ) + ResultInfo( const char* expr, + ResultWas::OfType result, + bool isNot, + const SourceLineInfo& lineInfo, + const char* macroName, + const char* message ) : m_macroName( macroName ), m_lineInfo( lineInfo ), m_expr( expr ), @@ -681,107 +640,55 @@ namespace Catch m_expr = "!" + m_expr; } - /////////////////////////////////////////////////////////////////////////// - virtual ~ResultInfo - () - { - } + virtual ~ResultInfo() {} - /////////////////////////////////////////////////////////////////////////// - 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; } - /////////////////////////////////////////////////////////////////////////// - bool hasExpandedExpression - () - const - { + bool hasExpandedExpression() const { return hasExpression() && getExpandedExpressionInternal() != m_expr; } - /////////////////////////////////////////////////////////////////////////// - std::string getExpandedExpression - () - const - { + std::string getExpandedExpression() const { return hasExpression() ? getExpandedExpressionInternal() : ""; } - /////////////////////////////////////////////////////////////////////////// - std::string getMessage - () - const - { + std::string getMessage() const { return m_message; } - /////////////////////////////////////////////////////////////////////////// - std::string getFilename - () - const - { + std::string getFilename() const { return m_lineInfo.file; } - /////////////////////////////////////////////////////////////////////////// - std::size_t getLine - () - const - { + std::size_t getLine() const { return m_lineInfo.line; } - /////////////////////////////////////////////////////////////////////////// - std::string getTestMacroName - () - const - { + std::string getTestMacroName() const { return m_macroName; } protected: - /////////////////////////////////////////////////////////////////////////// - std::string getExpandedExpressionInternal - () - const - { + std::string getExpandedExpressionInternal() const { if( m_op == "" || m_isNot ) return m_lhs.empty() ? m_expr : m_op + m_lhs; else if( m_op == "matches" ) @@ -799,12 +706,7 @@ namespace Catch return "{can't expand - use " + m_macroName + "_FALSE( " + m_expr.substr(1) + " ) instead of " + m_macroName + "( " + m_expr + " ) for better diagnostics}"; } - /////////////////////////////////////////////////////////////////////////// - bool isNotExpression - ( - const char* expr - ) - { + bool isNotExpression( const char* expr ) { return expr && expr[0] == '!'; } @@ -821,12 +723,10 @@ namespace Catch // #included from: catch_evaluate.hpp -namespace Catch -{ -namespace Internal -{ - enum Operator - { +namespace Catch { +namespace Internal { + + enum Operator { IsEqualTo, IsNotEqualTo, IsLessThan, @@ -862,157 +762,126 @@ namespace Internal class Evaluator{}; template<typename T1, typename T2> - struct Evaluator<T1, T2, IsEqualTo> - { - static bool evaluate( const T1& lhs, const T2& rhs) - { + struct Evaluator<T1, T2, IsEqualTo> { + static bool evaluate( const T1& lhs, const T2& rhs) { return const_cast<T1&>( lhs ) == const_cast<T2&>( rhs ); } }; template<typename T1, typename T2> - struct Evaluator<T1, T2, IsNotEqualTo> - { - static bool evaluate( const T1& lhs, const T2& rhs ) - { + struct Evaluator<T1, T2, IsNotEqualTo> { + static bool evaluate( const T1& lhs, const T2& rhs ) { return const_cast<T1&>( lhs ) != const_cast<T2&>( rhs ); } }; template<typename T1, typename T2> - struct Evaluator<T1, T2, IsLessThan> - { - static bool evaluate( const T1& lhs, const T2& rhs ) - { + struct Evaluator<T1, T2, IsLessThan> { + static bool evaluate( const T1& lhs, const T2& rhs ) { return const_cast<T1&>( lhs ) < const_cast<T2&>( rhs ); } }; template<typename T1, typename T2> - struct Evaluator<T1, T2, IsGreaterThan> - { - static bool evaluate( const T1& lhs, const T2& rhs ) - { + struct Evaluator<T1, T2, IsGreaterThan> { + static bool evaluate( const T1& lhs, const T2& rhs ) { return const_cast<T1&>( lhs ) > const_cast<T2&>( rhs ); } }; template<typename T1, typename T2> - struct Evaluator<T1, T2, IsGreaterThanOrEqualTo> - { - static bool evaluate( const T1& lhs, const T2& rhs ) - { + struct Evaluator<T1, T2, IsGreaterThanOrEqualTo> { + static bool evaluate( const T1& lhs, const T2& rhs ) { return const_cast<T1&>( lhs ) >= const_cast<T2&>( rhs ); } }; template<typename T1, typename T2> - struct Evaluator<T1, T2, IsLessThanOrEqualTo> - { - static bool evaluate( const T1& lhs, const T2& rhs ) - { + struct Evaluator<T1, T2, IsLessThanOrEqualTo> { + static bool evaluate( const T1& lhs, const T2& rhs ) { return const_cast<T1&>( lhs ) <= const_cast<T2&>( rhs ); } }; template<Operator Op, typename T1, typename T2> - bool applyEvaluator( const T1& lhs, const T2& rhs ) - { + bool applyEvaluator( const T1& lhs, const T2& rhs ) { return Evaluator<T1, T2, Op>::evaluate( lhs, rhs ); } // "base" overload template<Operator Op, typename T1, typename T2> - bool compare( const T1& lhs, const T2& rhs ) - { + bool compare( const T1& lhs, const T2& rhs ) { return Evaluator<T1, T2, Op>::evaluate( lhs, rhs ); } // unsigned X to int - template<Operator Op> bool compare( unsigned int lhs, int rhs ) - { + template<Operator Op> bool compare( unsigned int lhs, int rhs ) { return applyEvaluator<Op>( lhs, static_cast<unsigned int>( rhs ) ); } - template<Operator Op> bool compare( unsigned long lhs, int rhs ) - { + template<Operator Op> bool compare( unsigned long lhs, int rhs ) { return applyEvaluator<Op>( lhs, static_cast<unsigned int>( rhs ) ); } - template<Operator Op> bool compare( unsigned char lhs, int rhs ) - { + template<Operator Op> bool compare( unsigned char lhs, int rhs ) { return applyEvaluator<Op>( lhs, static_cast<unsigned int>( rhs ) ); } // unsigned X to long - template<Operator Op> bool compare( unsigned int lhs, long rhs ) - { + template<Operator Op> bool compare( unsigned int lhs, long rhs ) { return applyEvaluator<Op>( lhs, static_cast<unsigned long>( rhs ) ); } - template<Operator Op> bool compare( unsigned long lhs, long rhs ) - { + template<Operator Op> bool compare( unsigned long lhs, long rhs ) { return applyEvaluator<Op>( lhs, static_cast<unsigned long>( rhs ) ); } - template<Operator Op> bool compare( unsigned char lhs, long rhs ) - { + template<Operator Op> bool compare( unsigned char lhs, long rhs ) { return applyEvaluator<Op>( lhs, static_cast<unsigned long>( rhs ) ); } // int to unsigned X - template<Operator Op> bool compare( int lhs, unsigned int rhs ) - { + template<Operator Op> bool compare( int lhs, unsigned int rhs ) { return applyEvaluator<Op>( static_cast<unsigned int>( lhs ), rhs ); } - template<Operator Op> bool compare( int lhs, unsigned long rhs ) - { + template<Operator Op> bool compare( int lhs, unsigned long rhs ) { return applyEvaluator<Op>( static_cast<unsigned int>( lhs ), rhs ); } - template<Operator Op> bool compare( int lhs, unsigned char rhs ) - { + template<Operator Op> bool compare( int lhs, unsigned char rhs ) { return applyEvaluator<Op>( static_cast<unsigned int>( lhs ), rhs ); } // long to unsigned X - template<Operator Op> bool compare( long lhs, unsigned int rhs ) - { + template<Operator Op> bool compare( long lhs, unsigned int rhs ) { return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs ); } - template<Operator Op> bool compare( long lhs, unsigned long rhs ) - { + template<Operator Op> bool compare( long lhs, unsigned long rhs ) { return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs ); } - template<Operator Op> bool compare( long lhs, unsigned char rhs ) - { + template<Operator Op> bool compare( long lhs, unsigned char rhs ) { return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs ); } template<Operator Op, typename T> - bool compare( long lhs, const T* rhs ) - { + bool compare( long lhs, const T* rhs ) { return Evaluator<const T*, const T*, Op>::evaluate( reinterpret_cast<const T*>( lhs ), rhs ); } template<Operator Op, typename T> - bool compare( long lhs, T* rhs ) - { + bool compare( long lhs, T* rhs ) { return Evaluator<T*, T*, Op>::evaluate( reinterpret_cast<T*>( lhs ), rhs ); } template<Operator Op, typename T> - bool compare( const T* lhs, long rhs ) - { + bool compare( const T* lhs, long rhs ) { return Evaluator<const T*, const T*, Op>::evaluate( lhs, reinterpret_cast<const T*>( rhs ) ); } template<Operator Op, typename T> - bool compare( T* lhs, long rhs ) - { + bool compare( T* lhs, long rhs ) { return Evaluator<T*, T*, Op>::evaluate( lhs, reinterpret_cast<T*>( rhs ) ); } } // end of namespace Internal } // end of namespace Catch -namespace Catch -{ +namespace Catch { struct STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison; -class ResultInfoBuilder : public ResultInfo -{ +class ResultInfoBuilder : public ResultInfo { + public: ResultInfoBuilder() {} @@ -1068,7 +937,7 @@ public: ); private: - friend class ResultBuilder; + friend class ExpressionBuilder; template<typename T> friend class Expression; template<typename T> friend class PtrExpression; @@ -1097,12 +966,10 @@ private: } // end namespace Catch -namespace Catch -{ +namespace Catch { template<typename T> -class Expression -{ +class Expression { void operator = ( const Expression& ); public: @@ -1165,8 +1032,7 @@ private: }; template<typename LhsT> -class PtrExpression -{ +class PtrExpression { public: PtrExpression ( ResultInfoBuilder& result, const LhsT* lhs ) @@ -1205,63 +1071,132 @@ private: } // end namespace Catch +#include <sstream> + +namespace Catch { + +class ExpressionBuilder { +public: + + ExpressionBuilder( const SourceLineInfo& lineInfo, + const char* macroName, + const char* expr = "", + bool isNot = false ) + : m_result( expr, isNot, lineInfo, macroName ), + m_messageStream() + {} + + template<typename T> + Expression<const T&> operator->* ( const T & operand ) { + Expression<const T&> expr( m_result, operand ); + return expr; + } + + Expression<const char*> operator->* ( const char* const& operand ) { + Expression<const char*> expr( m_result, operand ); + return expr; + } + + template<typename T> + PtrExpression<T> operator->* ( const T* operand ) { + PtrExpression<T> expr( m_result, operand ); + return expr; + } + + template<typename T> + PtrExpression<T> operator->* ( T* operand ) { + PtrExpression<T> expr( m_result, operand ); + return expr; + } + + Expression<bool> operator->* ( bool value ) { + Expression<bool> expr( m_result, value ); + return expr; + } + + template<typename T> + ExpressionBuilder& operator << ( const T & value ) { + m_messageStream << Catch::toString( value ); + return *this; + } + + template<typename MatcherT, typename ArgT> + ExpressionBuilder& acceptMatcher( const MatcherT& matcher, + const ArgT& arg, + const std::string& matcherCallAsString ) { + std::string matcherAsString = Catch::toString( matcher ); + if( matcherAsString == "{?}" ) + matcherAsString = matcherCallAsString; + m_result.setLhs( Catch::toString( arg ) ); + m_result.setRhs( matcherAsString ); + m_result.setOp( "matches" ); + m_result.setResultType( matcher( arg ) ? ResultWas::Ok : ResultWas::ExpressionFailed ); + return *this; + } + + template<typename MatcherT, typename ArgT> + ExpressionBuilder& acceptMatcher( const MatcherT& matcher, + ArgT* arg, + const std::string& matcherCallAsString ) { + std::string matcherAsString = Catch::toString( matcher ); + if( matcherAsString == "{?}" ) + matcherAsString = matcherCallAsString; + m_result.setLhs( Catch::toString( arg ) ); + m_result.setRhs( matcherAsString ); + m_result.setOp( "matches" ); + m_result.setResultType( matcher( arg ) ? ResultWas::Ok : ResultWas::ExpressionFailed ); + return *this; + } + + ExpressionBuilder& setResultType( ResultWas::OfType resultType ) { + m_result.setResultType( resultType ); + return *this; + } + + operator ResultInfoBuilder&() { + m_result.setMessage( m_messageStream.str() ); + return m_result; + } + +private: + ResultInfoBuilder m_result; + std::ostringstream m_messageStream; +}; + +} // end namespace Catch + // #included from: catch_interfaces_capture.h #include <string> -namespace Catch -{ +namespace Catch { + class TestCaseInfo; class ScopedInfo; class ResultInfoBuilder; class ResultInfo; - struct IResultCapture - { - virtual ~IResultCapture - () - {} + struct IResultCapture { + + virtual ~IResultCapture(){} + + virtual void testEnded( const ResultInfo& result ) = 0; + virtual bool sectionStarted( const std::string& name, + const std::string& description, + const SourceLineInfo& lineInfo, + Counts& assertions ) = 0; + virtual void sectionEnded( const std::string& name, const Counts& assertions ) = 0; + virtual void pushScopedInfo( ScopedInfo* scopedInfo ) = 0; + virtual void popScopedInfo( ScopedInfo* scopedInfo ) = 0; + virtual bool shouldDebugBreak() const = 0; - virtual void testEnded - ( const ResultInfo& result - ) = 0; - virtual bool sectionStarted - ( const std::string& name, - const std::string& description, - const SourceLineInfo& lineInfo, - Counts& assertions - ) = 0; - virtual void sectionEnded - ( const std::string& name, - const Counts& assertions - ) = 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 ResultAction::Value acceptExpression - ( const ResultInfoBuilder& resultInfo - ) = 0; - virtual void acceptMessage - ( const std::string& msg - ) = 0; - - virtual std::string getCurrentTestName - () const = 0; - virtual const ResultInfo* getLastResult - () const = 0; + virtual ResultAction::Value acceptResult( bool result ) = 0; + virtual ResultAction::Value acceptResult( ResultWas::OfType result ) = 0; + virtual ResultAction::Value acceptExpression( const ResultInfoBuilder& resultInfo ) = 0; + virtual void acceptMessage( const std::string& msg ) = 0; + virtual std::string getCurrentTestName() const = 0; + virtual const ResultInfo* getLastResult() const = 0; }; } @@ -1285,15 +1220,15 @@ namespace Catch #include <unistd.h> #include <sys/sysctl.h> - namespace Catch - { + namespace Catch{ + // The following function is taken directly from the following technical note: // http://developer.apple.com/library/mac/#qa/qa2004/qa1361.html - inline bool isDebuggerActive() // Returns true if the current process is being debugged (either // running under the debugger or has a debugger attached post facto). - { + inline bool isDebuggerActive(){ + int junk; int mib[4]; struct kinfo_proc info; @@ -1329,8 +1264,7 @@ namespace Catch #ifdef DEBUG #if defined(__ppc64__) || defined(__ppc__) #define BreakIntoDebugger() \ - if( Catch::isDebuggerActive() ) \ - { \ + if( Catch::isDebuggerActive() ) { \ __asm__("li r0, 20\nsc\nnop\nli r0, 37\nli r4, 2\nsc\nnop\n" \ : : : "memory","r0","r3","r4" ); \ } @@ -1344,16 +1278,14 @@ namespace Catch #elif defined(_MSC_VER) extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent(); #define BreakIntoDebugger() if (IsDebuggerPresent() ) { __debugbreak(); } - inline bool isDebuggerActive() - { + inline bool isDebuggerActive() { return IsDebuggerPresent() != 0; } #elif defined(__MINGW32__) extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent(); extern "C" __declspec(dllimport) void __stdcall DebugBreak(); #define BreakIntoDebugger() if (IsDebuggerPresent() ) { DebugBreak(); } - inline bool isDebuggerActive() - { + inline bool isDebuggerActive() { return IsDebuggerPresent() != 0; } #else @@ -1363,174 +1295,23 @@ namespace Catch #ifdef CATCH_PLATFORM_WINDOWS extern "C" __declspec(dllimport) void __stdcall OutputDebugStringA( const char* ); -inline void writeToDebugConsole( const std::string& text ) -{ +inline void writeToDebugConsole( const std::string& text ) { ::OutputDebugStringA( text.c_str() ); } #else -inline void writeToDebugConsole( const std::string& text ) -{ +inline void writeToDebugConsole( const std::string& text ) { // !TBD: Need a version for Mac/ XCode and other IDEs std::cout << text; } #endif // CATCH_PLATFORM_WINDOWS -#include <sstream> +#include <ostream> -namespace Catch -{ +namespace Catch { struct TestFailureException{}; -struct DummyExceptionType_DontUse{}; -class ResultBuilder -{ -public: - - /////////////////////////////////////////////////////////////////////////// - ResultBuilder - ( - const SourceLineInfo& lineInfo, - const char* macroName, - const char* expr = "", - bool isNot = false - ) - : m_result( expr, isNot, lineInfo, macroName ), - m_messageStream() - {} - - /////////////////////////////////////////////////////////////////////////// - template<typename T> - Expression<const T&> operator->* - ( - const T & operand - ) - { - Expression<const T&> expr( m_result, operand ); - - return expr; - } - - /////////////////////////////////////////////////////////////////////////// - Expression<const char*> operator->* - ( - const char* const& operand - ) - { - Expression<const char*> expr( m_result, operand ); - - return expr; - } - - /////////////////////////////////////////////////////////////////////////// - template<typename T> - PtrExpression<T> operator->* - ( - const T* operand - ) - { - PtrExpression<T> expr( m_result, operand ); - - return expr; - } - - /////////////////////////////////////////////////////////////////////////// - template<typename T> - PtrExpression<T> operator->* - ( - T* operand - ) - { - PtrExpression<T> expr( m_result, operand ); - - return expr; - } - - /////////////////////////////////////////////////////////////////////////// - Expression<bool> operator->* - ( - bool value - ) - { - Expression<bool> expr( m_result, value ); - return expr; - } - - /////////////////////////////////////////////////////////////////////////// - template<typename T> - ResultBuilder& operator << - ( - const T & value - ) - { - m_messageStream << Catch::toString( value ); - return *this; - } - - /////////////////////////////////////////////////////////////////////////// - template<typename MatcherT, typename ArgT> - ResultBuilder& acceptMatcher - ( - const MatcherT& matcher, - const ArgT& arg, - const std::string& matcherCallAsString - ) - { - std::string matcherAsString = Catch::toString( matcher ); - if( matcherAsString == "{?}" ) - matcherAsString = matcherCallAsString; |