mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-08 23:29:53 +01:00
Separated resultinfo_builder from impl
This commit is contained in:
parent
ffe986d4ee
commit
c436a4dac1
@ -8,7 +8,7 @@
|
|||||||
#ifndef TWOBLUECUBES_CATCH_EXPRESSION_HPP_INCLUDED
|
#ifndef TWOBLUECUBES_CATCH_EXPRESSION_HPP_INCLUDED
|
||||||
#define TWOBLUECUBES_CATCH_EXPRESSION_HPP_INCLUDED
|
#define TWOBLUECUBES_CATCH_EXPRESSION_HPP_INCLUDED
|
||||||
|
|
||||||
#include "catch_resultinfo_builder.hpp"
|
#include "catch_resultinfo_builder.h"
|
||||||
#include "catch_evaluate.hpp"
|
#include "catch_evaluate.hpp"
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
#define TWOBLUECUBES_CATCH_EXPRESSION_BUILDER_HPP_INCLUDED
|
#define TWOBLUECUBES_CATCH_EXPRESSION_BUILDER_HPP_INCLUDED
|
||||||
|
|
||||||
#include "catch_expression.hpp"
|
#include "catch_expression.hpp"
|
||||||
#include "catch_resultinfo_builder.hpp"
|
#include "catch_resultinfo_builder.h"
|
||||||
#include "catch_tostring.hpp"
|
#include "catch_tostring.hpp"
|
||||||
#include "catch_resultinfo.h"
|
#include "catch_resultinfo.h"
|
||||||
#include "catch_result_type.h"
|
#include "catch_result_type.h"
|
||||||
|
@ -14,3 +14,4 @@
|
|||||||
#include "catch_console_colour_impl.hpp"
|
#include "catch_console_colour_impl.hpp"
|
||||||
#include "catch_generators_impl.hpp"
|
#include "catch_generators_impl.hpp"
|
||||||
#include "catch_resultinfo.hpp"
|
#include "catch_resultinfo.hpp"
|
||||||
|
#include "catch_resultinfo_builder.hpp"
|
||||||
|
77
include/internal/catch_resultinfo_builder.h
Normal file
77
include/internal/catch_resultinfo_builder.h
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* 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_H_INCLUDED
|
||||||
|
#define TWOBLUECUBES_CATCH_RESULTINFO_BUILDER_H_INCLUDED
|
||||||
|
|
||||||
|
#include "catch_tostring.hpp"
|
||||||
|
#include "catch_resultinfo.h"
|
||||||
|
#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 ResultInfoBuilder : public ResultInfo {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
ResultInfoBuilder();
|
||||||
|
|
||||||
|
ResultInfoBuilder( const char* expr,
|
||||||
|
bool isNot,
|
||||||
|
const SourceLineInfo& lineInfo,
|
||||||
|
const char* macroName,
|
||||||
|
const char* message = "" );
|
||||||
|
|
||||||
|
void setResultType( ResultWas::OfType result );
|
||||||
|
void setMessage( const std::string& message );
|
||||||
|
void setLineInfo( const SourceLineInfo& lineInfo );
|
||||||
|
void setLhs( const std::string& lhs );
|
||||||
|
void setRhs( const std::string& rhs );
|
||||||
|
void setOp( const std::string& 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 ExpressionBuilder;
|
||||||
|
template<typename T> friend class Expression;
|
||||||
|
|
||||||
|
template<typename T> friend class PtrExpression;
|
||||||
|
|
||||||
|
ResultInfoBuilder& captureBoolExpression( bool result );
|
||||||
|
|
||||||
|
template<Internal::Operator Op, typename T1, typename T2>
|
||||||
|
ResultInfoBuilder& 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>
|
||||||
|
ResultInfoBuilder& captureExpression( const T* lhs, int rhs ) {
|
||||||
|
return captureExpression<Op>( lhs, reinterpret_cast<const T*>( rhs ) );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // end namespace Catch
|
||||||
|
|
||||||
|
#endif // TWOBLUECUBES_CATCH_RESULTINFO_BUILDER_H_INCLUDED
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Created by Phil on 8/5/2012.
|
* Created by Phil on 8/8/2012.
|
||||||
* Copyright 2012 Two Blue Cubes Ltd. All rights reserved.
|
* Copyright 2012 Two Blue Cubes Ltd. All rights reserved.
|
||||||
*
|
*
|
||||||
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
@ -8,31 +8,21 @@
|
|||||||
#ifndef TWOBLUECUBES_CATCH_RESULTINFO_BUILDER_HPP_INCLUDED
|
#ifndef TWOBLUECUBES_CATCH_RESULTINFO_BUILDER_HPP_INCLUDED
|
||||||
#define TWOBLUECUBES_CATCH_RESULTINFO_BUILDER_HPP_INCLUDED
|
#define TWOBLUECUBES_CATCH_RESULTINFO_BUILDER_HPP_INCLUDED
|
||||||
|
|
||||||
#include "catch_tostring.hpp"
|
#include "catch_resultinfo_builder.h"
|
||||||
#include "catch_resultinfo.h"
|
|
||||||
#include "catch_result_type.h"
|
|
||||||
#include "catch_evaluate.hpp"
|
|
||||||
#include "catch_common.h"
|
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
struct STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison;
|
ResultInfoBuilder::ResultInfoBuilder() {}
|
||||||
|
|
||||||
class ResultInfoBuilder : public ResultInfo {
|
ResultInfoBuilder::ResultInfoBuilder( const char* expr,
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
ResultInfoBuilder() {}
|
|
||||||
|
|
||||||
ResultInfoBuilder( const char* expr,
|
|
||||||
bool isNot,
|
bool isNot,
|
||||||
const SourceLineInfo& lineInfo,
|
const SourceLineInfo& lineInfo,
|
||||||
const char* macroName,
|
const char* macroName,
|
||||||
const char* message = "" )
|
const char* message )
|
||||||
: ResultInfo( expr, ResultWas::Unknown, isNot, lineInfo, macroName, message )
|
: ResultInfo( expr, ResultWas::Unknown, isNot, lineInfo, macroName, message )
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void setResultType( ResultWas::OfType result ) {
|
void ResultInfoBuilder::setResultType( ResultWas::OfType result ) {
|
||||||
// Flip bool results if isNot is set
|
// Flip bool results if isNot is set
|
||||||
if( m_isNot && result == ResultWas::Ok )
|
if( m_isNot && result == ResultWas::Ok )
|
||||||
m_result = ResultWas::ExpressionFailed;
|
m_result = ResultWas::ExpressionFailed;
|
||||||
@ -42,66 +32,33 @@ public:
|
|||||||
m_result = result;
|
m_result = result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setMessage( const std::string& message ) {
|
void ResultInfoBuilder::setMessage( const std::string& message ) {
|
||||||
m_message = message;
|
m_message = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setLineInfo( const SourceLineInfo& lineInfo ) {
|
void ResultInfoBuilder::setLineInfo( const SourceLineInfo& lineInfo ) {
|
||||||
m_lineInfo = lineInfo;
|
m_lineInfo = lineInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setLhs( const std::string& lhs ) {
|
void ResultInfoBuilder::setLhs( const std::string& lhs ) {
|
||||||
m_lhs = lhs;
|
m_lhs = lhs;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setRhs( const std::string& rhs ) {
|
void ResultInfoBuilder::setRhs( const std::string& rhs ) {
|
||||||
m_rhs = rhs;
|
m_rhs = rhs;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setOp( const std::string& op ) {
|
void ResultInfoBuilder::setOp( const std::string& op ) {
|
||||||
m_op = op;
|
m_op = op;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename RhsT>
|
ResultInfoBuilder& ResultInfoBuilder::captureBoolExpression( bool result ) {
|
||||||
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 ExpressionBuilder;
|
|
||||||
template<typename T> friend class Expression;
|
|
||||||
|
|
||||||
template<typename T> friend class PtrExpression;
|
|
||||||
|
|
||||||
ResultInfoBuilder& captureBoolExpression( bool result ) {
|
|
||||||
m_lhs = Catch::toString( result );
|
m_lhs = Catch::toString( result );
|
||||||
m_op = m_isNot ? "!" : "";
|
m_op = m_isNot ? "!" : "";
|
||||||
setResultType( result ? ResultWas::Ok : ResultWas::ExpressionFailed );
|
setResultType( result ? ResultWas::Ok : ResultWas::ExpressionFailed );
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<Internal::Operator Op, typename T1, typename T2>
|
|
||||||
ResultInfoBuilder& 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>
|
|
||||||
ResultInfoBuilder& captureExpression( const T* lhs, int rhs ) {
|
|
||||||
return captureExpression<Op>( lhs, reinterpret_cast<const T*>( rhs ) );
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
} // end namespace Catch
|
} // end namespace Catch
|
||||||
|
|
||||||
#endif // TWOBLUECUBES_CATCH_RESULTINFO_BUILDER_HPP_INCLUDED
|
#endif // TWOBLUECUBES_CATCH_RESULTINFO_BUILDER_HPP_INCLUDED
|
||||||
|
@ -92,8 +92,9 @@
|
|||||||
4A7ADB4314F631E10094FE10 /* catch_totals.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = catch_totals.hpp; sourceTree = "<group>"; };
|
4A7ADB4314F631E10094FE10 /* catch_totals.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = catch_totals.hpp; sourceTree = "<group>"; };
|
||||||
4A90B59B15D0F61A00EF71BC /* catch_interfaces_generators.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = catch_interfaces_generators.h; sourceTree = "<group>"; };
|
4A90B59B15D0F61A00EF71BC /* catch_interfaces_generators.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = catch_interfaces_generators.h; sourceTree = "<group>"; };
|
||||||
4A90B59D15D24FE900EF71BC /* catch_resultinfo.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = catch_resultinfo.hpp; sourceTree = "<group>"; };
|
4A90B59D15D24FE900EF71BC /* catch_resultinfo.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = catch_resultinfo.hpp; sourceTree = "<group>"; };
|
||||||
|
4A90B59E15D2521E00EF71BC /* catch_resultinfo_builder.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = catch_resultinfo_builder.hpp; sourceTree = "<group>"; };
|
||||||
4A9D84B11558FC0400FBB209 /* catch_tostring.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = catch_tostring.hpp; sourceTree = "<group>"; };
|
4A9D84B11558FC0400FBB209 /* catch_tostring.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = catch_tostring.hpp; sourceTree = "<group>"; };
|
||||||
4A9D84B315599AC900FBB209 /* catch_resultinfo_builder.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = catch_resultinfo_builder.hpp; sourceTree = "<group>"; };
|
4A9D84B315599AC900FBB209 /* catch_resultinfo_builder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = catch_resultinfo_builder.h; sourceTree = "<group>"; };
|
||||||
4AB1C73514F97BDA00F31DF7 /* catch_console_colour_impl.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = catch_console_colour_impl.hpp; sourceTree = "<group>"; };
|
4AB1C73514F97BDA00F31DF7 /* catch_console_colour_impl.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = catch_console_colour_impl.hpp; sourceTree = "<group>"; };
|
||||||
4AB1C73714F97C1300F31DF7 /* catch_console_colour.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = catch_console_colour.hpp; sourceTree = "<group>"; };
|
4AB1C73714F97C1300F31DF7 /* catch_console_colour.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = catch_console_colour.hpp; sourceTree = "<group>"; };
|
||||||
4AB77CB51551AEA200857BF0 /* catch_ptr.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = catch_ptr.hpp; sourceTree = "<group>"; };
|
4AB77CB51551AEA200857BF0 /* catch_ptr.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = catch_ptr.hpp; sourceTree = "<group>"; };
|
||||||
@ -212,6 +213,7 @@
|
|||||||
4AB1C73514F97BDA00F31DF7 /* catch_console_colour_impl.hpp */,
|
4AB1C73514F97BDA00F31DF7 /* catch_console_colour_impl.hpp */,
|
||||||
4A4B0F9B15CEF8C400AE2392 /* catch_notimplemented_exception.hpp */,
|
4A4B0F9B15CEF8C400AE2392 /* catch_notimplemented_exception.hpp */,
|
||||||
4A90B59D15D24FE900EF71BC /* catch_resultinfo.hpp */,
|
4A90B59D15D24FE900EF71BC /* catch_resultinfo.hpp */,
|
||||||
|
4A90B59E15D2521E00EF71BC /* catch_resultinfo_builder.hpp */,
|
||||||
);
|
);
|
||||||
name = impl;
|
name = impl;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@ -223,7 +225,7 @@
|
|||||||
4A6D0C4F149B3E3D00DB3EAA /* catch_generators.hpp */,
|
4A6D0C4F149B3E3D00DB3EAA /* catch_generators.hpp */,
|
||||||
4A6D0C5C149B3E3D00DB3EAA /* catch_result_type.h */,
|
4A6D0C5C149B3E3D00DB3EAA /* catch_result_type.h */,
|
||||||
4A6D0C5D149B3E3D00DB3EAA /* catch_resultinfo.h */,
|
4A6D0C5D149B3E3D00DB3EAA /* catch_resultinfo.h */,
|
||||||
4A9D84B315599AC900FBB209 /* catch_resultinfo_builder.hpp */,
|
4A9D84B315599AC900FBB209 /* catch_resultinfo_builder.h */,
|
||||||
4A6D0C5F149B3E3D00DB3EAA /* catch_section.hpp */,
|
4A6D0C5F149B3E3D00DB3EAA /* catch_section.hpp */,
|
||||||
4A3D7DD01503869D005F9203 /* catch_matchers.hpp */,
|
4A3D7DD01503869D005F9203 /* catch_matchers.hpp */,
|
||||||
4A9D84B11558FC0400FBB209 /* catch_tostring.hpp */,
|
4A9D84B11558FC0400FBB209 /* catch_tostring.hpp */,
|
||||||
|
Loading…
Reference in New Issue
Block a user