2014-05-28 19:53:01 +02:00
|
|
|
/*
|
|
|
|
* Created by Phil on 28/5/2014.
|
|
|
|
* Copyright 2014 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_RESULT_BUILDER_H_INCLUDED
|
|
|
|
#define TWOBLUECUBES_CATCH_RESULT_BUILDER_H_INCLUDED
|
|
|
|
|
2014-05-29 08:50:19 +02:00
|
|
|
#include "catch_result_type.h"
|
|
|
|
#include "catch_assertionresult.h"
|
2014-05-28 19:53:01 +02:00
|
|
|
#include "catch_common.h"
|
2015-07-16 00:02:25 +02:00
|
|
|
#include "catch_matchers.hpp"
|
2014-05-28 19:53:01 +02:00
|
|
|
|
|
|
|
namespace Catch {
|
|
|
|
|
|
|
|
struct TestFailureException{};
|
|
|
|
|
2014-05-29 08:50:19 +02:00
|
|
|
template<typename T> class ExpressionLhs;
|
|
|
|
|
|
|
|
struct CopyableStream {
|
|
|
|
CopyableStream() {}
|
|
|
|
CopyableStream( CopyableStream const& other ) {
|
|
|
|
oss << other.oss.str();
|
|
|
|
}
|
|
|
|
CopyableStream& operator=( CopyableStream const& other ) {
|
2017-01-15 09:41:33 +01:00
|
|
|
oss.str(std::string());
|
2014-05-29 08:50:19 +02:00
|
|
|
oss << other.oss.str();
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
std::ostringstream oss;
|
|
|
|
};
|
|
|
|
|
2017-01-09 13:23:10 +01:00
|
|
|
class ResultBuilder : public DecomposedExpression {
|
2014-05-29 08:50:19 +02:00
|
|
|
public:
|
2014-05-28 19:53:01 +02:00
|
|
|
ResultBuilder( char const* macroName,
|
|
|
|
SourceLineInfo const& lineInfo,
|
|
|
|
char const* capturedExpression,
|
2015-07-13 07:34:41 +02:00
|
|
|
ResultDisposition::Flags resultDisposition,
|
|
|
|
char const* secondArg = "" );
|
2017-03-29 21:12:06 +02:00
|
|
|
~ResultBuilder();
|
2014-05-28 19:53:01 +02:00
|
|
|
|
|
|
|
template<typename T>
|
2015-06-26 07:35:33 +02:00
|
|
|
ExpressionLhs<T const&> operator <= ( T const& operand );
|
|
|
|
ExpressionLhs<bool> operator <= ( bool value );
|
2014-05-28 19:53:01 +02:00
|
|
|
|
2014-05-29 08:50:19 +02:00
|
|
|
template<typename T>
|
|
|
|
ResultBuilder& operator << ( T const& value ) {
|
|
|
|
m_stream.oss << value;
|
|
|
|
return *this;
|
2014-05-28 19:53:01 +02:00
|
|
|
}
|
|
|
|
|
2014-05-29 08:50:19 +02:00
|
|
|
ResultBuilder& setResultType( ResultWas::OfType result );
|
|
|
|
ResultBuilder& setResultType( bool result );
|
|
|
|
|
2017-01-09 13:23:10 +01:00
|
|
|
void endExpression( DecomposedExpression const& expr );
|
|
|
|
|
2017-02-06 23:37:23 +01:00
|
|
|
virtual void reconstructExpression( std::string& dest ) const CATCH_OVERRIDE;
|
2014-05-29 08:50:19 +02:00
|
|
|
|
|
|
|
AssertionResult build() const;
|
2017-01-09 13:23:10 +01:00
|
|
|
AssertionResult build( DecomposedExpression const& expr ) const;
|
2014-05-29 08:50:19 +02:00
|
|
|
|
2014-05-28 19:53:01 +02:00
|
|
|
void useActiveException( ResultDisposition::Flags resultDisposition = ResultDisposition::Normal );
|
|
|
|
void captureResult( ResultWas::OfType resultType );
|
|
|
|
void captureExpression();
|
2015-07-13 07:34:41 +02:00
|
|
|
void captureExpectedException( std::string const& expectedMessage );
|
2017-02-08 15:17:17 +01:00
|
|
|
void captureExpectedException( Matchers::Impl::MatcherBase<std::string> const& matcher );
|
2015-07-13 07:34:41 +02:00
|
|
|
void handleResult( AssertionResult const& result );
|
2014-05-28 19:53:01 +02:00
|
|
|
void react();
|
|
|
|
bool shouldDebugBreak() const;
|
|
|
|
bool allowThrows() const;
|
|
|
|
|
2017-01-09 13:23:10 +01:00
|
|
|
template<typename ArgT, typename MatcherT>
|
|
|
|
void captureMatch( ArgT const& arg, MatcherT const& matcher, char const* matcherString );
|
|
|
|
|
2017-03-29 21:12:06 +02:00
|
|
|
void setExceptionGuard();
|
|
|
|
void unsetExceptionGuard();
|
|
|
|
|
2014-05-29 08:50:19 +02:00
|
|
|
private:
|
2014-05-28 19:53:01 +02:00
|
|
|
AssertionInfo m_assertionInfo;
|
2014-05-29 08:50:19 +02:00
|
|
|
AssertionResultData m_data;
|
|
|
|
CopyableStream m_stream;
|
2015-11-04 19:01:28 +01:00
|
|
|
|
2014-05-28 19:53:01 +02:00
|
|
|
bool m_shouldDebugBreak;
|
|
|
|
bool m_shouldThrow;
|
2017-03-29 21:12:06 +02:00
|
|
|
bool m_guardException;
|
2014-05-28 19:53:01 +02:00
|
|
|
};
|
|
|
|
|
2014-05-29 08:50:19 +02:00
|
|
|
} // namespace Catch
|
|
|
|
|
|
|
|
// Include after due to circular dependency:
|
|
|
|
#include "catch_expression_lhs.hpp"
|
|
|
|
|
|
|
|
namespace Catch {
|
|
|
|
|
|
|
|
template<typename T>
|
2015-06-26 07:35:33 +02:00
|
|
|
inline ExpressionLhs<T const&> ResultBuilder::operator <= ( T const& operand ) {
|
2014-05-29 08:50:19 +02:00
|
|
|
return ExpressionLhs<T const&>( *this, operand );
|
|
|
|
}
|
|
|
|
|
2015-06-26 07:35:33 +02:00
|
|
|
inline ExpressionLhs<bool> ResultBuilder::operator <= ( bool value ) {
|
2014-05-29 08:50:19 +02:00
|
|
|
return ExpressionLhs<bool>( *this, value );
|
|
|
|
}
|
|
|
|
|
2017-01-09 13:23:10 +01:00
|
|
|
template<typename ArgT, typename MatcherT>
|
|
|
|
inline void ResultBuilder::captureMatch( ArgT const& arg, MatcherT const& matcher,
|
|
|
|
char const* matcherString ) {
|
|
|
|
MatchExpression<ArgT const&, MatcherT const&> expr( arg, matcher, matcherString );
|
|
|
|
setResultType( matcher.match( arg ) );
|
|
|
|
endExpression( expr );
|
|
|
|
}
|
|
|
|
|
2017-02-08 15:17:17 +01:00
|
|
|
|
2014-05-29 08:50:19 +02:00
|
|
|
} // namespace Catch
|
2014-05-28 19:53:01 +02:00
|
|
|
|
|
|
|
#endif // TWOBLUECUBES_CATCH_RESULT_BUILDER_H_INCLUDED
|