mirror of
https://github.com/catchorg/Catch2.git
synced 2025-05-31 17:07:52 +00:00
Factored MutableResultInfo into its own file
This commit is contained in:
parent
5d1c8f2c6d
commit
b5d367206b
3 changed files with 111 additions and 147 deletions
|
@ -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<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:
|
||||
friend class ResultBuilder;
|
||||
template<typename T> friend class Expression;
|
||||
|
||||
template<typename T> 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<Internal::Operator Op, typename T1, typename T2>
|
||||
MutableResultInfo& captureExpression
|
||||
(
|
||||
const T1& lhs,
|
||||
const T2& rhs
|
||||
)
|
||||
{
|
||||
setResultType( Internal::compare<Op>( lhs, rhs ) ? ResultWas::Ok : ResultWas::ExpressionFailed );
|
||||
m_lhs = Catch::toString( lhs );
|
||||
m_rhs = Catch::toString( rhs );
|
||||
m_op = Internal::OperatorTraits<Op>::getName();
|
||||
return *this;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template<Internal::Operator Op, typename T>
|
||||
MutableResultInfo& captureExpression
|
||||
(
|
||||
const T* lhs,
|
||||
int rhs
|
||||
)
|
||||
{
|
||||
return captureExpression<Op>( lhs, reinterpret_cast<const T*>( rhs ) );
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class Expression
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue