catch3
Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.
Clonegit clone https://git.progmasoft.com/catch3
Regenerated single include
- Commit
82acc2ca05459ce353de71469f141ba93e9b63cf- Author
- Phil Nash ·
- Parents
fe1d7c1d08f0
Changes
single_include/catch.hpp | 2361 +++++++++++++++++++++++----------------------- 1 file changed, 1182 insertions(+), 1179 deletions(-) diff --git a/single_include/catch.hpp b/single_include/catch.hpp index 32309c2f..96e87228 100644 --- a/single_include/catch.hpp +++ b/single_include/catch.hpp @@ -1,5 +1,5 @@ /* - * Generated: 2012-10-12 18:39:11.086583 + * Generated: 2012-10-28 12:06:53.944416 * ---------------------------------------------------------- * This file has been merged from multiple headers. Please don't edit it directly * Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved. @@ -139,6 +139,9 @@ namespace Catch { file.swap( other.file ); std::swap( line, other.line ); } + bool empty() const { + return file.empty(); + } std::string function; std::string file; @@ -445,14 +448,14 @@ private: // #included from: internal/catch_capture.hpp #define TWOBLUECUBES_CATCH_CAPTURE_HPP_INCLUDED -// #included from: catch_expression_builder.hpp -#define TWOBLUECUBES_CATCH_EXPRESSION_BUILDER_HPP_INCLUDED +// #included from: catch_expression_decomposer.hpp +#define TWOBLUECUBES_CATCH_EXPRESSION_DECOMPOSER_HPP_INCLUDED -// #included from: catch_expression.hpp -#define TWOBLUECUBES_CATCH_EXPRESSION_HPP_INCLUDED +// #included from: catch_expression_lhs.hpp +#define TWOBLUECUBES_CATCH_EXPRESSION_LHS_HPP_INCLUDED -// #included from: catch_resultinfo_builder.h -#define TWOBLUECUBES_CATCH_RESULTINFO_BUILDER_H_INCLUDED +// #included from: catch_expressionresult_builder.h +#define TWOBLUECUBES_CATCH_ASSERTIONRESULT_BUILDER_H_INCLUDED // #included from: catch_tostring.hpp #define TWOBLUECUBES_CATCH_TOSTRING_HPP_INCLUDED @@ -639,8 +642,8 @@ inline std::string toString( std::nullptr_t ) { } // end namespace Catch -// #included from: catch_resultinfo.h -#define TWOBLUECUBES_CATCH_RESULTINFO_H_INCLUDED +// #included from: catch_assertionresult.h +#define TWOBLUECUBES_CATCH_ASSERTIONRESULT_H_INCLUDED #include <string> // #included from: catch_result_type.h @@ -682,23 +685,37 @@ struct ResultAction { enum Value { namespace Catch { - struct ResultData + struct AssertionInfo { - ResultData() : resultType( ResultWas::Unknown ) {} + AssertionInfo() {} + AssertionInfo( const std::string& _macroName, const SourceLineInfo& _lineInfo, const std::string& _capturedExpression, bool _shouldNegate ) + : macroName( _macroName ), + lineInfo( _lineInfo ), + capturedExpression( _capturedExpression ) + { + if( _shouldNegate ) + capturedExpression = "!" + _capturedExpression; + } std::string macroName; SourceLineInfo lineInfo; std::string capturedExpression; + }; + + struct AssertionResultData + { + AssertionResultData() : resultType( ResultWas::Unknown ) {} + std::string reconstructedExpression; std::string message; ResultWas::OfType resultType; }; - class ResultInfo { + class AssertionResult { public: - ResultInfo(); - ResultInfo( const ResultData& data ); - ~ResultInfo(); + AssertionResult(); + AssertionResult( const AssertionInfo& info, const AssertionResultData& data ); + ~AssertionResult(); bool ok() const; ResultWas::OfType getResultType() const; @@ -708,12 +725,12 @@ namespace Catch { bool hasExpandedExpression() const; std::string getExpandedExpression() const; std::string getMessage() const; - std::string getFilename() const; - std::size_t getLine() const; + SourceLineInfo getSourceInfo() const; std::string getTestMacroName() const; protected: - ResultData m_data; + AssertionInfo m_info; + AssertionResultData m_resultData; }; } // end namespace Catch @@ -885,201 +902,145 @@ namespace Internal { namespace Catch { -struct STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison; - -class ResultInfoBuilder { +// Wraps the (stringised versions of) the lhs, operator and rhs of an expression - as well as +// the result of evaluating it. This is used to build an AssertionResult object +class ExpressionResultBuilder { public: - ResultInfoBuilder(); + ExpressionResultBuilder( ResultWas::OfType resultType = ResultWas::Unknown ); + ExpressionResultBuilder( const ExpressionResultBuilder& other ); + ExpressionResultBuilder& operator=(const ExpressionResultBuilder& other ); - ResultInfoBuilder& setResultType( ResultWas::OfType result ); - ResultInfoBuilder& setCapturedExpression( const std::string& capturedExpression ); - ResultInfoBuilder& setIsFalse( bool isFalse ); - ResultInfoBuilder& setMessage( const std::string& message ); - ResultInfoBuilder& setLineInfo( const SourceLineInfo& lineInfo ); - ResultInfoBuilder& setLhs( const std::string& lhs ); - ResultInfoBuilder& setRhs( const std::string& rhs ); - ResultInfoBuilder& setOp( const std::string& op ); - ResultInfoBuilder& setMacroName( const std::string& macroName ); + ExpressionResultBuilder& setResultType( ResultWas::OfType result ); + ExpressionResultBuilder& setResultType( bool result ); + ExpressionResultBuilder& setLhs( const std::string& lhs ); + ExpressionResultBuilder& setRhs( const std::string& rhs ); + ExpressionResultBuilder& setOp( const std::string& op ); - std::string reconstructExpression() const; + ExpressionResultBuilder& negate( bool shouldNegate ); - ResultInfo build() const; + template<typename T> + ExpressionResultBuilder& operator << ( const T& value ) { + m_stream << value; + return *this; + } - // Disable attempts to use || and && in expressions (without parantheses) - template<typename RhsT> - STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator || ( const RhsT& ); - template<typename RhsT> - STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator && ( const RhsT& ); + std::string reconstructExpression( const AssertionInfo& info ) const; - bool getIsFalse() const { - return m_isFalse; - } + AssertionResult buildResult( const AssertionInfo& info ) const; private: - ResultData m_data; - std::string m_lhs, m_rhs, m_op; - bool m_isFalse; + AssertionResultData m_data; + struct ExprComponents { + ExprComponents() : shouldNegate( false ) {} + bool shouldNegate; + std::string lhs, rhs, op; + } m_exprComponents; + std::ostringstream m_stream; }; } // end namespace Catch namespace Catch { + struct STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison; + + template<typename T> + inline void setResultIfBoolean( ExpressionResultBuilder&, const T& ) {} + inline void setResultIfBoolean( ExpressionResultBuilder& result, bool value ) { + result.setResultType( value ); + } + +// Wraps the LHS of an expression and captures the operator and RHS (if any) - wrapping them all +// in an ExpressionResultBuilder object template<typename T> -class Expression { - void operator = ( const Expression& ); +class ExpressionLhs { + void operator = ( const ExpressionLhs& ); public: - Expression( ResultInfoBuilder& result, T lhs ) - : m_result( result.setLhs( Catch::toString( lhs ) ) ), - m_lhs( lhs ) - {} + ExpressionLhs( T lhs ) : m_lhs( lhs ) { + setResultIfBoolean( m_result.setLhs( Catch::toString( lhs ) ), lhs ); + } template<typename RhsT> - ResultInfoBuilder& operator == ( const RhsT& rhs ) { + ExpressionResultBuilder& operator == ( const RhsT& rhs ) { return captureExpression<Internal::IsEqualTo>( rhs ); } template<typename RhsT> - ResultInfoBuilder& operator != ( const RhsT& rhs ) { + ExpressionResultBuilder& operator != ( const RhsT& rhs ) { return captureExpression<Internal::IsNotEqualTo>( rhs ); } template<typename RhsT> - ResultInfoBuilder& operator < ( const RhsT& rhs ) { + ExpressionResultBuilder& operator < ( const RhsT& rhs ) { return captureExpression<Internal::IsLessThan>( rhs ); } template<typename RhsT> - ResultInfoBuilder& operator > ( const RhsT& rhs ) { + ExpressionResultBuilder& operator > ( const RhsT& rhs ) { return captureExpression<Internal::IsGreaterThan>( rhs ); } template<typename RhsT> - ResultInfoBuilder& operator <= ( const RhsT& rhs ) { + ExpressionResultBuilder& operator <= ( const RhsT& rhs ) { return captureExpression<Internal::IsLessThanOrEqualTo>( rhs ); } template<typename RhsT> - ResultInfoBuilder& operator >= ( const RhsT& rhs ) { + ExpressionResultBuilder& operator >= ( const RhsT& rhs ) { return captureExpression<Internal::IsGreaterThanOrEqualTo>( rhs ); } - ResultInfoBuilder& operator == ( bool rhs ) { + ExpressionResultBuilder& operator == ( bool rhs ) { return captureExpression<Internal::IsEqualTo>( rhs ); } - ResultInfoBuilder& operator != ( bool rhs ) { + ExpressionResultBuilder& operator != ( bool rhs ) { return captureExpression<Internal::IsNotEqualTo>( rhs ); } - operator ResultInfoBuilder& () { - return m_result.setResultType( m_lhs ? ResultWas::Ok : ResultWas::ExpressionFailed ); + ExpressionResultBuilder& negate( bool shouldNegate ) { + return m_result.negate( shouldNegate ); } - template<typename RhsT> - STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator + ( const RhsT& ); - - template<typename RhsT> - STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator - ( const RhsT& ); + // Only simple binary expressions are allowed on the LHS. + // If more complex compositions are required then place the sub expression in parentheses + template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator + ( const RhsT& ); + template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator - ( const RhsT& ); + template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator / ( const RhsT& ); + template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator * ( const RhsT& ); private: template<Internal::Operator Op, typename RhsT> - ResultInfoBuilder& captureExpression( const RhsT& rhs ) { + ExpressionResultBuilder& captureExpression( const RhsT& rhs ) { return m_result - .setResultType( Internal::compare<Op>( m_lhs, rhs ) ? ResultWas::Ok : ResultWas::ExpressionFailed ) + .setResultType( Internal::compare<Op>( m_lhs, rhs ) ) .setRhs( Catch::toString( rhs ) ) .setOp( Internal::OperatorTraits<Op>::getName() ); } private: - ResultInfoBuilder& m_result; + ExpressionResultBuilder m_result; T m_lhs; }; } // end namespace Catch -#include <sstream> - namespace Catch { -class ExpressionBuilder { +// Captures the LHS of the expression and wraps it in an Expression Lhs object +class ExpressionDecomposer { public: - ExpressionBuilder( const SourceLineInfo& lineInfo, - const char* macroName, - const char* expr = "", - bool isFalse = false ) - : m_messageStream() - { - m_result - .setCapturedExpression( expr ) - .setIsFalse( isFalse ) - .setLineInfo( lineInfo ) - .setMacroName( macroName ); - } - - template<typename T> - Expression<const T&> operator->* ( const T & operand ) { - Expression<const 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 = matcher.toString(); - if( matcherAsString == "{?}" ) - matcherAsString = matcherCallAsString; - m_result - .setLhs( Catch::toString( arg ) ) - .setRhs( matcherAsString ) - .setOp( "matches" ) - .setResultType( matcher.match( 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 = matcher.toString(); - if( matcherAsString == "{?}" ) - matcherAsString = matcherCallAsString; - m_result - .setLhs( Catch::toString( arg ) ) - .setRhs( matcherAsString ) - .setOp( "matches" ) - .setResultType( matcher.match( arg ) ? ResultWas::Ok : ResultWas::ExpressionFailed ); - return *this; - } - - ExpressionBuilder& setResultType( ResultWas::OfType resultType ) { - m_result.setResultType( resultType ); - return *this; + ExpressionLhs<const T&> operator->* ( const T & operand ) { + return ExpressionLhs<const T&>( operand ); } - operator ResultInfoBuilder&() { - m_result.setMessage( m_messageStream.str() ); - return m_result; + ExpressionLhs<bool> operator->* ( bool value ) { + return ExpressionLhs<bool>( value ); } - -private: - ResultInfoBuilder m_result; - std::ostringstream m_messageStream; }; } // end namespace Catch @@ -1152,14 +1113,15 @@ namespace Catch { class TestCaseInfo; class ScopedInfo; - class ResultInfoBuilder; - class ResultInfo; + class ExpressionResultBuilder; + class AssertionResult; + struct AssertionInfo; struct IResultCapture { virtual ~IResultCapture(); - virtual void testEnded( const ResultInfo& result ) = 0; + virtual void testEnded( const AssertionResult& result ) = 0; virtual bool sectionStarted( const std::string& name, const std::string& description, const SourceLineInfo& lineInfo, @@ -1169,13 +1131,11 @@ namespace Catch { 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 void acceptAssertionInfo( const AssertionInfo& assertionInfo ) = 0; + virtual ResultAction::Value acceptExpression( const ExpressionResultBuilder& assertionResult ) = 0; virtual std::string getCurrentTestName() const = 0; - virtual const ResultInfo* getLastResult() const = 0; + virtual const AssertionResult* getLastResult() const = 0; }; } @@ -1285,1102 +1245,1153 @@ inline void writeToDebugConsole( const std::string& text ) { } #endif // CATCH_PLATFORM_WINDOWS -#include <ostream> - -namespace Catch { - -struct TestFailureException{}; +// #included from: catch_interfaces_registry_hub.h +#define TWOBLUECUBES_CATCH_INTERFACES_REGISTRY_HUB_H_INCLUDED -class ScopedInfo { -public: - ScopedInfo() : m_oss() { - getCurrentContext().getResultCapture().pushScopedInfo( this ); - } +// #included from: catch_interfaces_reporter.h +#define TWOBLUECUBES_CATCH_INTERFACES_REPORTER_H_INCLUDED - ~ScopedInfo() { - getCurrentContext().getResultCapture().popScopedInfo( this ); - } +// #included from: catch_config.hpp +#define TWOBLUECUBES_CATCH_CONFIG_HPP_INCLUDED - template<typename T> - ScopedInfo& operator << ( const T& value ) { - m_oss << value; - return *this; - } +// #included from: catch_test_spec.h +#define TWOBLUECUBES_CATCH_TEST_SPEC_H_INCLUDED - ResultInfo getInfo () const { - return ResultInfoBuilder() - .setResultType( ResultWas::Info ) - .setMessage( m_oss.str() ) - .setMacroName( "SCOPED_INFO" ) - .build(); - } +// #included from: catch_test_case_info.h +#define TWOBLUECUBES_CATCH_TEST_CASE_INFO_H_INCLUDED -private: - std::ostringstream m_oss; -}; +#include <string> +#include <set> -// This is just here to avoid compiler warnings with macro constants -inline bool isTrue( bool value ){ return value; } +namespace Catch { -} // end namespace Catch + struct ITestCase; -/////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CATCH_ACCEPT_EXPR( expr, stopOnFailure, originalExpr ) \ - if( Catch::ResultAction::Value internal_catch_action = Catch::getCurrentContext().getResultCapture().acceptExpression( expr ) ) { \ - if( internal_catch_action & Catch::ResultAction::Debug ) BreakIntoDebugger(); \ - if( internal_catch_action & Catch::ResultAction::Abort ) throw Catch::TestFailureException(); \ - if( Catch::isTrue( stopOnFailure ) ) throw Catch::TestFailureException(); \ - if( Catch::isTrue( false ) ){ bool this_is_here_to_invoke_warnings = ( originalExpr ); Catch::isTrue( this_is_here_to_invoke_warnings ); } \ - } + class TestCaseInfo { + public: + TestCaseInfo(); -/////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CATCH_TEST( expr, isFalse, stopOnFailure, macroName ) \ - do { try { \ - INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr, isFalse )->*expr ), stopOnFailure, expr ); \ - } catch( Catch::TestFailureException& ) { \ - throw; \ - } catch( ... ) { \ - INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr ) << Catch::getRegistryHub().getExceptionTranslatorRegistry().translateActiveException() ).setResultType( Catch::ResultWas::ThrewException ), false, expr ); \ - throw; \ - } } while( Catch::isTrue( false ) ) + TestCaseInfo( ITestCase* testCase, + const char* name, + const char* description, + const SourceLineInfo& lineInfo ); -/////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CATCH_IF( expr, isFalse, stopOnFailure, macroName ) \ - INTERNAL_CATCH_TEST( expr, isFalse, stopOnFailure, macroName ); \ - if( Catch::getCurrentContext().getResultCapture().getLastResult()->ok() ) + TestCaseInfo( const TestCaseInfo& other, const std::string& name ); + TestCaseInfo( const TestCaseInfo& other ); -/////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CATCH_ELSE( expr, isFalse, stopOnFailure, macroName ) \ - INTERNAL_CATCH_TEST( expr, isFalse, stopOnFailure, macroName ); \ - if( !Catch::getCurrentContext().getResultCapture().getLastResult()->ok() ) + void invoke() const; + const std::string& getName() const; + const std::string& getDescription() const; + const SourceLineInfo& getLineInfo() const; + bool isHidden() const; + bool hasTag( const std::string& tag ) const; + bool matchesTags( const std::string& tagPattern ) const; + const std::set<std::string>& getTags() const; -/////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CATCH_NO_THROW( expr, stopOnFailure, macroName ) \ - try { \ - expr; \ - 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::getRegistryHub().getExceptionTranslatorRegistry().translateActiveException() ).setResultType( Catch::ResultWas::ThrewException ), stopOnFailure, false ); \ - } + void swap( TestCaseInfo& other ); + bool operator == ( const TestCaseInfo& other ) const; + bool operator < ( const TestCaseInfo& other ) const; + TestCaseInfo& operator = ( const TestCaseInfo& other ); -/////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CATCH_THROWS( expr, exceptionType, stopOnFailure, macroName ) \ - try { \ - if( Catch::getCurrentContext().getConfig()->allowThrows() ) { \ - expr; \ - INTERNAL_CATCH_ACCEPT_EXPR( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr ).setResultType( Catch::ResultWas::DidntThrowException ), stopOnFailure, false ); \ - } \ - } \ - catch( Catch::TestFailureException& ) { \ - throw; \ - } \ - catch( exceptionType ) { \ - INTERNAL_CATCH_ACCEPT_EXPR( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr ).setResultType( Catch::ResultWas::Ok ), stopOnFailure, false ); \ - } + private: + Ptr<ITestCase> m_test; + std::string m_name; + std::string m_description; + std::set<std::string> m_tags; + SourceLineInfo m_lineInfo; + bool m_isHidden; + }; +} -/////////////////////////////////////////////////////////////////////////////// -#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::getRegistryHub().getExceptionTranslatorRegistry() ).setResultType( Catch::ResultWas::ThrewException ), stopOnFailure, false ); \ - } +// #included from: catch_tags.hpp +#define TWOBLUECUBES_CATCH_TAGS_HPP_INCLUDED -/////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CATCH_MSG( reason, resultType, stopOnFailure, macroName ) \ - Catch::getCurrentContext().getResultCapture().acceptExpression( ( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName ) << reason ).setResultType( resultType ) ); +#include <string> +#include <set> +#include <map> +#include <vector> -/////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CATCH_SCOPED_INFO( log ) \ - Catch::ScopedInfo INTERNAL_CATCH_UNIQUE_NAME( info ); \ - INTERNAL_CATCH_UNIQUE_NAME( info ) << log +#ifdef __clang__ +#pragma clang diagnostic ignored "-Wpadded" +#endif -/////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CHECK_THAT( arg, matcher, stopOnFailure, macroName ) \ - do { try { \ - INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName, #arg " " #matcher, false ).acceptMatcher( ::Catch::Matchers::matcher, arg, #matcher ) ), stopOnFailure, false ); \ - } catch( Catch::TestFailureException& ) { \ - throw; \ - } catch( ... ) { \ - INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName, #arg " " #matcher ) << Catch::getRegistryHub().getExceptionTranslatorRegistry().translateActiveException() ).setResultType( Catch::ResultWas::ThrewException ), false, false ); \ - throw; \ - }}while( Catch::isTrue( false ) ) +namespace Catch { + class TagParser { + public: + virtual ~TagParser(); -// #included from: internal/catch_section.hpp -#define TWOBLUECUBES_CATCH_SECTION_HPP_INCLUDED + void parse( const std::string& str ) { + std::size_t pos = 0; + while( pos < str.size() ) { + char c = str[pos]; + if( c == '[' ) { + std::size_t end = str.find_first_of( ']', pos ); + if( end != std::string::npos ) { + acceptTag( str.substr( pos+1, end-pos-1 ) ); + pos = end+1; + } + else { + acceptChar( c ); + pos++; + } + } + else { + acceptChar( c ); + pos++; + } + } + endParse(); + } -#include <string> + protected: + virtual void acceptTag( const std::string& tag ) = 0; + virtual void acceptChar( char c ) = 0; + virtual void endParse() {} -namespace Catch { + private: + }; - class Section { + class TagExtracter : public TagParser { public: - Section( const std::string& name, - const std::string& description, - const SourceLineInfo& lineInfo ) - : m_name( name ), - m_sectionIncluded( getCurrentContext().getResultCapture().sectionStarted( name, description, lineInfo, m_assertions ) ) - {} - ~Section() { - if( m_sectionIncluded ) - getCurrentContext().getResultCapture().sectionEnded( m_name, m_assertions ); - } + TagExtracter( std::set<std::string>& tags ) + : m_tags( tags ) + {} + virtual ~TagExtracter(); - // This indicates whether the section should be executed or not - operator bool() { - return m_sectionIncluded; + void parse( std::string& description ) { + TagParser::parse( description ); + description = m_remainder; } private: + virtual void acceptTag( const std::string& tag ) { + m_tags.insert( tag ); + } + virtual void acceptChar( char c ) { + m_remainder += c; + } - std::string m_name; - Counts m_assertions; - bool m_sectionIncluded; + std::set<std::string>& m_tags; + std::string m_remainder; }; -} // end namespace Catch - -#define INTERNAL_CATCH_SECTION( name, desc ) \ - if( Catch::Section INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::Section( name, desc, CATCH_INTERNAL_LINEINFO ) ) - -// #included from: internal/catch_generators.hpp -#define TWOBLUECUBES_CATCH_GENERATORS_HPP_INCLUDED - -#include <iterator> -#include <vector> -#include <string> -#include <stdlib.h> - -namespace Catch { + class Tag { + public: + Tag() + : m_isNegated( false ) + {} -template<typename T> -struct IGenerator { - virtual ~IGenerator() {} - virtual T getValue( std::size_t index ) const = 0; - virtual std::size_t size () const = 0; -}; + Tag( const std::string& name, bool isNegated ) + : m_name( name ), + m_isNegated( isNegated ) + {} -template<typename T> -class BetweenGenerator : public IGenerator<T> { -public: - BetweenGenerator( T from, T to ) : m_from( from ), m_to( to ){} + std::string getName() const { + return m_name; + } + bool isNegated() const { + return m_isNegated; + } - virtual T getValue( std::size_t index ) const { - return m_from+static_cast<T>( index ); - } + bool operator ! () const { + return m_name.empty(); + } - virtual std::size_t size() const { - return static_cast<std::size_t>( 1+m_to-m_from ); - } + private: + std::string m_name; + bool m_isNegated; + }; -private: + class TagSet { + typedef std::map<std::string, Tag> TagMap; + public: + void add( const Tag& tag ) { + m_tags.insert( std::make_pair( tag.getName(), tag ) ); + } - T m_from; - T m_to; -}; + bool empty() const { + return m_tags.empty(); + } -template<typename T> -class ValuesGenerator : public IGenerator<T> { -public: - ValuesGenerator(){} + bool matches( const std::set<std::string>& tags ) const { + TagMap::const_iterator it = m_tags.begin(); + TagMap::const_iterator itEnd = m_tags.end(); + for(; it != itEnd; ++it ) { + bool found = tags.find( it->first ) != tags.end(); + if( found == it->second.isNegated() ) + return false; + } + return true; + } - void add( T value ) { - m_values.push_back( value ); - } + private: + TagMap m_tags; + }; - virtual T getValue( std::size_t index ) const { - return m_values[index]; - } + class TagExpression { + public: + bool matches( const std::set<std::string>& tags ) const { + std::vector<TagSet>::const_iterator it = m_tagSets.begin(); + std::vector<TagSet>::const_iterator itEnd = m_tagSets.end(); + for(; it != itEnd; ++it ) + if( it->matches( tags ) ) + return true; + return false; + } - virtual std::size_t size() const { - return m_values.size(); - } + private: + friend class TagExpressionParser; -private: - std::vector<T> m_values; -}; + std::vector<TagSet> m_tagSets; + }; -template<typename T> -class CompositeGenerator { -public: - CompositeGenerator() : m_totalSize( 0 ) {} + class TagExpressionParser : public TagParser { + public: + TagExpressionParser( TagExpression& exp ) + : m_isNegated( false ), + m_exp( exp ) + {} - // *** Move semantics, similar to auto_ptr *** - CompositeGenerator( CompositeGenerator& other ) - : m_fileInfo( other.m_fileInfo ), - m_totalSize( 0 ) - { - move( other ); - } + ~TagExpressionParser(); - CompositeGenerator& setFileInfo( const char* fileInfo ) { - m_fileInfo = fileInfo; - return *this; - } + private: + virtual void acceptTag( const std::string& tag ) { + m_currentTagSet.add( Tag( tag, m_isNegated ) ); + m_isNegated = false; + } + virtual void acceptChar( char c ) { + switch( c ) { + case '~': + m_isNegated = true; + break; + case ',': + m_exp.m_tagSets.push_back( m_currentTagSet ); + break; + } + } + virtual void endParse() { + if( !m_currentTagSet.empty() ) + m_exp.m_tagSets.push_back( m_currentTagSet ); + } - ~CompositeGenerator() { - deleteAll( m_composed ); - } + bool m_isNegated; + TagSet m_currentTagSet; + TagExpression& m_exp; + }; - operator T () const { - size_t overallIndex = getCurrentContext().getGeneratorIndex( m_fileInfo, m_totalSize ); +} // end namespace Catch - typename std::vector<const IGenerator<T>*>::const_iterator it = m_composed.begin(); - typename std::vector<const IGenerator<T>*>::const_iterator itEnd = m_composed.end(); - for( size_t index = 0; it != itEnd; ++it ) - { - const IGenerator<T>* generator = *it; - if( overallIndex >= index && overallIndex < index + generator->size() ) - { - return generator->getValue( overallIndex-index ); - } - index += generator->size(); - } - CATCH_INTERNAL_ERROR( "Indexed past end of generated range" ); - return T(); // Suppress spurious "not all control paths return a value" warning in Visual Studio - if you know how to fix this please do so - } +#include <string> +#include <vector> - void add( const IGenerator<T>* generator ) { - m_totalSize += generator->size(); - m_composed.push_back( generator ); - } +namespace Catch { - CompositeGenerator& then( CompositeGenerator& other ) { - move( other ); - return *this; - } + struct IfFilterMatches{ enum DoWhat { + AutoDetectBehaviour, + IncludeTests, + ExcludeTests + }; }; - CompositeGenerator& then( T value ) { - ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>(); - valuesGen->add( value ); - add( valuesGen ); - return *this; - } + class TestCaseFilter { + enum WildcardPosition { + NoWildcard = 0, + WildcardAtStart = 1, + WildcardAtEnd = 2, + WildcardAtBothEnds = WildcardAtStart | WildcardAtEnd + }; -private: + public: + TestCaseFilter( const std::string& testSpec, IfFilterMatches::DoWhat matchBehaviour = IfFilterMatches::AutoDetectBehaviour ) + : m_stringToMatch( testSpec ), + m_filterType( matchBehaviour ), + m_wildcardPosition( NoWildcard ) + { + if( m_filterType == IfFilterMatches::AutoDetectBehaviour ) { + if( startsWith( m_stringToMatch, "exclude:" ) ) { + m_stringToMatch = m_stringToMatch.substr( 8 ); + m_filterType = IfFilterMatches::ExcludeTests; + } + else if( startsWith( m_stringToMatch, "~" ) ) { + m_stringToMatch = m_stringToMatch.substr( 1 ); + m_filterType = IfFilterMatches::ExcludeTests; + } + else { + m_filterType = IfFilterMatches::IncludeTests; + } + } - void move( CompositeGenerator& other ) { - std::copy( other.m_composed.begin(), other.m_composed.end(), std::back_inserter( m_composed ) ); - m_totalSize += other.m_totalSize; - other.m_composed.clear(); - } + if( m_stringToMatch[0] == '*' ) { + m_stringToMatch = m_stringToMatch.substr( 1 ); + m_wildcardPosition = (WildcardPosition)( m_wildcardPosition | WildcardAtStart ); + } + if( m_stringToMatch[m_stringToMatch.size()-1] == '*' ) { + m_stringToMatch = m_stringToMatch.substr( 0, m_stringToMatch.size()-1 ); + m_wildcardPosition = (WildcardPosition)( m_wildcardPosition | WildcardAtEnd ); + } + } - std::vector<const IGenerator<T>*> m_composed; - std::string m_fileInfo; - size_t m_totalSize; -}; + IfFilterMatches::DoWhat getFilterType() const { + return m_filterType; + } -namespace Generators -{ - template<typename T> - CompositeGenerator<T> between( T from, T to ) { - CompositeGenerator<T> generators; - generators.add( new BetweenGenerator<T>( from, to ) ); - return generators; - } + bool shouldInclude( const TestCaseInfo& testCase ) const { + return isMatch( testCase ) == (m_filterType == IfFilterMatches::IncludeTests); + } + private: - template<typename T> - CompositeGenerator<T> values( T val1, T val2 ) { - CompositeGenerator<T> generators; - ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>(); - valuesGen->add( val1 ); - valuesGen->add( val2 ); - generators.add( valuesGen ); - return generators; - } +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunreachable-code" +#endif - template<typename T> - CompositeGenerator<T> values( T val1, T val2, T val3 ){ - CompositeGenerator<T> generators; - ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>(); - valuesGen->add( val1 ); - valuesGen->add( val2 ); - valuesGen->add( val3 ); - generators.add( valuesGen ); - return generators; - } + bool isMatch( const TestCaseInfo& testCase ) const { + const std::string& name = testCase.getName(); - template<typename T> - CompositeGenerator<T> values( T val1, T val2, T val3, T val4 ) { - CompositeGenerator<T> generators; - ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>(); - valuesGen->add( val1 ); - valuesGen->add( val2 ); - valuesGen->add( val3 ); - valuesGen->add( val4 ); - generators.add( valuesGen ); - return generators; - } + switch( m_wildcardPosition ) { + case NoWildcard: + return m_stringToMatch == name; + case WildcardAtStart: + return endsWith( name, m_stringToMatch ); + case WildcardAtEnd: + return startsWith( name, m_stringToMatch ); + case WildcardAtBothEnds: + return contains( name, m_stringToMatch ); + } + throw std::logic_error( "Unhandled wildcard type" ); + } -} // end namespace Generators +#ifdef __clang__ +#pragma clang diagnostic pop +#endif -using namespace Generators; + std::string m_stringToMatch; + IfFilterMatches::DoWhat m_filterType; + WildcardPosition m_wildcardPosition; + }; -} // end namespace Catch + class TestCaseFilters { + public: + TestCaseFilters( const std::string& name ) : m_name( name ) {} -#define INTERNAL_CATCH_LINESTR2( line ) #line -#define INTERNAL_CATCH_LINESTR( line ) INTERNAL_CATCH_LINESTR2( line ) + std::string getName() const { + return m_name; + } -#define INTERNAL_CATCH_GENERATE( expr ) expr.setFileInfo( __FILE__ "(" INTERNAL_CATCH_LINESTR( __LINE__ ) ")" ) + void addFilter( const TestCaseFilter& filter ) { + if( filter.getFilterType() == IfFilterMatches::ExcludeTests ) + m_exclusionFilters.push_back( filter ); + else + m_inclusionFilters.push_back( filter ); + } -// #included from: internal/catch_interfaces_exception.h -#define TWOBLUECUBES_CATCH_INTERFACES_EXCEPTION_H_INCLUDED + void addTags( const std::string& tagPattern ) { + TagExpression exp; + TagExpressionParser( exp ).parse( tagPattern ); -#include <string> -// #included from: catch_interfaces_registry_hub.h -#define TWOBLUECUBES_CATCH_INTERFACES_REGISTRY_HUB_H_INCLUDED + m_tagExpressions.push_back( exp ); + } -// #included from: catch_interfaces_reporter.h -#define TWOBLUECUBES_CATCH_INTERFACES_REPORTER_H_INCLUDED + bool shouldInclude( const TestCaseInfo& testCase ) const { + if( !m_tagExpressions.empty() ) { + std::vector<TagExpression>::const_iterator it = m_tagExpressions.begin(); + std::vector<TagExpression>::const_iterator itEnd = m_tagExpressions.end(); + for(; it != itEnd; ++it ) + if( it->matches( testCase.getTags() ) ) + break; + if( it == itEnd ) + return false; + } -// #included from: catch_config.hpp -#define TWOBLUECUBES_CATCH_CONFIG_HPP_INCLUDED + if( !m_inclusionFilters.empty() ) { + std::vector<TestCaseFilter>::const_iterator it = m_inclusionFilters.begin(); + std::vector<TestCaseFilter>::const_iterator itEnd = m_inclusionFilters.end(); + for(; it != itEnd; ++it ) + if( it->shouldInclude( testCase ) ) + break; + if( it == itEnd ) + return false; + } + else if( m_exclusionFilters.empty() && m_tagExpressions.empty() ) { + return !testCase.isHidden(); + } -// #included from: catch_test_spec.h -#define TWOBLUECUBES_CATCH_TEST_SPEC_H_INCLUDED + std::vector<TestCaseFilter>::const_iterator it = m_exclusionFilters.begin(); + std::vector<TestCaseFilter>::const_iterator itEnd = m_exclusionFilters.end(); + for(; it != itEnd; ++it ) + if( !it->shouldInclude( testCase ) ) + return false; + return true; + } + private: + std::vector<TagExpression> m_tagExpressions; + std::vector<TestCaseFilter> m_inclusionFilters; + std::vector<TestCaseFilter> m_exclusionFilters; + std::string m_name; + }; -// #included from: catch_test_case_info.h -#define TWOBLUECUBES_CATCH_TEST_CASE_INFO_H_INCLUDED +} -#include <string> -#include <set> +// #included from: catch_interfaces_config.h +#define TWOBLUECUBES_CATCH_INTERFACES_CONFIG_H_INCLUDED namespace Catch { - struct ITestCase; + struct IConfig { - class TestCaseInfo { - public: - TestCaseInfo(); + virtual ~IConfig(); - TestCaseInfo( ITestCase* testCase, - const char* name, - const char* description, - const SourceLineInfo& lineInfo ); + virtual bool allowThrows() const = 0; + }; +} - TestCaseInfo( const TestCaseInfo& other, const std::string& name ); - TestCaseInfo( const TestCaseInfo& other ); +// #included from: catch_stream.hpp +#define TWOBLUECUBES_CATCH_STREAM_HPP_INCLUDED - void invoke() const; - const std::string& getName() const; - const std::string& getDescription() const; - const SourceLineInfo& getLineInfo() const; - bool isHidden() const; - bool hasTag( const std::string& tag ) const; - bool matchesTags( const std::string& tagPattern ) const; - const std::set<std::string>& getTags() const; +// #included from: catch_streambuf.h +#define TWOBLUECUBES_CATCH_STREAMBUF_H_INCLUDED - void swap( TestCaseInfo& other ); - bool operator == ( const TestCaseInfo& other ) const; - bool operator < ( const TestCaseInfo& other ) const; - TestCaseInfo& operator = ( const TestCaseInfo& other ); +#include <streambuf> - private: - Ptr<ITestCase> m_test; - std::string m_name; - std::string m_description; - std::set<std::string> m_tags; - SourceLineInfo m_lineInfo; - bool m_isHidden; +namespace Catch { + + class StreamBufBase : public std::streambuf { + public: + virtual ~StreamBufBase(); }; } -// #included from: catch_tags.hpp -#define TWOBLUECUBES_CATCH_TAGS_HPP_INCLUDED +#include <stdexcept> +#include <cstdio> -#include <string> -#include <set> -#include <map> -#include <vector> +namespace Catch { -#ifdef __clang__ -#pragma clang diagnostic ignored "-Wpadded" -#endif + template<typename WriterF, size_t bufferSize=256> + class StreamBufImpl : public StreamBufBase { + char data[bufferSize]; + WriterF m_writer; -namespace Catch { - class TagParser { public: - virtual ~TagParser(); + StreamBufImpl() { + setp( data, data + sizeof(data) ); + } - void parse( const std::string& str ) { - std::size_t pos = 0; - while( pos < str.size() ) { - char c = str[pos]; - if( c == '[' ) { - std::size_t end = str.find_first_of( ']', pos ); - if( end != std::string::npos ) { - acceptTag( str.substr( pos+1, end-pos-1 ) ); - pos = end+1; - } - else { - acceptChar( c ); - pos++; - } - } - else { - acceptChar( c ); - pos++; - } + ~StreamBufImpl() { + sync(); + } + + private: + int overflow( int c ) { + sync(); + + if( c != EOF ) { + if( pbase() == epptr() ) + m_writer( std::string( 1, static_cast<char>( c ) ) ); + else + sputc( static_cast<char>( c ) ); + } + return 0; + } + + int sync() { + if( pbase() != pptr() ) { + m_writer( std::string( pbase(), static_cast<std::string::size_type>( pptr() - pbase() ) ) ); + setp( pbase(), epptr() ); } - endParse(); + return 0; } - - protected: - virtual void acceptTag( const std::string& tag ) = 0; - virtual void acceptChar( char c ) = 0; - virtual void endParse() {} - - private: }; - class TagExtracter : public TagParser { - public: - - TagExtracter( std::set<std::string>& tags ) - : m_tags( tags ) - {} - virtual ~TagExtracter(); + /////////////////////////////////////////////////////////////////////////// - void parse( std::string& description ) { - TagParser::parse( description ); - description = m_remainder; - } + struct OutputDebugWriter { - private: - virtual void acceptTag( const std::string& tag ) { - m_tags.insert( tag ); - } - virtual void acceptChar( char c ) { - m_remainder += c; + void operator()( const std::string &str ) { + writeToDebugConsole( str ); } - - std::set<std::string>& m_tags; - std::string m_remainder; }; - class Tag { + class Stream { public: - Tag() - : m_isNegated( false ) + Stream() + : streamBuf( NULL ), isOwned( false ) {} - Tag( const std::string& name, bool isNegated ) - : m_name( name ), - m_isNegated( isNegated ) + Stream( std::streambuf* _streamBuf, bool _isOwned ) + : streamBuf( _streamBuf ), isOwned( _isOwned ) {} - std::string getName() const { - return m_name; - } - bool isNegated() const { - return m_isNegated; + void release() { + if( isOwned ) { + delete streamBuf; + streamBuf = NULL; + isOwned = false; + } } - bool operator ! () const { - return m_name.empty(); - } + std::streambuf* streamBuf; private: - std::string m_name; - bool m_isNegated; + bool isOwned; }; +} - class TagSet { - typedef std::map<std::string, Tag> TagMap; - public: - void add( const Tag& tag ) { - m_tags.insert( std::make_pair( tag.getName(), tag ) ); - } +#include <memory> +#include <vector> +#include <string> +#include <iostream> - bool empty() const { - return m_tags.empty(); - } +namespace Catch { - bool matches( const std::set<std::string>& tags ) const { - TagMap::const_iterator it = m_tags.begin(); - TagMap::const_iterator itEnd = m_tags.end(); - for(; it != itEnd; ++it ) { - bool found = tags.find( it->first ) != tags.end(); - if( found == it->second.isNegated() ) - return false; - } - return true; - } + struct Include { enum WhichResults { + FailedOnly, + SuccessfulResults + }; }; - private: - TagMap m_tags; - }; + struct List{ enum What { + None = 0, - class TagExpression { - public: - bool matches( const std::set<std::string>& tags ) const { - std::vector<TagSet>::const_iterator it = m_tagSets.begin(); - std::vector<TagSet>::const_iterator itEnd = m_tagSets.end(); - for(; it != itEnd; ++it ) - if( it->matches( tags ) ) - return true; - return false; - } + Reports = 1, + Tests = 2, + All = 3, - private: - friend class TagExpressionParser; + TestNames = 6, - std::vector<TagSet> m_tagSets; + WhatMask = 0xf, + + AsText = 0x10, + AsXml = 0x20, + + AsMask = 0xf0 + }; }; + + struct ConfigData { + + struct WarnAbout { enum What { + Nothing = 0x00, + NoAssertions = 0x01 + }; }; + + ConfigData() + : listSpec( List::None ), + shouldDebugBreak( false ), + includeWhichResults( Include::FailedOnly ), + cutoff( -1 ), + allowThrows( true ), + warnings( WarnAbout::Nothing ) + {} + + std::string reporter; + std::string outputFilename; + List::What listSpec; + std::vector<TestCaseFilters> filters; + bool shouldDebugBreak; + std::string stream; + Include::WhichResults includeWhichResults; + std::string name; + int cutoff; + bool allowThrows; + WarnAbout::What warnings; }; - class TagExpressionParser : public TagParser { + class Config : public IConfig { + private: + Config( const Config& other ); + Config& operator = ( const Config& other ); + virtual void dummy(); public: - TagExpressionParser( TagExpression& exp ) - : m_isNegated( false ), - m_exp( exp ) + + Config() + : m_os( std::cout.rdbuf() ) {} - ~TagExpressionParser(); + Config( const ConfigData& data ) + : m_data( data ), + m_os( std::cout.rdbuf() ) + {} - private: - virtual void acceptTag( const std::string& tag ) { - m_currentTagSet.add( Tag( tag, m_isNegated ) ); - m_isNegated = false; - } - virtual void acceptChar( char c ) { - switch( c ) { - case '~': - m_isNegated = true; - break; - case ',': - m_exp.m_tagSets.push_back( m_currentTagSet ); - break; - } - } - virtual void endParse() { - if( !m_currentTagSet.empty() ) - m_exp.m_tagSets.push_back( m_currentTagSet ); + virtual ~Config() { + m_os.rdbuf( std::cout.rdbuf() ); + m_stream.release(); } - bool m_isNegated; - TagSet m_currentTagSet; - TagExpression& m_exp; - }; + void setFilename( const std::string& filename ) { + m_data.outputFilename = filename; + } -} // end namespace Catch + List::What getListSpec( void ) const { + return m_data.listSpec; + } -#include <string> -#include <vector> + const std::string& getFilename() const { + return m_data.outputFilename ; + } -namespace Catch { + List::What listWhat() const { + return static_cast<List::What>( m_data.listSpec & List::WhatMask ); + } - struct IfFilterMatches{ enum DoWhat { - AutoDetectBehaviour, - IncludeTests, - ExcludeTests - }; }; + List::What listAs() const { + return static_cast<List::What>( m_data.listSpec & List::AsMask ); + } - class TestCaseFilter { - enum WildcardPosition { - NoWildcard = 0, - WildcardAtStart = 1, - WildcardAtEnd = 2, - WildcardAtBothEnds = WildcardAtStart | WildcardAtEnd - }; + std::string getName() const { + return m_data.name; + } - public: - TestCaseFilter( const std::string& testSpec, IfFilterMatches::DoWhat matchBehaviour = IfFilterMatches::AutoDetectBehaviour ) - : m_stringToMatch( testSpec ), - m_filterType( matchBehaviour ), - m_wildcardPosition( NoWildcard ) - { - if( m_filterType == IfFilterMatches::AutoDetectBehaviour ) { - if( startsWith( m_stringToMatch, "exclude:" ) ) { - m_stringToMatch = m_stringToMatch.substr( 8 ); - m_filterType = IfFilterMatches::ExcludeTests; - } - else if( startsWith( m_stringToMatch, "~" ) ) { - m_stringToMatch = m_stringToMatch.substr( 1 ); - m_filterType = IfFilterMatches::ExcludeTests; - } - else { - m_filterType = IfFilterMatches::IncludeTests; - } - } + bool shouldDebugBreak() const { + return m_data.shouldDebugBreak; + } - if( m_stringToMatch[0] == '*' ) { - m_stringToMatch = m_stringToMatch.substr( 1 ); - m_wildcardPosition = (WildcardPosition)( m_wildcardPosition | WildcardAtStart ); - } - if( m_stringToMatch[m_stringToMatch.size()-1] == '*' ) { - m_stringToMatch = m_stringToMatch.substr( 0, m_stringToMatch.size()-1 ); - m_wildcardPosition = (WildcardPosition)( m_wildcardPosition | WildcardAtEnd ); - } + virtual std::ostream& stream() const { + return m_os; } - IfFilterMatches::DoWhat getFilterType() const { - return m_filterType; + void setStreamBuf( std::streambuf* buf ) { + m_os.rdbuf( buf ? buf : std::cout.rdbuf() ); } - bool shouldInclude( const TestCaseInfo& testCase ) const { - return isMatch( testCase ) == (m_filterType == IfFilterMatches::IncludeTests); + void useStream( const std::string& streamName ) { + Stream stream = createStream( streamName ); + setStreamBuf( stream.streamBuf ); + m_stream.release(); + m_stream = stream; } - private: -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wunreachable-code" -#endif + void addTestSpec( const std::string& testSpec ) { + TestCaseFilters filters( testSpec ); + filters.addFilter( TestCaseFilter( testSpec ) ); + m_data.filters.push_back( filters ); + } - bool isMatch( const TestCaseInfo& testCase ) const { - const std::string& name = testCase.getName(); + virtual bool includeSuccessfulResults() const { + return m_data.includeWhichResults == Include::SuccessfulResults; + } - switch( m_wildcardPosition ) { - case NoWildcard: - return m_stringToMatch == name; - case WildcardAtStart: - return endsWith( name, m_stringToMatch ); - case WildcardAtEnd: - return startsWith( name, m_stringToMatch ); - case WildcardAtBothEnds: - return contains( name, m_stringToMatch ); - } - throw std::logic_error( "Unhandled wildcard type" ); + int getCutoff() const { + return m_data.cutoff; } -#ifdef __clang__ -#pragma clang diagnostic pop -#endif + virtual bool allowThrows() const { + return m_data.allowThrows; + } - std::string m_stringToMatch; - IfFilterMatches::DoWhat m_filterType; - WildcardPosition m_wildcardPosition; - }; + const ConfigData& data() const { + return m_data; + } + ConfigData& data() { + return m_data; + } - class TestCaseFilters { - public: - TestCaseFilters( const std::string& name ) : m_name( name ) {} + private: + ConfigData m_data; - std::string getName() const { - return m_name; - } + // !TBD Move these out of here + Stream m_stream; + mutable std::ostream m_os; + }; - void addFilter( const TestCaseFilter& filter ) { - if( filter.getFilterType() == IfFilterMatches::ExcludeTests ) - m_exclusionFilters.push_back( filter ); - else - m_inclusionFilters.push_back( filter ); - } +} // end namespace Catch - void addTags( const std::string& tagPattern ) { - TagExpression exp; - TagExpressionParser( exp ).parse( tagPattern ); +#include <string> +#include <ostream> +#include <map> - m_tagExpressions.push_back( exp ); - } +namespace Catch +{ + struct ReporterConfig + { + ReporterConfig( const std::string& _name, + std::ostream& _stream, + bool _includeSuccessfulResults, + const ConfigData& _fullConfig ) + : name( _name ), + stream( _stream ), + includeSuccessfulResults( _includeSuccessfulResults ), + fullConfig( _fullConfig ) + {} - bool shouldInclude( const TestCaseInfo& testCase ) const { - if( !m_tagExpressions.empty() ) { - std::vector<TagExpression>::const_iterator it = m_tagExpressions.begin(); - std::vector<TagExpression>::const_iterator itEnd = m_tagExpressions.end(); - for(; it != itEnd; ++it ) - if( it->matches( testCase.getTags() ) ) - break; - if( it == itEnd ) - return false; - } + ReporterConfig( const ReporterConfig& other ) + : name( other.name ), + stream( other.stream ), + includeSuccessfulResults( other.includeSuccessfulResults ), + fullConfig( other.fullConfig ) + {} - if( !m_inclusionFilters.empty() ) { - std::vector<TestCaseFilter>::const_iterator it = m_inclusionFilters.begin(); - std::vector<TestCaseFilter>::const_iterator itEnd = m_inclusionFilters.end(); - for(; it != itEnd; ++it ) - if( it->shouldInclude( testCase ) ) - break; - if( it == itEnd ) - return false; - } - else if( m_exclusionFilters.empty() && m_tagExpressions.empty() ) { - return !testCase.isHidden(); - } + std::string name; + std::ostream& stream; + bool includeSuccessfulResults; + ConfigData fullConfig; - std::vector<TestCaseFilter>::const_iterator it = m_exclusionFilters.begin(); - std::vector<TestCaseFilter>::const_iterator itEnd = m_exclusionFilters.end(); - for(; it != itEnd; ++it ) - if( !it->shouldInclude( testCase ) ) - return false; - return true; - } private: - std::vector<TagExpression> m_tagExpressions; - std::vector<TestCaseFilter> m_inclusionFilters; - std::vector<TestCaseFilter> m_exclusionFilters; - std::string m_name; + void operator=(const ReporterConfig&); }; -} + class TestCaseInfo; + class AssertionResult; -// #included from: catch_interfaces_config.h -#define TWOBLUECUBES_CATCH_INTERFACES_CONFIG_H_INCLUDED + struct IReporter : IShared { + virtual ~IReporter(); -namespace Catch { + virtual bool shouldRedirectStdout() const = 0; - struct IConfig { + virtual void StartTesting() = 0; + virtual void EndTesting( const Totals& totals ) = 0; - virtual ~IConfig(); + virtual void StartGroup( const std::string& groupName ) = 0; + virtual void EndGroup( const std::string& groupName, const Totals& totals ) = 0; - virtual bool allowThrows() const = 0; - }; -} + virtual void StartTestCase( const TestCaseInfo& testInfo ) = 0; + // TestCaseResult + virtual void EndTestCase( const TestCaseInfo& testInfo, const Totals& totals, const std::string& stdOut, const std::string& stdErr ) = 0; -// #included from: catch_stream.hpp -#define TWOBLUECUBES_CATCH_STREAM_HPP_INCLUDED + // SectionInfo + virtual void StartSection( const std::string& sectionName, const std::string& description ) = 0; + // Section Result + virtual void EndSection( const std::string& sectionName, const Counts& assertions ) = 0; -// #included from: catch_streambuf.h -#define TWOBLUECUBES_CATCH_STREAMBUF_H_INCLUDED + // - merge into SectionResult ? + virtual void NoAssertionsInSection( const std::string& sectionName ) = 0; + virtual void NoAssertionsInTestCase( const std::string& testName ) = 0; -#include <streambuf> + // - merge into SectionResult, TestCaseResult, GroupResult & TestRunResult + virtual void Aborted() = 0; -namespace Catch { + // AssertionReslt + virtual void Result( const AssertionResult& result ) = 0; + }; - class StreamBufBase : public std::streambuf { - public: - virtual ~StreamBufBase(); + struct IReporterFactory { + virtual ~IReporterFactory(); + virtual IReporter* create( const ReporterConfig& config ) const = 0; + virtual std::string getDescription() const = 0; + }; + + struct IReporterRegistry { + typedef std::map<std::string, IReporterFactory*> FactoryMap; + + virtual ~IReporterRegistry(); + virtual IReporter* create( const std::string& name, const ReporterConfig& config ) const = 0; + virtual const FactoryMap& getFactories() const = 0; }; + + 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 " ); + + return start != std::string::npos ? str.substr( start, 1+end-start ) : ""; + } } -#include <stdexcept> -#include <cstdio> +#include <vector> namespace Catch { - template<typename WriterF, size_t bufferSize=256> - class StreamBufImpl : public StreamBufBase { - char data[bufferSize]; - WriterF m_writer; + class TestCaseInfo; + struct ITestCaseRegistry; + struct IExceptionTranslatorRegistry; + struct IExceptionTranslator; - public: - StreamBufImpl() { - setp( data, data + sizeof(data) ); - } + struct IRegistryHub { + virtual ~IRegistryHub(); - ~StreamBufImpl() { - sync(); - } + virtual const IReporterRegistry& getReporterRegistry() const = 0; + virtual const ITestCaseRegistry& getTestCaseRegistry() const = 0; + virtual IExceptionTranslatorRegistry& getExceptionTranslatorRegistry() = 0; + }; - private: - int overflow( int c ) { - sync(); + struct IMutableRegistryHub { + virtual ~IMutableRegistryHub(); + virtual void registerReporter( const std::string& name, IReporterFactory* factory ) = 0; + virtual void registerTest( const TestCaseInfo& testInfo ) = 0; + virtual void registerTranslator( const IExceptionTranslator* translator ) = 0; + }; - if( c != EOF ) { - if( pbase() == epptr() ) - m_writer( std::string( 1, static_cast<char>( c ) ) ); - else - sputc( static_cast<char>( c ) ); - } - return 0; - } + IRegistryHub& getRegistryHub(); + IMutableRegistryHub& getMutableRegistryHub(); + void cleanUp(); + std::string translateActiveException(); - int sync() { - if( pbase() != pptr() ) { - m_writer( std::string( pbase(), static_cast<std::string::size_type>( pptr() - pbase() ) ) ); - setp( pbase(), epptr() ); - } - return 0; - } - }; +} + +#include <ostream> + +namespace Catch { + + inline IResultCapture& getResultCapture() { + return getCurrentContext().getResultCapture(); + } + + template<typename MatcherT> + ExpressionResultBuilder expressionResultBuilderFromMatcher( const MatcherT& matcher, + const std::string& matcherCallAsString ) { + std::string matcherAsString = matcher.toString(); + if( matcherAsString == "{?}" ) + matcherAsString = matcherCallAsString; + return ExpressionResultBuilder() + .setRhs( matcherAsString ) + .setOp( "matches" ); + } - /////////////////////////////////////////////////////////////////////////// + template<typename MatcherT, typename ArgT> + ExpressionResultBuilder expressionResultBuilderFromMatcher( const MatcherT& matcher, + const ArgT& arg, + const std::string& matcherCallAsString ) { + return expressionResultBuilderFromMatcher( matcher, matcherCallAsString ) + .setLhs( Catch::toString( arg ) ) + .setResultType( matcher.match( arg ) ); + } - struct OutputDebugWriter { + template<typename MatcherT, typename ArgT> + ExpressionResultBuilder expressionResultBuilderFromMatcher( const MatcherT& matcher, + ArgT* arg, + const std::string& matcherCallAsString ) { + return expressionResultBuilderFromMatcher( matcher, matcherCallAsString ) + .setLhs( Catch::toString( arg ) ) + .setResultType( matcher.match( arg ) ); + } - void operator()( const std::string &str ) { - writeToDebugConsole( str ); - } - }; +struct TestFailureException{}; - class Stream { - public: - Stream() - : streamBuf( NULL ), isOwned( false ) - {} +class ScopedInfo { +public: + ScopedInfo() : m_resultBuilder( ResultWas::Info ) { + getResultCapture().pushScopedInfo( this ); + } + ~ScopedInfo() { + getResultCapture().popScopedInfo( this ); + } + template<typename T> + ScopedInfo& operator << ( const T& value ) { + m_resultBuilder << value; + return *this; + } + AssertionResult buildResult( const AssertionInfo& assertionInfo ) const { + return m_resultBuilder.buildResult( assertionInfo ); + } - Stream( std::streambuf* _streamBuf, bool _isOwned ) - : streamBuf( _streamBuf ), isOwned( _isOwned ) - {} +private: + ExpressionResultBuilder m_resultBuilder; +}; - void release() { - if( isOwned ) { - delete streamBuf; - streamBuf = NULL; - isOwned = false; - } - } +// This is just here to avoid compiler warnings with macro constants and boolean literals +inline bool isTrue( bool value ){ return value; } - std::streambuf* streamBuf; +} // end namespace Catch - private: - bool isOwned; - }; -} +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CATCH_ACCEPT_EXPR( evaluatedExpr, stopOnFailure, originalExpr ) \ + if( Catch::ResultAction::Value internal_catch_action = Catch::getResultCapture().acceptExpression( evaluatedExpr ) ) { \ + if( internal_catch_action & Catch::ResultAction::Debug ) BreakIntoDebugger(); \ + if( internal_catch_action & Catch::ResultAction::Abort ) throw Catch::TestFailureException(); \ + if( Catch::isTrue( stopOnFailure ) ) throw Catch::TestFailureException(); \ + if( Catch::isTrue( false ) ){ bool this_is_here_to_invoke_warnings = ( originalExpr ); Catch::isTrue( this_is_here_to_invoke_warnings ); } \ + } -#include <memory> -#include <vector> -#include <string> -#include <iostream> +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CATCH_ACCEPT_INFO( expr, macroName, shouldNegate ) \ + Catch::getResultCapture().acceptAssertionInfo( Catch::AssertionInfo( macroName, CATCH_INTERNAL_LINEINFO, expr, shouldNegate ) ); -namespace Catch { +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CATCH_TEST( expr, shouldNegate, stopOnFailure, macroName ) \ + do { try { \ + INTERNAL_CATCH_ACCEPT_INFO( #expr, macroName, shouldNegate ); \ + INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionDecomposer()->*expr ).negate( shouldNegate ), stopOnFailure, expr ); \ + } catch( Catch::TestFailureException& ) { \ + throw; \ + } catch( ... ) { \ + INTERNAL_CATCH_ACCEPT_EXPR( Catch::ExpressionResultBuilder( Catch::ResultWas::ThrewException ) << Catch::translateActiveException(), false, expr ); \ + throw; \ + } } while( Catch::isTrue( false ) ) - struct Include { enum WhichResults { - FailedOnly, - SuccessfulResults - }; }; +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CATCH_IF( expr, shouldNegate, stopOnFailure, macroName ) \ + INTERNAL_CATCH_TEST( expr, shouldNegate, stopOnFailure, macroName ); \ + if( Catch::getResultCapture().getLastResult()->ok() ) - struct List{ enum What { - None = 0, +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CATCH_ELSE( expr, shouldNegate, stopOnFailure, macroName ) \ + INTERNAL_CATCH_TEST( expr, shouldNegate, stopOnFailure, macroName ); \ + if( !Catch::getResultCapture().getLastResult()->ok() ) - Reports = 1, - Tests = 2, - All = 3, +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CATCH_NO_THROW( expr, stopOnFailure, macroName ) \ + try { \ + INTERNAL_CATCH_ACCEPT_INFO( #expr, macroName, false ); \ + expr; \ + INTERNAL_CATCH_ACCEPT_EXPR( Catch::ExpressionResultBuilder( Catch::ResultWas::Ok ), stopOnFailure, false ); \ + } \ + catch( ... ) { \ + INTERNAL_CATCH_ACCEPT_EXPR( Catch::ExpressionResultBuilder( Catch::ResultWas::ThrewException ) << Catch::translateActiveException(), stopOnFailure, false ); \ + } - TestNames = 6, +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CATCH_THROWS( expr, exceptionType, stopOnFailure, macroName ) \ + try { \ + INTERNAL_CATCH_ACCEPT_INFO( #expr, macroName, false ); \ + if( Catch::getCurrentContext().getConfig()->allowThrows() ) { \ + expr; \ + INTERNAL_CATCH_ACCEPT_EXPR( Catch::ExpressionResultBuilder( Catch::ResultWas::DidntThrowException ), stopOnFailure, false ); \ + } \ + } \ + catch( Catch::TestFailureException& ) { \ + throw; \ + } \ + catch( exceptionType ) { \ + INTERNAL_CATCH_ACCEPT_EXPR( Catch::ExpressionResultBuilder( Catch::ResultWas::Ok ), stopOnFailure, false ); \ + } - WhatMask = 0xf, +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CATCH_THROWS_AS( expr, exceptionType, stopOnFailure, macroName ) \ + INTERNAL_CATCH_THROWS( expr, exceptionType, stopOnFailure, macroName ) \ + catch( ... ) { \ + INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionResultBuilder( Catch::ResultWas::ThrewException ) << Catch::translateActiveException() ), stopOnFailure, false ); \ + } - AsText = 0x10, - AsXml = 0x20, +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CATCH_MSG( reason, resultType, stopOnFailure, macroName ) \ + INTERNAL_CATCH_ACCEPT_EXPR( Catch::ExpressionResultBuilder( resultType ) << reason, stopOnFailure, true ); - AsMask = 0xf0 - }; }; +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CATCH_SCOPED_INFO( log, macroName ) \ + INTERNAL_CATCH_ACCEPT_INFO( "", macroName, false ); \ + Catch::ScopedInfo INTERNAL_CATCH_UNIQUE_NAME( info ); \ + INTERNAL_CATCH_UNIQUE_NAME( info ) << log - struct ConfigData { +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CHECK_THAT( arg, matcher, stopOnFailure, macroName ) \ + do { try { \ + INTERNAL_CATCH_ACCEPT_INFO( #arg " " #matcher, macroName, false ) \ + INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::expressionResultBuilderFromMatcher( ::Catch::Matchers::matcher, arg, #matcher ) ), stopOnFailure, false ); \ + } catch( Catch::TestFailureException& ) { \ + throw; \ + } catch( ... ) { \ + INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionResultBuilder( Catch::ResultWas::ThrewException ) << Catch::translateActiveException() ), false, false ); \ + throw; \ + }}while( Catch::isTrue( false ) ) - struct WarnAbout { enum What { - Nothing = 0x00, - NoAssertions = 0x01 - }; }; +// #included from: internal/catch_section.hpp +#define TWOBLUECUBES_CATCH_SECTION_HPP_INCLUDED - ConfigData() - : listSpec( List::None ), - shouldDebugBreak( false ), - includeWhichResults( Include::FailedOnly ), - cutoff( -1 ), - allowThrows( true ), - warnings( WarnAbout::Nothing ) - {} +#include <string> - std::string reporter; - std::string outputFilename; - List::What listSpec; - std::vector<TestCaseFilters> filters; - bool shouldDebugBreak; - std::string stream; - Include::WhichResults includeWhichResults; - std::string name; - int cutoff; - bool allowThrows; - WarnAbout::What warnings; - }; +namespace Catch { - class Config : public IConfig { - private: - Config( const Config& other ); - Config& operator = ( const Config& other ); - virtual void dummy(); + class Section { public: - - Config() - : m_os( std::cout.rdbuf() ) - {} - - Config( const ConfigData& data ) - : m_data( data ), - m_os( std::cout.rdbuf() ) + Section( const std::string& name, + const std::string& description, + const SourceLineInfo& lineInfo ) + : m_name( name ), + m_sectionIncluded( getCurrentContext().getResultCapture().sectionStarted( name, description, lineInfo, m_assertions ) ) {} - virtual ~Config() { - m_os.rdbuf( std::cout.rdbuf() ); - m_stream.release(); + ~Section() { + if( m_sectionIncluded ) + getCurrentContext().getResultCapture().sectionEnded( m_name, m_assertions ); } - void setFilename( const std::string& filename ) { - m_data.outputFilename = filename; + // This indicates whether the section should be executed or not + operator bool() { + return m_sectionIncluded; } - List::What getListSpec( void ) const { - return m_data.listSpec; - } + private: - const std::string& getFilename() const { - return m_data.outputFilename ; - } + std::string m_name; + Counts m_assertions; + bool m_sectionIncluded; + }; - List::What listWhat() const { - return static_cast<List::What>( m_data.listSpec & List::WhatMask ); - } +} // end namespace Catch - List::What listAs() const { - return static_cast<List::What>( m_data.listSpec & List::AsMask ); - } +#define INTERNAL_CATCH_SECTION( name, desc ) \ + if( Catch::Section INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::Section( name, desc, CATCH_INTERNAL_LINEINFO ) ) - std::string getName() const { - return m_data.name; - } +// #included from: internal/catch_generators.hpp +#define TWOBLUECUBES_CATCH_GENERATORS_HPP_INCLUDED - bool shouldDebugBreak() const { - return m_data.shouldDebugBreak; - } +#include <iterator> +#include <vector> +#include <string> +#include <stdlib.h> - virtual std::ostream& stream() const { - return m_os; - } +namespace Catch { - void setStreamBuf( std::streambuf* buf ) { - m_os.rdbuf( buf ? buf : std::cout.rdbuf() ); - } +template<typename T> +struct IGenerator { + virtual ~IGenerator() {} + virtual T getValue( std::size_t index ) const = 0; + virtual std::size_t size () const = 0; +}; - void useStream( const std::string& streamName ) { - Stream stream = createStream( streamName ); - setStreamBuf( stream.streamBuf ); - m_stream.release(); - m_stream = stream; - } +template<typename T> +class BetweenGenerator : public IGenerator<T> { +public: + BetweenGenerator( T from, T to ) : m_from( from ), m_to( to ){} - void addTestSpec( const std::string& testSpec ) { - TestCaseFilters filters( testSpec ); - filters.addFilter( TestCaseFilter( testSpec ) ); - m_data.filters.push_back( filters ); - } + virtual T getValue( std::size_t index ) const { + return m_from+static_cast<T>( index ); + } + + virtual std::size_t size() const { + return static_cast<std::size_t>( 1+m_to-m_from ); + } + +private: + + T m_from; + T m_to; +}; + +template<typename T> +class ValuesGenerator : public IGenerator<T> { +public: + ValuesGenerator(){} - virtual bool includeSuccessfulResults() const { - return m_data.includeWhichResults == Include::SuccessfulResults; - } + void add( T value ) { + m_values.push_back( value ); + } - int getCutoff() const { - return m_data.cutoff; - } + virtual T getValue( std::size_t index ) const { + return m_values[index]; + } - virtual bool allowThrows() const { - return m_data.allowThrows; - } + virtual std::size_t size() const { + return m_values.size(); + } - const ConfigData& data() const { - return m_data; - } - ConfigData& data() { - return m_data; - } +private: + std::vector<T> m_values; +}; - private: - ConfigData m_data; +template<typename T> +class CompositeGenerator { +public: + CompositeGenerator() : m_totalSize( 0 ) {} - // !TBD Move these out of here - Stream m_stream; - mutable std::ostream m_os; - }; + // *** Move semantics, similar to auto_ptr *** + CompositeGenerator( CompositeGenerator& other ) + : m_fileInfo( other.m_fileInfo ), + m_totalSize( 0 ) + { + move( other ); + } -} // end namespace Catch + CompositeGenerator& setFileInfo( const char* fileInfo ) { + m_fileInfo = fileInfo; + return *this; + } -#include <string> -#include <ostream> -#include <map> + ~CompositeGenerator() { + deleteAll( m_composed ); + } -namespace Catch -{ - struct ReporterConfig - { - ReporterConfig( const std::string& _name, - std::ostream& _stream, - bool _includeSuccessfulResults, - const ConfigData& _fullConfig ) - : name( _name ), - stream( _stream ), - includeSuccessfulResults( _includeSuccessfulResults ), - fullConfig( _fullConfig ) - {} + operator T () const { + size_t overallIndex = getCurrentContext().getGeneratorIndex( m_fileInfo, m_totalSize ); - ReporterConfig( const ReporterConfig& other ) - : name( other.name ), - stream( other.stream ), - includeSuccessfulResults( other.includeSuccessfulResults ), - fullConfig( other.fullConfig ) - {} + typename std::vector<const IGenerator<T>*>::const_iterator it = m_composed.begin(); + typename std::vector<const IGenerator<T>*>::const_iterator itEnd = m_composed.end(); + for( size_t index = 0; it != itEnd; ++it ) + { + const IGenerator<T>* generator = *it; + if( overallIndex >= index && overallIndex < index + generator->size() ) + { + return generator->getValue( overallIndex-index ); + } + index += generator->size(); + } + CATCH_INTERNAL_ERROR( "Indexed past end of generated range" ); + return T(); // Suppress spurious "not all control paths return a value" warning in Visual Studio - if you know how to fix this please do so + } - std::string name; - std::ostream& stream; - bool includeSuccessfulResults; - ConfigData fullConfig; + void add( const IGenerator<T>* generator ) { + m_totalSize += generator->size(); + m_composed.push_back( generator ); + } - private: - void operator=(const ReporterConfig&); - }; + CompositeGenerator& then( CompositeGenerator& other ) { + move( other ); + return *this; + } - class TestCaseInfo; - class ResultInfo; + CompositeGenerator& then( T value ) { + ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>(); + valuesGen->add( value ); + add( valuesGen ); + return *this; + } - struct IReporter : IShared { - virtual ~IReporter(); - virtual bool shouldRedirectStdout() const = 0; - virtual void StartTesting() = 0; - 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 NoAssertionsInSection( const std::string& sectionName ) = 0; - virtual void NoAssertionsInTestCase( const std::string& testName ) = 0; - virtual void EndSection( const std::string& sectionName, const Counts& assertions ) = 0; - virtual void StartTestCase( const TestCaseInfo& testInfo ) = 0; - virtual void Aborted() = 0; - virtual void EndTestCase( const TestCaseInfo& testInfo, const Totals& totals, const std::string& stdOut, const std::string& stdErr ) = 0; - virtual void Result( const ResultInfo& result ) = 0; - }; +private: - struct IReporterFactory { - virtual ~IReporterFactory(); - virtual IReporter* create( const ReporterConfig& config ) const = 0; - virtual std::string getDescription() const = 0; - }; + void move( CompositeGenerator& other ) { + std::copy( other.m_composed.begin(), other.m_composed.end(), std::back_inserter( m_composed ) ); + m_totalSize += other.m_totalSize; + other.m_composed.clear(); + } - struct IReporterRegistry { - typedef std::map<std::string, IReporterFactory*> FactoryMap; + std::vector<const IGenerator<T>*> m_composed; + std::string m_fileInfo; + size_t m_totalSize; +}; - virtual ~IReporterRegistry(); - virtual IReporter* create( const std::string& name, const ReporterConfig& config ) const = 0; - virtual const FactoryMap& getFactories() const = 0; - }; +namespace Generators +{ + template<typename T> + CompositeGenerator<T> between( T from, T to ) { + CompositeGenerator<T> generators; + generators.add( new BetweenGenerator<T>( from, to ) ); + return generators; + } - 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 " ); + template<typename T> + CompositeGenerator<T> values( T val1, T val2 ) { + CompositeGenerator<T> generators; + ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>(); + valuesGen->add( val1 ); + valuesGen->add( val2 ); + generators.add( valuesGen ); + return generators; + } - return start != std::string::npos ? str.substr( start, 1+end-start ) : ""; + template<typename T> + CompositeGenerator<T> values( T val1, T val2, T val3 ){ + CompositeGenerator<T> generators; + ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>(); + valuesGen->add( val1 ); + valuesGen->add( val2 ); + valuesGen->add( val3 ); + generators.add( valuesGen ); + return generators; } -} -#include <vector> + template<typename T> + CompositeGenerator<T> values( T val1, T val2, T val3, T val4 ) { + CompositeGenerator<T> generators; + ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>(); + valuesGen->add( val1 ); + valuesGen->add( val2 ); + valuesGen->add( val3 ); + valuesGen->add( val4 ); + generators.add( valuesGen ); + return generators; + } -namespace Catch { +} // end namespace Generators - class TestCaseInfo; - struct ITestCaseRegistry; - struct IExceptionTranslatorRegistry; - struct IExceptionTranslator; +using namespace Generators; - struct IRegistryHub { - virtual ~IRegistryHub(); +} // end namespace Catch - virtual const IReporterRegistry& getReporterRegistry() const = 0; - virtual const ITestCaseRegistry& getTestCaseRegistry() const = 0; - virtual IExceptionTranslatorRegistry& getExceptionTranslatorRegistry() = 0; - }; +#define INTERNAL_CATCH_LINESTR2( line ) #line +#define INTERNAL_CATCH_LINESTR( line ) INTERNAL_CATCH_LINESTR2( line ) - struct IMutableRegistryHub { - virtual ~IMutableRegistryHub(); - virtual void registerReporter( const std::string& name, IReporterFactory* factory ) = 0; - virtual void registerTest( const TestCaseInfo& testInfo ) = 0; - virtual void registerTranslator( const IExceptionTranslator* translator ) = 0; - }; +#define INTERNAL_CATCH_GENERATE( expr ) expr.setFileInfo( __FILE__ "(" INTERNAL_CATCH_LINESTR( __LINE__ ) ")" ) - IRegistryHub& getRegistryHub(); - IMutableRegistryHub& getMutableRegistryHub(); - void cleanUp(); -} +// #included from: internal/catch_interfaces_exception.h +#define TWOBLUECUBES_CATCH_INTERFACES_EXCEPTION_H_INCLUDED +#include <string> namespace Catch { @@ -3942,7 +3953,7 @@ namespace Catch { do { do { - m_currentResult.setLineInfo( m_runningTest->getTestCaseInfo().getLineInfo() ); + m_assertionInfo.lineInfo = m_runningTest->getTestCaseInfo().getLineInfo(); runCurrentTest( redirectedCout, redirectedCerr ); } while( m_runningTest->hasUntestedSections() && !aborting() ); @@ -3964,25 +3975,16 @@ namespace Catch { private: // IResultCapture - virtual ResultAction::Value acceptResult( bool result ) { - return acceptResult( result ? ResultWas::Ok : ResultWas::ExpressionFailed ); + virtual void acceptAssertionInfo( const AssertionInfo& assertionInfo ) { + m_assertionInfo = assertionInfo; } - virtual ResultAction::Value acceptResult( ResultWas::OfType result ) { - m_currentResult.setResultType( result ); + virtual ResultAction::Value acceptExpression( const ExpressionResultBuilder& assertionResult ) { + m_currentResult = assertionResult; return actOnCurrentResult(); } - virtual ResultAction::Value acceptExpression( const ResultInfoBuilder& resultInfo ) { - m_currentResult = resultInfo; - return actOnCurrentResult(); - } - - virtual void acceptMessage( const std::string& msg ) { - m_currentResult.setMessage( msg ); - } - - virtual void testEnded( const ResultInfo& result ) { + virtual void testEnded( const AssertionResult& result ) { if( result.getResultType() == ResultWas::Ok ) { m_totals.assertions.passed++; } @@ -3993,19 +3995,19 @@ namespace Catch { std::vector<ScopedInfo*>::const_iterator it = m_scopedInfos.begin(); std::vector<ScopedInfo*>::const_iterator itEnd = m_scopedInfos.end(); for(; it != itEnd; ++it ) - m_reporter->Result( (*it)->getInfo() ); + m_reporter->Result( (*it)->buildResult( m_assertionInfo ) ); } { - std::vector<ResultInfo>::const_iterator it = m_info.begin(); - std::vector<ResultInfo>::const_iterator itEnd = m_info.end(); + std::vector<AssertionResult>::const_iterator it = m_assertionResults.begin(); + std::vector<AssertionResult>::const_iterator itEnd = m_assertionResults.end(); for(; it != itEnd; ++it ) m_reporter->Result( *it ); } - m_info.clear(); + m_assertionResults.clear(); } if( result.getResultType() == ResultWas::Info ) - m_info.push_back( result ); + m_assertionResults.push_back( result ); else m_reporter->Result( result ); } @@ -4023,7 +4025,7 @@ namespace Catch { if( !m_runningTest->addSection( oss.str() ) ) return false; - m_currentResult.setLineInfo( lineInfo ); + m_assertionInfo.lineInfo = lineInfo; m_reporter->StartSection( name, description ); assertions = m_totals.assertions; @@ -4062,7 +4064,7 @@ namespace Catch { : ""; } - virtual const ResultInfo* getLastResult() const { + virtual const AssertionResult* getLastResult() const { return &m_lastResult; } @@ -4075,10 +4077,11 @@ namespace Catch { private: ResultAction::Value actOnCurrentResult() { - m_lastResult = m_currentResult.build(); + m_lastResult = m_currentResult.buildResult( m_assertionInfo ); testEnded( m_lastResult ); - m_currentResult = ResultInfoBuilder(); + m_currentResult = ExpressionResultBuilder(); + m_assertionInfo = AssertionInfo(); ResultAction::Value action = ResultAction::None; @@ -4117,26 +4120,29 @@ namespace Catch { // This just means the test was aborted due to failure } catch(...) { - acceptMessage( getRegistryHub().getExceptionTranslatorRegistry().translateActiveException() ); - acceptResult( ResultWas::ThrewException ); + m_currentResult + .setResultType( ResultWas::ThrewException ) + << translateActiveException(); + actOnCurrentResult(); } - m_info.clear(); + m_assertionResults.clear(); } private: IMutableContext& m_context; RunningTest* m_runningTest; - ResultInfoBuilder m_currentResult; - ResultInfo m_lastResult; + ExpressionResultBuilder m_currentResult; + AssertionResult m_lastResult; const Config& m_config; Totals m_totals; Ptr<IReporter> m_reporter; std::vector<ScopedInfo*> m_scopedInfos; - std::vector<ResultInfo> m_info; + std::vector<AssertionResult> m_assertionResults; IRunner* m_prevRunner; IResultCapture* m_prevResultCapture; const IConfig* m_prevConfig; + AssertionInfo m_assertionInfo; }; } // end namespace Catch @@ -4669,6 +4675,9 @@ namespace Catch { getTheRegistryHub() = NULL; cleanUpContext(); } + std::string translateActiveException() { + return getRegistryHub().getExceptionTranslatorRegistry().translateActiveException(); + } } // end namespace Catch @@ -4987,151 +4996,145 @@ namespace Catch { } // end namespace Catch -// #included from: catch_resultinfo.hpp -#define TWOBLUECUBES_CATCH_RESULTINFO_HPP_INCLUDED +// #included from: catch_assertionresult.hpp +#define TWOBLUECUBES_CATCH_ASSERTIONRESULT_HPP_INCLUDED namespace Catch { - ResultInfo::ResultInfo() {} + AssertionResult::AssertionResult() {} - ResultInfo::ResultInfo( const ResultData& data ) : m_data( data ) {} + AssertionResult::AssertionResult( const AssertionInfo& info, const AssertionResultData& data ) + : m_info( info ), + m_resultData( data ) + {} - ResultInfo::~ResultInfo() {} + AssertionResult::~AssertionResult() {} - bool ResultInfo::ok() const { - return isOk( m_data.resultType ); + bool AssertionResult::ok() const { + return isOk( m_resultData.resultType ); } - ResultWas::OfType ResultInfo::getResultType() const { - return m_data.resultType; + ResultWas::OfType AssertionResult::getResultType() const { + return m_resultData.resultType; } - bool ResultInfo::hasExpression() const { - return !m_data.capturedExpression.empty(); + bool AssertionResult::hasExpression() const { + return !m_info.capturedExpression.empty(); } - bool ResultInfo::hasMessage() const { - return !m_data.message.empty(); + bool AssertionResult::hasMessage() const { + return !m_resultData.message.empty(); } - std::string ResultInfo::getExpression() const { - return m_data.capturedExpression; + std::string AssertionResult::getExpression() const { + return m_info.capturedExpression; } - bool ResultInfo::hasExpandedExpression() const { + bool AssertionResult::hasExpandedExpression() const { return hasExpression() && getExpandedExpression() != getExpression(); } - std::string ResultInfo::getExpandedExpression() const { - return m_data.reconstructedExpression; - } - - std::string ResultInfo::getMessage() const { - return m_data.message; + std::string AssertionResult::getExpandedExpression() const { + return m_resultData.reconstructedExpression; } - std::string ResultInfo::getFilename() const { - return m_data.lineInfo.file; + std::string AssertionResult::getMessage() const { + return m_resultData.message; } - - std::size_t ResultInfo::getLine() const { - return m_data.lineInfo.line; + SourceLineInfo AssertionResult::getSourceInfo() const { + return m_info.lineInfo; } - std::string ResultInfo::getTestMacroName() const { - return m_data.macroName; + std::string AssertionResult::getTestMacroName() const { + return m_info.macroName; } } // end namespace Catch -// #included from: catch_resultinfo_builder.hpp -#define TWOBLUECUBES_CATCH_RESULTINFO_BUILDER_HPP_INCLUDED +// #included from: catch_expressionresult_builder.hpp +#define TWOBLUECUBES_CATCH_EXPRESSIONRESULT_BUILDER_HPP_INCLUDED -namespace Catch { +#include <assert.h> - ResultInfoBuilder::ResultInfoBuilder() {} +namespace Catch { - ResultInfoBuilder& ResultInfoBuilder::setResultType( ResultWas::OfType result ) { - // Flip bool results if isFalse is set - if( m_isFalse && result == ResultWas::Ok ) - m_data.resultType = ResultWas::ExpressionFailed; - else if( m_isFalse && result == ResultWas::ExpressionFailed ) - m_data.resultType = ResultWas::Ok; - else - m_data.resultType = result; - return *this; + ExpressionResultBuilder::ExpressionResultBuilder( ResultWas::OfType resultType ) { + m_data.resultType = resultType; } - ResultInfoBuilder& ResultInfoBuilder::setCapturedExpression( const std::string& capturedExpression ) { - m_data.capturedExpression = capturedExpression; - return *this; + ExpressionResultBuilder::ExpressionResultBuilder( const ExpressionResultBuilder& other ) + : m_data( other.m_data ), + m_exprComponents( other.m_exprComponents ) + { + m_stream << other.m_stream.str(); } - ResultInfoBuilder& ResultInfoBuilder::setIsFalse( bool isFalse ) { - m_isFalse = isFalse; + ExpressionResultBuilder& ExpressionResultBuilder::operator=(const ExpressionResultBuilder& other ) { + m_data = other.m_data; + m_exprComponents = other.m_exprComponents; + m_stream.str(""); + m_stream << other.m_stream.str(); return *this; } - - ResultInfoBuilder& ResultInfoBuilder::setMessage( const std::string& message ) { - m_data.message = message; + ExpressionResultBuilder& ExpressionResultBuilder::setResultType( ResultWas::OfType result ) { + m_data.resultType = result; return *this; } - - ResultInfoBuilder& ResultInfoBuilder::setLineInfo( const SourceLineInfo& lineInfo ) { - m_data.lineInfo = lineInfo; + ExpressionResultBuilder& ExpressionResultBuilder::setResultType( bool result ) { + m_data.resultType = result ? ResultWas::Ok : ResultWas::ExpressionFailed; return *this; } - - ResultInfoBuilder& ResultInfoBuilder::setMacroName( const std::string& macroName ) { - m_data.macroName = macroName; + ExpressionResultBuilder& ExpressionResultBuilder::negate( bool shouldNegate ) { + m_exprComponents.shouldNegate = shouldNegate; return *this; } - - ResultInfoBuilder& ResultInfoBuilder::setLhs( const std::string& lhs ) { - m_lhs = lhs; + ExpressionResultBuilder& ExpressionResultBuilder::setLhs( const std::string& lhs ) { + m_exprComponents.lhs = lhs; return *this; } - - ResultInfoBuilder& ResultInfoBuilder::setRhs( const std::string& rhs ) { - m_rhs = rhs; + ExpressionResultBuilder& ExpressionResultBuilder::setRhs( const std::string& rhs ) { + m_exprComponents.rhs = rhs; return *this; } - - ResultInfoBuilder& ResultInfoBuilder::setOp( const std::string& op ) { - m_op = op; + ExpressionResultBuilder& ExpressionResultBuilder::setOp( const std::string& op ) { + m_exprComponents.op = op; return *this; } - - ResultInfo ResultInfoBuilder::build() const + AssertionResult ExpressionResultBuilder::buildResult( const AssertionInfo& info ) const { - ResultData data = m_data; - data.reconstructedExpression = reconstructExpression(); - if( m_isFalse ) { - if( m_op == "" ) { - data.capturedExpression = "!" + data.capturedExpression; + assert( m_data.resultType != ResultWas::Unknown ); + + AssertionResultData data = m_data; + + // Flip bool results if shouldNegate is set + if( m_exprComponents.shouldNegate && data.resultType == ResultWas::Ok ) + data.resultType = ResultWas::ExpressionFailed; + else if( m_exprComponents.shouldNegate && data.resultType == ResultWas::ExpressionFailed ) + data.resultType = ResultWas::Ok; + + data.message = m_stream.str(); + data.reconstructedExpression = reconstructExpression( info ); + if( m_exprComponents.shouldNegate ) { + if( m_exprComponents.op == "" ) data.reconstructedExpression = "!" + data.reconstructedExpression; - } - else { - data.capturedExpression = "!(" + data.capturedExpression + ")"; + else data.reconstructedExpression = "!(" + data.reconstructedExpression + ")"; - } } - return ResultInfo( data ); - } - - std::string ResultInfoBuilder::reconstructExpression() const { - if( m_op == "" ) - return m_lhs.empty() ? m_data.capturedExpression : m_op + m_lhs; - else if( m_op == "matches" ) - return m_lhs + " " + m_rhs; - else if( m_op != "!" ) { - if( m_lhs.size() + m_rhs.size() < 30 ) - return m_lhs + " " + m_op + " " + m_rhs; - else if( m_lhs.size() < 70 && m_rhs.size() < 70 ) - return "\n\t" + m_lhs + "\n\t" + m_op + "\n\t" + m_rhs; + return AssertionResult( info, data ); + } + std::string ExpressionResultBuilder::reconstructExpression( const AssertionInfo& info ) const { + if( m_exprComponents.op == "" ) + return m_exprComponents.lhs.empty() ? info.capturedExpression : m_exprComponents.op + m_exprComponents.lhs; + else if( m_exprComponents.op == "matches" ) + return m_exprComponents.lhs + " " + m_exprComponents.rhs; + else if( m_exprComponents.op != "!" ) { + if( m_exprComponents.lhs.size() + m_exprComponents.rhs.size() < 30 ) + return m_exprComponents.lhs + " " + m_exprComponents.op + " " + m_exprComponents.rhs; + else if( m_exprComponents.lhs.size() < 70 && m_exprComponents.rhs.size() < 70 ) + return "\n\t" + m_exprComponents.lhs + "\n\t" + m_exprComponents.op + "\n\t" + m_exprComponents.rhs; else - return "\n" + m_lhs + "\n" + m_op + "\n" + m_rhs + "\n\n"; + return "\n" + m_exprComponents.lhs + "\n" + m_exprComponents.op + "\n" + m_exprComponents.rhs + "\n\n"; } else - return "{can't expand - use " + m_data.macroName + "_FALSE( " + m_data.capturedExpression.substr(1) + " ) instead of " + m_data.macroName + "( " + m_data.capturedExpression + " ) for better diagnostics}"; + return "{can't expand - use " + info.macroName + "_FALSE( " + info.capturedExpression.substr(1) + " ) instead of " + info.macroName + "( " + info.capturedExpression + " ) for better diagnostics}"; } } // end namespace Catch @@ -5414,21 +5417,21 @@ namespace Catch { m_sectionSpans.pop_back(); } - virtual void Result( const ResultInfo& resultInfo ) { - if( !m_config.includeSuccessfulResults && resultInfo.getResultType() == ResultWas::Ok ) + virtual void Result( const AssertionResult& assertionResult ) { + if( !m_config.includeSuccessfulResults && assertionResult.getResultType() == ResultWas::Ok ) return; startSpansLazily(); - if( !resultInfo.getFilename().empty() ) { + if( !assertionResult.getSourceInfo().empty() ) { TextColour colour( TextColour::FileName ); - m_config.stream << SourceLineInfo( resultInfo.getFilename(), resultInfo.getLine() ); + m_config.stream << assertionResult.getSourceInfo(); } - if( resultInfo.hasExpression() ) { + if( assertionResult.hasExpression() ) { TextColour colour( TextColour::OriginalExpression ); - m_config.stream << resultInfo.getExpression(); - if( resultInfo.ok() ) { + m_config.stream << assertionResult.getExpression(); + if( assertionResult.ok() ) { TextColour successColour( TextColour::Success ); m_config.stream << " succeeded"; } @@ -5437,36 +5440,36 @@ namespace Catch { m_config.stream << " failed"; } } - switch( resultInfo.getResultType() ) { + switch( assertionResult.getResultType() ) { case ResultWas::ThrewException: { TextColour colour( TextColour::Error ); - if( resultInfo.hasExpression() ) + if( assertionResult.hasExpression() ) m_config.stream << " with unexpected"; else m_config.stream << "Unexpected"; - m_config.stream << " exception with message: '" << resultInfo.getMessage() << "'"; + m_config.stream << " exception with message: '" << assertionResult.getMessage() << "'"; } break; case ResultWas::DidntThrowException: { TextColour colour( TextColour::Error ); - if( resultInfo.hasExpression() ) + if( assertionResult.hasExpression() ) m_config.stream << " because no exception was thrown where one was expected"; else m_config.stream << "No exception thrown where one was expected"; } break; case ResultWas::Info: - streamVariableLengthText( "info", resultInfo.getMessage() ); + streamVariableLengthText( "info", assertionResult.getMessage() ); break; case ResultWas::Warning: - m_config.stream << "warning:\n'" << resultInfo.getMessage() << "'"; + streamVariableLengthText( "warning", assertionResult.getMessage() ); break; case ResultWas::ExplicitFailure: { TextColour colour( TextColour::Error ); - m_config.stream << "failed with message: '" << resultInfo.getMessage() << "'"; + m_config.stream << "failed with message: '" << assertionResult.getMessage() << "'"; } break; case ResultWas::Unknown: // These cases are here to prevent compiler warnings @@ -5474,8 +5477,8 @@ namespace Catch { case ResultWas::FailureBit: case ResultWas::ExpressionFailed: case ResultWas::Exception: - if( !resultInfo.hasExpression() ) { - if( resultInfo.ok() ) { + if( !assertionResult.hasExpression() ) { + if( assertionResult.ok() ) { TextColour colour( TextColour::Success ); m_config.stream << " succeeded"; } @@ -5487,14 +5490,14 @@ namespace Catch { break; } - if( resultInfo.hasExpandedExpression() ) { + if( assertionResult.hasExpandedExpression() ) { m_config.stream << " for: "; - if( resultInfo.getExpandedExpression().size() > 40 ) + if( assertionResult.getExpandedExpression().size() > 40 ) m_config.stream << "\n"; - if( resultInfo.getExpandedExpression().size() < 70 ) + if( assertionResult.getExpandedExpression().size() < 70 ) m_config.stream << "\t"; TextColour colour( TextColour::ReconstructedExpression ); - m_config.stream << resultInfo.getExpandedExpression(); + m_config.stream << assertionResult.getExpandedExpression(); } m_config.stream << std::endl; } @@ -5564,7 +5567,7 @@ namespace Catch { void streamVariableLengthText( const std::string& prefix, const std::string& text ) { std::string trimmed = trim( text ); if( trimmed.find_first_of( "\r\n" ) == std::string::npos ) { - m_config.stream << "[" << prefix << ": " << trimmed << "]\n"; + m_config.stream << "[" << prefix << ": " << trimmed << "]"; } else { m_config.stream << "\n[" << prefix << "] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n" << trimmed @@ -5853,42 +5856,42 @@ namespace Catch { m_currentTestSuccess = true; } - virtual void Result( const Catch::ResultInfo& resultInfo ) { - if( !m_config.includeSuccessfulResults && resultInfo.getResultType() == ResultWas::Ok ) + virtual void Result( const Catch::AssertionResult& assertionResult ) { + if( !m_config.includeSuccessfulResults && assertionResult.getResultType() == ResultWas::Ok ) return; - if( resultInfo.hasExpression() ) { + if( assertionResult.hasExpression() ) { m_xml.startElement( "Expression" ) - .writeAttribute( "success", resultInfo.ok() ) - .writeAttribute( "filename", resultInfo.getFilename() ) - .writeAttribute( "line", resultInfo.getLine() ); + .writeAttribute( "success", assertionResult.ok() ) + .writeAttribute( "filename", assertionResult.getSourceInfo().file ) + .writeAttribute( "line", assertionResult.getSourceInfo().line ); m_xml.scopedElement( "Original" ) - .writeText( resultInfo.getExpression() ); + .writeText( assertionResult.getExpression() ); m_xml.scopedElement( "Expanded" ) - .writeText( resultInfo.getExpandedExpression() ); - m_currentTestSuccess &= resultInfo.ok(); + .writeText( assertionResult.getExpandedExpression() ); + m_currentTestSuccess &= assertionResult.ok(); } - switch( resultInfo.getResultType() ) { + switch( assertionResult.getResultType() ) { case ResultWas::ThrewException: m_xml.scopedElement( "Exception" ) - .writeAttribute( "filename", resultInfo.getFilename() ) - .writeAttribute( "line", resultInfo.getLine() ) - .writeText( resultInfo.getMessage() ); + .writeAttribute( "filename", assertionResult.getSourceInfo().file ) + .writeAttribute( "line", assertionResult.getSourceInfo().line ) + .writeText( assertionResult.getMessage() ); m_currentTestSuccess = false; break; case ResultWas::Info: m_xml.scopedElement( "Info" ) - .writeText( resultInfo.getMessage() ); + .writeText( assertionResult.getMessage() ); break; case ResultWas::Warning: m_xml.scopedElement( "Warning" ) - .writeText( resultInfo.getMessage() ); + .writeText( assertionResult.getMessage() ); break; case ResultWas::ExplicitFailure: m_xml.scopedElement( "Failure" ) - .writeText( resultInfo.getMessage() ); + .writeText( assertionResult.getMessage() ); m_currentTestSuccess = false; break; case ResultWas::Unknown: @@ -5899,7 +5902,7 @@ namespace Catch { case ResultWas::DidntThrowException: break; } - if( resultInfo.hasExpression() ) + if( assertionResult.hasExpression() ) m_xml.endElement(); } @@ -6007,19 +6010,19 @@ namespace Catch { m_currentStats->m_testCaseStats.push_back( TestCaseStats( testInfo.getName() ) ); } - virtual void Result( const Catch::ResultInfo& resultInfo ) { - if( resultInfo.getResultType() != ResultWas::Ok || m_config.includeSuccessfulResults ) { + virtual void Result( const Catch::AssertionResult& assertionResult ) { + if( assertionResult.getResultType() != ResultWas::Ok || m_config.includeSuccessfulResults ) { TestCaseStats& testCaseStats = m_currentStats->m_testCaseStats.back(); TestStats stats; std::ostringstream oss; - if( !resultInfo.getMessage().empty() ) - oss << resultInfo.getMessage() << " at "; - oss << SourceLineInfo( resultInfo.getFilename(), resultInfo.getLine() ); + if( !assertionResult.getMessage().empty() ) + oss << assertionResult.getMessage() << " at "; + oss << assertionResult.getSourceInfo(); stats.m_content = oss.str(); - stats.m_message = resultInfo.getExpandedExpression(); - stats.m_resultType = resultInfo.getTestMacroName(); + stats.m_message = assertionResult.getExpandedExpression(); + stats.m_resultType = assertionResult.getTestMacroName(); - switch( resultInfo.getResultType() ) { + switch( assertionResult.getResultType() ) { case ResultWas::ThrewException: stats.m_element = "error"; m_currentStats->m_errorsCount++; @@ -6244,9 +6247,9 @@ int main (int argc, char * const argv[]) { #define CATCH_WARN( msg ) INTERNAL_CATCH_MSG( msg, Catch::ResultWas::Warning, false, "CATCH_WARN" ) #define CATCH_FAIL( msg ) INTERNAL_CATCH_MSG( msg, Catch::ResultWas::ExplicitFailure, true, "CATCH_FAIL" ) #define CATCH_SUCCEED( msg ) INTERNAL_CATCH_MSG( msg, Catch::ResultWas::Ok, false, "CATCH_SUCCEED" ) -#define CATCH_SCOPED_INFO( msg ) INTERNAL_CATCH_SCOPED_INFO( msg ) +#define CATCH_SCOPED_INFO( msg ) INTERNAL_CATCH_SCOPED_INFO( msg, "CATCH_SCOPED_INFO" ) #define CATCH_CAPTURE( msg ) INTERNAL_CATCH_MSG( #msg " := " << msg, Catch::ResultWas::Info, false, "CATCH_CAPTURE" ) -#define CATCH_SCOPED_CAPTURE( msg ) INTERNAL_CATCH_SCOPED_INFO( #msg " := " << msg ) +#define CATCH_SCOPED_CAPTURE( msg ) INTERNAL_CATCH_SCOPED_INFO( #msg " := " << msg, "CATCH_SCOPED_CAPTURE" ) #define CATCH_SECTION( name, description ) INTERNAL_CATCH_SECTION( name, description ) @@ -6289,9 +6292,9 @@ int main (int argc, char * const argv[]) { #define WARN( msg ) INTERNAL_CATCH_MSG( msg, Catch::ResultWas::Warning, false, "WARN" ) #define FAIL( msg ) INTERNAL_CATCH_MSG( msg, Catch::ResultWas::ExplicitFailure, true, "FAIL" ) #define SUCCEED( msg ) INTERNAL_CATCH_MSG( msg, Catch::ResultWas::Ok, false, "SUCCEED" ) -#define SCOPED_INFO( msg ) INTERNAL_CATCH_SCOPED_INFO( msg ) +#define SCOPED_INFO( msg ) INTERNAL_CATCH_SCOPED_INFO( msg, "SCOPED_INFO" ) #define CAPTURE( msg ) INTERNAL_CATCH_MSG( #msg " := " << msg, Catch::ResultWas::Info, false, "CAPTURE" ) -#define SCOPED_CAPTURE( msg ) INTERNAL_CATCH_SCOPED_INFO( #msg " := " << msg ) +#define SCOPED_CAPTURE( msg ) INTERNAL_CATCH_SCOPED_INFO( #msg " := " << msg, "SCOPED_CAPTURE" ) #define SECTION( name, description ) INTERNAL_CATCH_SECTION( name, description )