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_assertionresult.h"
|
2017-08-08 18:53:01 +02:00
|
|
|
#include "catch_decomposer.h"
|
|
|
|
|
|
|
|
#include "catch_result_type.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
|
|
|
|
2017-08-01 18:46:33 +02:00
|
|
|
#include <sstream>
|
|
|
|
|
2014-05-28 19:53:01 +02:00
|
|
|
namespace Catch {
|
|
|
|
|
2014-05-29 08:50:19 +02:00
|
|
|
template<typename T> class ExpressionLhs;
|
|
|
|
|
|
|
|
struct CopyableStream {
|
2017-04-25 19:56:53 +02:00
|
|
|
CopyableStream() = default;
|
2017-07-19 10:13:47 +02:00
|
|
|
CopyableStream( CopyableStream const& other );
|
|
|
|
CopyableStream& operator=( CopyableStream const& other );
|
|
|
|
|
2014-05-29 08:50:19 +02:00
|
|
|
std::ostringstream oss;
|
|
|
|
};
|
|
|
|
|
2017-01-09 13:23:10 +01:00
|
|
|
class ResultBuilder : public DecomposedExpression {
|
2014-05-29 08:50:19 +02:00
|
|
|
public:
|
2017-08-08 02:22:21 +02:00
|
|
|
ResultBuilder( StringRef macroName,
|
2014-05-28 19:53:01 +02:00
|
|
|
SourceLineInfo const& lineInfo,
|
2017-08-08 02:22:21 +02:00
|
|
|
StringRef capturedExpression,
|
2017-06-22 18:13:05 +02:00
|
|
|
ResultDisposition::Flags resultDisposition);
|
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 ) {
|
2017-06-26 21:30:23 +02:00
|
|
|
stream().oss << value;
|
2014-05-29 08:50:19 +02:00
|
|
|
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-07-20 16:57:17 +02:00
|
|
|
void reconstructExpression( std::string& dest ) const 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();
|
2017-07-29 08:43:32 +02:00
|
|
|
#if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
|
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 );
|
2017-07-28 21:34:34 +02:00
|
|
|
#endif // CATCH_CONFIG_DISABLE_MATCHERS
|
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;
|
2017-06-23 18:31:17 +02:00
|
|
|
|
2017-06-26 21:30:23 +02:00
|
|
|
CopyableStream& stream();
|
|
|
|
static CopyableStream& s_stream();
|
2015-11-04 19:01:28 +01:00
|
|
|
|
2017-04-25 19:56:53 +02:00
|
|
|
bool m_shouldDebugBreak = false;
|
|
|
|
bool m_shouldThrow = false;
|
|
|
|
bool m_guardException = false;
|
2017-06-26 21:30:23 +02:00
|
|
|
bool m_usedStream = false;
|
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>
|
2017-07-19 10:11:10 +02:00
|
|
|
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>
|
2017-07-19 10:11:10 +02:00
|
|
|
void ResultBuilder::captureMatch( ArgT const& arg, MatcherT const& matcher,
|
2017-01-09 13:23:10 +01:00
|
|
|
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
|