mirror of
https://github.com/catchorg/Catch2.git
synced 2025-09-23 21:15:39 +02:00
Folded ExpressionResultBuilder into ResultBuilder
(even more SRP violations!)
This commit is contained in:
@@ -8,28 +8,61 @@
|
||||
#ifndef TWOBLUECUBES_CATCH_RESULT_BUILDER_H_INCLUDED
|
||||
#define TWOBLUECUBES_CATCH_RESULT_BUILDER_H_INCLUDED
|
||||
|
||||
#include "catch_expression_lhs.hpp"
|
||||
#include "catch_expressionresult_builder.h"
|
||||
#include "catch_result_type.h"
|
||||
#include "catch_assertionresult.h"
|
||||
#include "catch_common.h"
|
||||
|
||||
namespace Catch {
|
||||
|
||||
struct TestFailureException{};
|
||||
|
||||
struct ResultBuilder {
|
||||
template<typename T> class ExpressionLhs;
|
||||
|
||||
struct STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison;
|
||||
|
||||
struct CopyableStream {
|
||||
CopyableStream() {}
|
||||
CopyableStream( CopyableStream const& other ) {
|
||||
oss << other.oss.str();
|
||||
}
|
||||
CopyableStream& operator=( CopyableStream const& other ) {
|
||||
oss.str("");
|
||||
oss << other.oss.str();
|
||||
return *this;
|
||||
}
|
||||
std::ostringstream oss;
|
||||
};
|
||||
|
||||
class ResultBuilder {
|
||||
public:
|
||||
ResultBuilder( char const* macroName,
|
||||
SourceLineInfo const& lineInfo,
|
||||
char const* capturedExpression,
|
||||
ResultDisposition::Flags resultDisposition );
|
||||
|
||||
template<typename T>
|
||||
ExpressionLhs<T const&> operator->* ( T const& operand ) {
|
||||
return ExpressionLhs<T const&>( *this, operand );
|
||||
ExpressionLhs<T const&> operator->* ( T const& operand );
|
||||
ExpressionLhs<bool> operator->* ( bool value );
|
||||
|
||||
template<typename T>
|
||||
ResultBuilder& operator << ( T const& value ) {
|
||||
m_stream.oss << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
ExpressionLhs<bool> operator->* ( bool value ) {
|
||||
return ExpressionLhs<bool>( *this, value );
|
||||
}
|
||||
template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator && ( RhsT const& );
|
||||
template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator || ( RhsT const& );
|
||||
|
||||
ResultBuilder& setResultType( ResultWas::OfType result );
|
||||
ResultBuilder& setResultType( bool result );
|
||||
ResultBuilder& setLhs( std::string const& lhs );
|
||||
ResultBuilder& setRhs( std::string const& rhs );
|
||||
ResultBuilder& setOp( std::string const& op );
|
||||
|
||||
void endExpression();
|
||||
|
||||
std::string reconstructExpression() const;
|
||||
AssertionResult build() const;
|
||||
|
||||
void useActiveException( ResultDisposition::Flags resultDisposition = ResultDisposition::Normal );
|
||||
void captureResult( ResultWas::OfType resultType );
|
||||
@@ -38,12 +71,36 @@ namespace Catch {
|
||||
bool shouldDebugBreak() const;
|
||||
bool allowThrows() const;
|
||||
|
||||
private:
|
||||
AssertionInfo m_assertionInfo;
|
||||
ExpressionResultBuilder m_resultBuilder;
|
||||
AssertionResultData m_data;
|
||||
struct ExprComponents {
|
||||
ExprComponents() : testFalse( false ) {}
|
||||
bool testFalse;
|
||||
std::string lhs, rhs, op;
|
||||
} m_exprComponents;
|
||||
CopyableStream m_stream;
|
||||
|
||||
bool m_shouldDebugBreak;
|
||||
bool m_shouldThrow;
|
||||
};
|
||||
|
||||
} // end namespace Catch
|
||||
} // namespace Catch
|
||||
|
||||
// Include after due to circular dependency:
|
||||
#include "catch_expression_lhs.hpp"
|
||||
|
||||
namespace Catch {
|
||||
|
||||
template<typename T>
|
||||
inline ExpressionLhs<T const&> ResultBuilder::operator->* ( T const& operand ) {
|
||||
return ExpressionLhs<T const&>( *this, operand );
|
||||
}
|
||||
|
||||
inline ExpressionLhs<bool> ResultBuilder::operator->* ( bool value ) {
|
||||
return ExpressionLhs<bool>( *this, value );
|
||||
}
|
||||
|
||||
} // namespace Catch
|
||||
|
||||
#endif // TWOBLUECUBES_CATCH_RESULT_BUILDER_H_INCLUDED
|
||||
|
Reference in New Issue
Block a user