diff --git a/include/internal/catch_capture.hpp b/include/internal/catch_capture.hpp index 32928163..45362eb4 100644 --- a/include/internal/catch_capture.hpp +++ b/include/internal/catch_capture.hpp @@ -1,17 +1,14 @@ /* - * catch_capture.hpp - * Catch - * * Created by Phil on 18/10/2010. * Copyright 2010 Two Blue Cubes Ltd. All rights reserved. * * Distributed under the Boost Software License, Version 1.0. (See accompanying * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - * */ #ifndef TWOBLUECUBES_CATCH_CAPTURE_HPP_INCLUDED #define TWOBLUECUBES_CATCH_CAPTURE_HPP_INCLUDED +#include "catch_resultinfo_builder.hpp" #include "catch_tostring.hpp" #include "catch_resultinfo.hpp" #include "catch_result_type.h" @@ -28,149 +25,6 @@ namespace Catch struct TestFailureException{}; struct DummyExceptionType_DontUse{}; -struct STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison; - -class MutableResultInfo : public ResultInfo -{ -public: - - /////////////////////////////////////////////////////////////////////////// - MutableResultInfo - () - {} - - /////////////////////////////////////////////////////////////////////////// - MutableResultInfo - ( - const char* expr, - bool isNot, - const SourceLineInfo& lineInfo, - const char* macroName, - const char* message = "" - ) - : ResultInfo( expr, ResultWas::Unknown, isNot, lineInfo, macroName, message ) - { - } - - /////////////////////////////////////////////////////////////////////////// - void setResultType - ( - ResultWas::OfType result - ) - { - // Flip bool results if isNot is set - if( m_isNot && result == ResultWas::Ok ) - m_result = ResultWas::ExpressionFailed; - else if( m_isNot && result == ResultWas::ExpressionFailed ) - m_result = ResultWas::Ok; - else - m_result = result; - } - - /////////////////////////////////////////////////////////////////////////// - void setMessage - ( - const std::string& message - ) - { - m_message = message; - } - - /////////////////////////////////////////////////////////////////////////// - void setLineInfo - ( - const SourceLineInfo& lineInfo - ) - { - m_lineInfo = lineInfo; - } - - /////////////////////////////////////////////////////////////////////////// - void setLhs - ( - const std::string& lhs - ) - { - m_lhs = lhs; - } - - /////////////////////////////////////////////////////////////////////////// - void setRhs - ( - const std::string& rhs - ) - { - m_rhs = rhs; - } - - /////////////////////////////////////////////////////////////////////////// - void setOp - ( - const std::string& op - ) - { - m_op = op; - } - - /////////////////////////////////////////////////////////////////////////// - template - STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator || - ( - const RhsT& - ); - - /////////////////////////////////////////////////////////////////////////// - template - STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator && - ( - const RhsT& - ); - -private: - friend class ResultBuilder; - template friend class Expression; - - template friend class PtrExpression; - - /////////////////////////////////////////////////////////////////////////// - MutableResultInfo& captureBoolExpression - ( - bool result - ) - { - m_lhs = Catch::toString( result ); - m_op = m_isNot ? "!" : ""; - setResultType( result ? ResultWas::Ok : ResultWas::ExpressionFailed ); - return *this; - } - - /////////////////////////////////////////////////////////////////////////// - template - MutableResultInfo& captureExpression - ( - const T1& lhs, - const T2& rhs - ) - { - setResultType( Internal::compare( lhs, rhs ) ? ResultWas::Ok : ResultWas::ExpressionFailed ); - m_lhs = Catch::toString( lhs ); - m_rhs = Catch::toString( rhs ); - m_op = Internal::OperatorTraits::getName(); - return *this; - } - - /////////////////////////////////////////////////////////////////////////// - template - MutableResultInfo& captureExpression - ( - const T* lhs, - int rhs - ) - { - return captureExpression( lhs, reinterpret_cast( rhs ) ); - } -}; - template class Expression { diff --git a/include/internal/catch_resultinfo_builder.hpp b/include/internal/catch_resultinfo_builder.hpp new file mode 100644 index 00000000..96923ecc --- /dev/null +++ b/include/internal/catch_resultinfo_builder.hpp @@ -0,0 +1,108 @@ +/* + * Created by Phil on 8/5/2012. + * Copyright 2012 Two Blue Cubes Ltd. All rights reserved. + * + * Distributed under the Boost Software License, Version 1.0. (See accompanying + * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + */ +#ifndef TWOBLUECUBES_CATCH_RESULTINFO_BUILDER_HPP_INCLUDED +#define TWOBLUECUBES_CATCH_RESULTINFO_BUILDER_HPP_INCLUDED + +#include "catch_tostring.hpp" +#include "catch_resultinfo.hpp" +#include "catch_result_type.h" +#include "catch_evaluate.hpp" +#include "catch_common.h" + +namespace Catch +{ + +struct STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison; + +class MutableResultInfo : public ResultInfo +{ +public: + + MutableResultInfo() {} + + MutableResultInfo( const char* expr, + bool isNot, + const SourceLineInfo& lineInfo, + const char* macroName, + const char* message = "" ) + : ResultInfo( expr, ResultWas::Unknown, isNot, lineInfo, macroName, message ) + {} + + void setResultType( ResultWas::OfType result ) { + // Flip bool results if isNot is set + if( m_isNot && result == ResultWas::Ok ) + m_result = ResultWas::ExpressionFailed; + else if( m_isNot && result == ResultWas::ExpressionFailed ) + m_result = ResultWas::Ok; + else + m_result = result; + } + + void setMessage( const std::string& message ) { + m_message = message; + } + + void setLineInfo( const SourceLineInfo& lineInfo ) { + m_lineInfo = lineInfo; + } + + void setLhs( const std::string& lhs ) { + m_lhs = lhs; + } + + void setRhs( const std::string& rhs ) { + m_rhs = rhs; + } + + void setOp( const std::string& op ) { + m_op = op; + } + + template + STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator || + ( + const RhsT& + ); + + template + STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator && + ( + const RhsT& + ); + +private: + friend class ResultBuilder; + template friend class Expression; + + template friend class PtrExpression; + + MutableResultInfo& captureBoolExpression( bool result ) { + m_lhs = Catch::toString( result ); + m_op = m_isNot ? "!" : ""; + setResultType( result ? ResultWas::Ok : ResultWas::ExpressionFailed ); + return *this; + } + + template + MutableResultInfo& captureExpression( const T1& lhs, const T2& rhs ) { + setResultType( Internal::compare( lhs, rhs ) ? ResultWas::Ok : ResultWas::ExpressionFailed ); + m_lhs = Catch::toString( lhs ); + m_rhs = Catch::toString( rhs ); + m_op = Internal::OperatorTraits::getName(); + return *this; + } + + template + MutableResultInfo& captureExpression( const T* lhs, int rhs ) { + return captureExpression( lhs, reinterpret_cast( rhs ) ); + } +}; + +} // end namespace Catch + +#endif // TWOBLUECUBES_CATCH_RESULTINFO_BUILDER_HPP_INCLUDED diff --git a/projects/XCode4/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj b/projects/XCode4/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj index 92672ce3..d879996a 100644 --- a/projects/XCode4/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj +++ b/projects/XCode4/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj @@ -86,6 +86,7 @@ 4A6D0C68149B3E3D00DB3EAA /* catch_reporter_xml.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = catch_reporter_xml.hpp; sourceTree = ""; }; 4A7ADB4314F631E10094FE10 /* catch_totals.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = catch_totals.hpp; sourceTree = ""; }; 4A9D84B11558FC0400FBB209 /* catch_tostring.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = catch_tostring.hpp; sourceTree = ""; }; + 4A9D84B315599AC900FBB209 /* catch_resultinfo_builder.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = catch_resultinfo_builder.hpp; sourceTree = ""; }; 4AB1C73514F97BDA00F31DF7 /* catch_console_colour_impl.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = catch_console_colour_impl.hpp; sourceTree = ""; }; 4AB1C73714F97C1300F31DF7 /* catch_console_colour.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = catch_console_colour.hpp; sourceTree = ""; }; 4AB77CB51551AEA200857BF0 /* catch_ptr.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = catch_ptr.hpp; sourceTree = ""; }; @@ -188,6 +189,7 @@ 4A6D0C5B149B3E3D00DB3EAA /* catch_reporter_registry.hpp */, 4A6D0C5C149B3E3D00DB3EAA /* catch_result_type.h */, 4A6D0C5D149B3E3D00DB3EAA /* catch_resultinfo.hpp */, + 4A9D84B315599AC900FBB209 /* catch_resultinfo_builder.hpp */, 4A6D0C5E149B3E3D00DB3EAA /* catch_runner_impl.hpp */, 4A6D0C5F149B3E3D00DB3EAA /* catch_section.hpp */, 4A6D0C60149B3E3D00DB3EAA /* catch_stream.hpp */,