mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 13:26:10 +01:00
Moved ResultBuilder out into its own file
This commit is contained in:
parent
6217966743
commit
7a0cadc342
@ -8,169 +8,17 @@
|
||||
#ifndef TWOBLUECUBES_CATCH_CAPTURE_HPP_INCLUDED
|
||||
#define TWOBLUECUBES_CATCH_CAPTURE_HPP_INCLUDED
|
||||
|
||||
#include "catch_expression.hpp"
|
||||
#include "catch_resultinfo_builder.hpp"
|
||||
#include "catch_tostring.hpp"
|
||||
#include "catch_resultinfo.hpp"
|
||||
#include "catch_result_type.h"
|
||||
#include "catch_expression_builder.hpp"
|
||||
#include "catch_interfaces_capture.h"
|
||||
#include "catch_debugger.hpp"
|
||||
#include "catch_evaluate.hpp"
|
||||
#include "catch_context.h"
|
||||
#include "catch_common.h"
|
||||
#include <sstream>
|
||||
#include <ostream>
|
||||
|
||||
namespace Catch
|
||||
{
|
||||
|
||||
struct TestFailureException{};
|
||||
struct DummyExceptionType_DontUse{};
|
||||
|
||||
class ResultBuilder
|
||||
{
|
||||
public:
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
ResultBuilder
|
||||
(
|
||||
const SourceLineInfo& lineInfo,
|
||||
const char* macroName,
|
||||
const char* expr = "",
|
||||
bool isNot = false
|
||||
)
|
||||
: m_result( expr, isNot, lineInfo, macroName ),
|
||||
m_messageStream()
|
||||
{}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
Expression<const T&> operator->*
|
||||
(
|
||||
const T & operand
|
||||
)
|
||||
{
|
||||
Expression<const T&> expr( m_result, operand );
|
||||
|
||||
return expr;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
Expression<const char*> operator->*
|
||||
(
|
||||
const char* const& operand
|
||||
)
|
||||
{
|
||||
Expression<const char*> expr( m_result, operand );
|
||||
|
||||
return expr;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
PtrExpression<T> operator->*
|
||||
(
|
||||
const T* operand
|
||||
)
|
||||
{
|
||||
PtrExpression<T> expr( m_result, operand );
|
||||
|
||||
return expr;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
PtrExpression<T> operator->*
|
||||
(
|
||||
T* operand
|
||||
)
|
||||
{
|
||||
PtrExpression<T> expr( m_result, operand );
|
||||
|
||||
return expr;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
Expression<bool> operator->*
|
||||
(
|
||||
bool value
|
||||
)
|
||||
{
|
||||
Expression<bool> expr( m_result, value );
|
||||
return expr;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
ResultBuilder& operator <<
|
||||
(
|
||||
const T & value
|
||||
)
|
||||
{
|
||||
m_messageStream << Catch::toString( value );
|
||||
return *this;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template<typename MatcherT, typename ArgT>
|
||||
ResultBuilder& acceptMatcher
|
||||
(
|
||||
const MatcherT& matcher,
|
||||
const ArgT& arg,
|
||||
const std::string& matcherCallAsString
|
||||
)
|
||||
{
|
||||
std::string matcherAsString = Catch::toString( matcher );
|
||||
if( matcherAsString == "{?}" )
|
||||
matcherAsString = matcherCallAsString;
|
||||
m_result.setLhs( Catch::toString( arg ) );
|
||||
m_result.setRhs( matcherAsString );
|
||||
m_result.setOp( "matches" );
|
||||
m_result.setResultType( matcher( arg ) ? ResultWas::Ok : ResultWas::ExpressionFailed );
|
||||
return *this;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template<typename MatcherT, typename ArgT>
|
||||
ResultBuilder& acceptMatcher
|
||||
(
|
||||
const MatcherT& matcher,
|
||||
ArgT* arg,
|
||||
const std::string& matcherCallAsString
|
||||
)
|
||||
{
|
||||
std::string matcherAsString = Catch::toString( matcher );
|
||||
if( matcherAsString == "{?}" )
|
||||
matcherAsString = matcherCallAsString;
|
||||
m_result.setLhs( Catch::toString( arg ) );
|
||||
m_result.setRhs( matcherAsString );
|
||||
m_result.setOp( "matches" );
|
||||
m_result.setResultType( matcher( arg ) ? ResultWas::Ok : ResultWas::ExpressionFailed );
|
||||
return *this;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
ResultBuilder& setResultType
|
||||
(
|
||||
ResultWas::OfType resultType
|
||||
)
|
||||
{
|
||||
m_result.setResultType( resultType );
|
||||
return *this;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
operator ResultInfoBuilder&
|
||||
()
|
||||
{
|
||||
m_result.setMessage( m_messageStream.str() );
|
||||
return m_result;
|
||||
}
|
||||
|
||||
private:
|
||||
ResultInfoBuilder m_result;
|
||||
std::ostringstream m_messageStream;
|
||||
|
||||
};
|
||||
|
||||
class ScopedInfo
|
||||
{
|
||||
|
170
include/internal/catch_expression_builder.hpp
Normal file
170
include/internal/catch_expression_builder.hpp
Normal file
@ -0,0 +1,170 @@
|
||||
/*
|
||||
* Created by Phil on 11/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_EXPRESSION_BUILDER_HPP_INCLUDED
|
||||
#define TWOBLUECUBES_CATCH_EXPRESSION_BUILDER_HPP_INCLUDED
|
||||
|
||||
#include "catch_expression.hpp"
|
||||
#include "catch_resultinfo_builder.hpp"
|
||||
#include "catch_tostring.hpp"
|
||||
#include "catch_resultinfo.hpp"
|
||||
#include "catch_result_type.h"
|
||||
#include "catch_context.h"
|
||||
#include "catch_common.h"
|
||||
#include <sstream>
|
||||
|
||||
namespace Catch
|
||||
{
|
||||
|
||||
class ResultBuilder
|
||||
{
|
||||
public:
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
ResultBuilder
|
||||
(
|
||||
const SourceLineInfo& lineInfo,
|
||||
const char* macroName,
|
||||
const char* expr = "",
|
||||
bool isNot = false
|
||||
)
|
||||
: m_result( expr, isNot, lineInfo, macroName ),
|
||||
m_messageStream()
|
||||
{}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
Expression<const T&> operator->*
|
||||
(
|
||||
const T & operand
|
||||
)
|
||||
{
|
||||
Expression<const T&> expr( m_result, operand );
|
||||
|
||||
return expr;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
Expression<const char*> operator->*
|
||||
(
|
||||
const char* const& operand
|
||||
)
|
||||
{
|
||||
Expression<const char*> expr( m_result, operand );
|
||||
|
||||
return expr;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
PtrExpression<T> operator->*
|
||||
(
|
||||
const T* operand
|
||||
)
|
||||
{
|
||||
PtrExpression<T> expr( m_result, operand );
|
||||
|
||||
return expr;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
PtrExpression<T> operator->*
|
||||
(
|
||||
T* operand
|
||||
)
|
||||
{
|
||||
PtrExpression<T> expr( m_result, operand );
|
||||
|
||||
return expr;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
Expression<bool> operator->*
|
||||
(
|
||||
bool value
|
||||
)
|
||||
{
|
||||
Expression<bool> expr( m_result, value );
|
||||
return expr;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
ResultBuilder& operator <<
|
||||
(
|
||||
const T & value
|
||||
)
|
||||
{
|
||||
m_messageStream << Catch::toString( value );
|
||||
return *this;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template<typename MatcherT, typename ArgT>
|
||||
ResultBuilder& acceptMatcher
|
||||
(
|
||||
const MatcherT& matcher,
|
||||
const ArgT& arg,
|
||||
const std::string& matcherCallAsString
|
||||
)
|
||||
{
|
||||
std::string matcherAsString = Catch::toString( matcher );
|
||||
if( matcherAsString == "{?}" )
|
||||
matcherAsString = matcherCallAsString;
|
||||
m_result.setLhs( Catch::toString( arg ) );
|
||||
m_result.setRhs( matcherAsString );
|
||||
m_result.setOp( "matches" );
|
||||
m_result.setResultType( matcher( arg ) ? ResultWas::Ok : ResultWas::ExpressionFailed );
|
||||
return *this;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template<typename MatcherT, typename ArgT>
|
||||
ResultBuilder& acceptMatcher
|
||||
(
|
||||
const MatcherT& matcher,
|
||||
ArgT* arg,
|
||||
const std::string& matcherCallAsString
|
||||
)
|
||||
{
|
||||
std::string matcherAsString = Catch::toString( matcher );
|
||||
if( matcherAsString == "{?}" )
|
||||
matcherAsString = matcherCallAsString;
|
||||
m_result.setLhs( Catch::toString( arg ) );
|
||||
m_result.setRhs( matcherAsString );
|
||||
m_result.setOp( "matches" );
|
||||
m_result.setResultType( matcher( arg ) ? ResultWas::Ok : ResultWas::ExpressionFailed );
|
||||
return *this;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
ResultBuilder& setResultType
|
||||
(
|
||||
ResultWas::OfType resultType
|
||||
)
|
||||
{
|
||||
m_result.setResultType( resultType );
|
||||
return *this;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
operator ResultInfoBuilder&
|
||||
()
|
||||
{
|
||||
m_result.setMessage( m_messageStream.str() );
|
||||
return m_result;
|
||||
}
|
||||
|
||||
private:
|
||||
ResultInfoBuilder m_result;
|
||||
std::ostringstream m_messageStream;
|
||||
};
|
||||
|
||||
} // end namespace Catch
|
||||
|
||||
#endif // TWOBLUECUBES_CATCH_EXPRESSION_BUILDER_HPP_INCLUDED
|
@ -93,6 +93,7 @@
|
||||
4AB77CB71553B72B00857BF0 /* catch_section_info.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = catch_section_info.hpp; sourceTree = "<group>"; };
|
||||
4AB77CB81553BB3800857BF0 /* catch_running_test.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = catch_running_test.hpp; sourceTree = "<group>"; };
|
||||
4AC91CCE155CF02800DC5117 /* catch_expression.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = catch_expression.hpp; sourceTree = "<group>"; };
|
||||
4AC91CD0155D8DA600DC5117 /* catch_expression_builder.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = catch_expression_builder.hpp; sourceTree = "<group>"; };
|
||||
4AE1840A14EE4F230066340D /* catch_self_test.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = catch_self_test.cpp; path = ../../../SelfTest/catch_self_test.cpp; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
@ -216,6 +217,7 @@
|
||||
4A6D0C46149B3E3D00DB3EAA /* catch_approx.hpp */,
|
||||
4A6D0C47149B3E3D00DB3EAA /* catch_capture.hpp */,
|
||||
4AC91CCE155CF02800DC5117 /* catch_expression.hpp */,
|
||||
4AC91CD0155D8DA600DC5117 /* catch_expression_builder.hpp */,
|
||||
);
|
||||
name = Assertions;
|
||||
sourceTree = "<group>";
|
||||
|
Loading…
Reference in New Issue
Block a user