mirror of
https://github.com/catchorg/Catch2.git
synced 2025-08-01 12:55:40 +02:00
Squashed commit of the following:
commit2a1e8bfc6e
Author: Phil Nash <github@philnash.me> Date: Thu Nov 1 08:16:15 2012 +0000 Updated colour comments commitf0f407fc3e
Author: Phil Nash <github@philnash.me> Date: Wed Oct 31 18:28:21 2012 +0000 Manually applied merge #133 from Master commit355b95fda1
Author: Phil Nash <github@philnash.me> Date: Wed Oct 31 18:04:22 2012 +0000 Cleaned up ANSI colour code impl a bit commit778f9c4fc7
Author: Phil Nash <github@philnash.me> Date: Tue Oct 30 09:09:30 2012 +0000 Removed "no-" from Wno-global-constructors when disabling commit5efa4bcb8a
Author: Phil Nash <github@philnash.me> Date: Mon Oct 29 20:49:22 2012 +0000 Regenerated single_include commit108f1937d8
Author: Phil Nash <github@philnash.me> Date: Mon Oct 29 20:46:45 2012 +0000 Added terminal colour codes for POSIX With thanks to Adam Strzelecki commit8f4cc541d5
Author: Phil Nash <github@philnash.me> Date: Mon Oct 29 19:55:34 2012 +0000 Added regression test baselines commit2e203a1834
Author: Phil Nash <github@philnash.me> Date: Mon Oct 29 19:55:13 2012 +0000 Fixed remaining reporting regressions commit134e45b3ad
Author: Phil Nash <github@philnash.me> Date: Sun Oct 28 20:57:21 2012 +0000 Fixed #132 commit2f92db9898
Author: Phil Nash <github@philnash.me> Date: Sun Oct 28 12:15:34 2012 +0000 Updated the readme specifically for the Integration branch commit82acc2ca05
Author: Phil Nash <github@philnash.me> Date: Sun Oct 28 12:07:17 2012 +0000 Regenerated single include commitfe1d7c1d08
Author: Phil Nash <github@philnash.me> Date: Sun Oct 28 10:27:44 2012 +0000 Small fixes and tweaks commit355b5e546d
Author: Phil Nash <github@philnash.me> Date: Fri Oct 26 09:05:36 2012 +0100 Some tidy-up commitf847186ebb
Author: Phil Nash <github@philnash.me> Date: Fri Oct 26 08:45:23 2012 +0100 AssertionResultBuilder -> ExpressionResultBuilder commit8cca2f1369
Author: Phil Nash <github@philnash.me> Date: Wed Oct 24 22:09:01 2012 +0100 ExpressionBuilder ->ExpressionDecomposer Expression -> ExpressionLhs commite04e74f896
Author: Phil Nash <github@philnash.me> Date: Wed Oct 24 21:59:47 2012 +0100 More AssertionResult refactoring commit1dd56d4d2b
Author: Phil Nash <github@philnash.me> Date: Fri Oct 19 08:01:34 2012 +0100 AssertionResultBuilder can be constructed from result type commitf2d5f1b3e4
Author: Phil Nash <github@philnash.me> Date: Fri Oct 19 08:01:05 2012 +0100 Expression has its own result builder - not passed in from expression builder commite3b111a39a
Author: Phil Nash <github@philnash.me> Date: Thu Oct 18 22:59:16 2012 +0100 streamlined acceptResult commit3ad13256e1
Author: Phil Nash <github@philnash.me> Date: Thu Oct 18 08:39:44 2012 +0100 Refactored assertion builder stuff out of expression builder commitc96f9330a0
Author: Phil Nash <github@philnash.me> Date: Wed Oct 17 08:14:22 2012 +0100 Collect assertion info up front commita5fa78284d
Author: Phil Nash <github@philnash.me> Date: Tue Oct 16 08:33:13 2012 +0100 ResultData -> AssertionResultData commitc597a893fa
Author: Phil Nash <github@philnash.me> Date: Tue Oct 16 08:31:05 2012 +0100 ResultInfo -> AssertionResult filenames and variables commitd16955f63a
Author: Phil Nash <github@philnash.me> Date: Tue Oct 16 08:27:21 2012 +0100 Renamed ResultInfo -> AssertionResult commit175da3ef64
Author: Phil Nash <github@philnash.me> Date: Fri Oct 12 18:39:22 2012 +0100 regen test 3
This commit is contained in:
66
include/internal/catch_assertionresult.h
Normal file
66
include/internal/catch_assertionresult.h
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Created by Phil on 28/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_ASSERTIONRESULT_H_INCLUDED
|
||||
#define TWOBLUECUBES_CATCH_ASSERTIONRESULT_H_INCLUDED
|
||||
|
||||
#include <string>
|
||||
#include "catch_result_type.h"
|
||||
|
||||
namespace Catch {
|
||||
|
||||
struct AssertionInfo
|
||||
{
|
||||
AssertionInfo() {}
|
||||
AssertionInfo( const std::string& _macroName, const SourceLineInfo& _lineInfo, const std::string& _capturedExpression, bool _shouldNegate )
|
||||
: macroName( _macroName ),
|
||||
lineInfo( _lineInfo ),
|
||||
capturedExpression( _capturedExpression )
|
||||
{
|
||||
if( _shouldNegate )
|
||||
capturedExpression = "!" + _capturedExpression;
|
||||
}
|
||||
|
||||
std::string macroName;
|
||||
SourceLineInfo lineInfo;
|
||||
std::string capturedExpression;
|
||||
};
|
||||
|
||||
struct AssertionResultData
|
||||
{
|
||||
AssertionResultData() : resultType( ResultWas::Unknown ) {}
|
||||
|
||||
std::string reconstructedExpression;
|
||||
std::string message;
|
||||
ResultWas::OfType resultType;
|
||||
};
|
||||
|
||||
class AssertionResult {
|
||||
public:
|
||||
AssertionResult();
|
||||
AssertionResult( const AssertionInfo& info, const AssertionResultData& data );
|
||||
~AssertionResult();
|
||||
|
||||
bool ok() const;
|
||||
ResultWas::OfType getResultType() const;
|
||||
bool hasExpression() const;
|
||||
bool hasMessage() const;
|
||||
std::string getExpression() const;
|
||||
bool hasExpandedExpression() const;
|
||||
std::string getExpandedExpression() const;
|
||||
std::string getMessage() const;
|
||||
SourceLineInfo getSourceInfo() const;
|
||||
std::string getTestMacroName() const;
|
||||
|
||||
protected:
|
||||
AssertionInfo m_info;
|
||||
AssertionResultData m_resultData;
|
||||
};
|
||||
|
||||
} // end namespace Catch
|
||||
|
||||
#endif // TWOBLUECUBES_CATCH_ASSERTIONRESULT_H_INCLUDED
|
65
include/internal/catch_assertionresult.hpp
Normal file
65
include/internal/catch_assertionresult.hpp
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Created by Phil on 8/8/12
|
||||
* 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_ASSERTIONRESULT_HPP_INCLUDED
|
||||
#define TWOBLUECUBES_CATCH_ASSERTIONRESULT_HPP_INCLUDED
|
||||
|
||||
#include "catch_assertionresult.h"
|
||||
|
||||
namespace Catch {
|
||||
|
||||
AssertionResult::AssertionResult() {}
|
||||
|
||||
AssertionResult::AssertionResult( const AssertionInfo& info, const AssertionResultData& data )
|
||||
: m_info( info ),
|
||||
m_resultData( data )
|
||||
{}
|
||||
|
||||
AssertionResult::~AssertionResult() {}
|
||||
|
||||
bool AssertionResult::ok() const {
|
||||
return isOk( m_resultData.resultType );
|
||||
}
|
||||
|
||||
ResultWas::OfType AssertionResult::getResultType() const {
|
||||
return m_resultData.resultType;
|
||||
}
|
||||
|
||||
bool AssertionResult::hasExpression() const {
|
||||
return !m_info.capturedExpression.empty();
|
||||
}
|
||||
|
||||
bool AssertionResult::hasMessage() const {
|
||||
return !m_resultData.message.empty();
|
||||
}
|
||||
|
||||
std::string AssertionResult::getExpression() const {
|
||||
return m_info.capturedExpression;
|
||||
}
|
||||
|
||||
bool AssertionResult::hasExpandedExpression() const {
|
||||
return hasExpression() && getExpandedExpression() != getExpression();
|
||||
}
|
||||
|
||||
std::string AssertionResult::getExpandedExpression() const {
|
||||
return m_resultData.reconstructedExpression;
|
||||
}
|
||||
|
||||
std::string AssertionResult::getMessage() const {
|
||||
return m_resultData.message;
|
||||
}
|
||||
SourceLineInfo AssertionResult::getSourceInfo() const {
|
||||
return m_info.lineInfo;
|
||||
}
|
||||
|
||||
std::string AssertionResult::getTestMacroName() const {
|
||||
return m_info.macroName;
|
||||
}
|
||||
|
||||
} // end namespace Catch
|
||||
|
||||
#endif // TWOBLUECUBES_CATCH_ASSERTIONRESULT_HPP_INCLUDED
|
@@ -8,53 +8,84 @@
|
||||
#ifndef TWOBLUECUBES_CATCH_CAPTURE_HPP_INCLUDED
|
||||
#define TWOBLUECUBES_CATCH_CAPTURE_HPP_INCLUDED
|
||||
|
||||
#include "catch_expression_builder.hpp"
|
||||
#include "catch_expression_decomposer.hpp"
|
||||
#include "catch_expressionresult_builder.h"
|
||||
#include "catch_interfaces_capture.h"
|
||||
#include "catch_debugger.hpp"
|
||||
#include "catch_context.h"
|
||||
#include "catch_common.h"
|
||||
#include "catch_interfaces_registry_hub.h"
|
||||
#include <ostream>
|
||||
|
||||
namespace Catch {
|
||||
|
||||
inline IResultCapture& getResultCapture() {
|
||||
return getCurrentContext().getResultCapture();
|
||||
}
|
||||
|
||||
template<typename MatcherT>
|
||||
ExpressionResultBuilder expressionResultBuilderFromMatcher( const MatcherT& matcher,
|
||||
const std::string& matcherCallAsString ) {
|
||||
std::string matcherAsString = matcher.toString();
|
||||
if( matcherAsString == "{?}" )
|
||||
matcherAsString = matcherCallAsString;
|
||||
return ExpressionResultBuilder()
|
||||
.setRhs( matcherAsString )
|
||||
.setOp( "matches" );
|
||||
}
|
||||
|
||||
template<typename MatcherT, typename ArgT>
|
||||
ExpressionResultBuilder expressionResultBuilderFromMatcher( const MatcherT& matcher,
|
||||
const ArgT& arg,
|
||||
const std::string& matcherCallAsString ) {
|
||||
return expressionResultBuilderFromMatcher( matcher, matcherCallAsString )
|
||||
.setLhs( Catch::toString( arg ) )
|
||||
.setResultType( matcher.match( arg ) );
|
||||
}
|
||||
|
||||
template<typename MatcherT, typename ArgT>
|
||||
ExpressionResultBuilder expressionResultBuilderFromMatcher( const MatcherT& matcher,
|
||||
ArgT* arg,
|
||||
const std::string& matcherCallAsString ) {
|
||||
return expressionResultBuilderFromMatcher( matcher, matcherCallAsString )
|
||||
.setLhs( Catch::toString( arg ) )
|
||||
.setResultType( matcher.match( arg ) );
|
||||
}
|
||||
|
||||
struct TestFailureException{};
|
||||
|
||||
class ScopedInfo {
|
||||
public:
|
||||
ScopedInfo() : m_oss() {
|
||||
getCurrentContext().getResultCapture().pushScopedInfo( this );
|
||||
ScopedInfo() : m_resultBuilder( ResultWas::Info ) {
|
||||
getResultCapture().pushScopedInfo( this );
|
||||
}
|
||||
|
||||
~ScopedInfo() {
|
||||
getCurrentContext().getResultCapture().popScopedInfo( this );
|
||||
getResultCapture().popScopedInfo( this );
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ScopedInfo& operator << ( const T& value ) {
|
||||
m_oss << value;
|
||||
m_resultBuilder << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
ResultInfo getInfo () const {
|
||||
return ResultInfoBuilder()
|
||||
.setResultType( ResultWas::Info )
|
||||
.setMessage( m_oss.str() )
|
||||
.setMacroName( "SCOPED_INFO" )
|
||||
.build();
|
||||
AssertionResult buildResult( const AssertionInfo& assertionInfo ) const {
|
||||
return m_resultBuilder.buildResult( assertionInfo );
|
||||
}
|
||||
|
||||
private:
|
||||
std::ostringstream m_oss;
|
||||
ExpressionResultBuilder m_resultBuilder;
|
||||
};
|
||||
|
||||
// This is just here to avoid compiler warnings with macro constants
|
||||
// This is just here to avoid compiler warnings with macro constants and boolean literals
|
||||
inline bool isTrue( bool value ){ return value; }
|
||||
|
||||
|
||||
} // end namespace Catch
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#define INTERNAL_CATCH_ACCEPT_EXPR( expr, stopOnFailure, originalExpr ) \
|
||||
if( Catch::ResultAction::Value internal_catch_action = Catch::getCurrentContext().getResultCapture().acceptExpression( expr ) ) { \
|
||||
#define INTERNAL_CATCH_ASSERTIONINFO_NAME INTERNAL_CATCH_UNIQUE_NAME( __assertionInfo )
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#define INTERNAL_CATCH_ACCEPT_EXPR( evaluatedExpr, stopOnFailure, originalExpr ) \
|
||||
if( Catch::ResultAction::Value internal_catch_action = Catch::getResultCapture().acceptExpression( evaluatedExpr, INTERNAL_CATCH_ASSERTIONINFO_NAME ) ) { \
|
||||
if( internal_catch_action & Catch::ResultAction::Debug ) BreakIntoDebugger(); \
|
||||
if( internal_catch_action & Catch::ResultAction::Abort ) throw Catch::TestFailureException(); \
|
||||
if( Catch::isTrue( stopOnFailure ) ) throw Catch::TestFailureException(); \
|
||||
@@ -62,76 +93,102 @@ inline bool isTrue( bool value ){ return value; }
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#define INTERNAL_CATCH_TEST( expr, isFalse, stopOnFailure, macroName ) \
|
||||
do { try { \
|
||||
INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr, isFalse )->*expr ), stopOnFailure, expr ); \
|
||||
} catch( Catch::TestFailureException& ) { \
|
||||
throw; \
|
||||
} catch( ... ) { \
|
||||
INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr ) << Catch::getRegistryHub().getExceptionTranslatorRegistry().translateActiveException() ).setResultType( Catch::ResultWas::ThrewException ), false, expr ); \
|
||||
throw; \
|
||||
} } while( Catch::isTrue( false ) )
|
||||
#define INTERNAL_CATCH_ACCEPT_INFO( expr, macroName, shouldNegate ) \
|
||||
Catch::AssertionInfo INTERNAL_CATCH_ASSERTIONINFO_NAME( macroName, CATCH_INTERNAL_LINEINFO, expr, shouldNegate );
|
||||
// !TBD Catch::getResultCapture().acceptAssertionInfo( INTERNAL_CATCH_ASSERTIONINFO_NAME )
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#define INTERNAL_CATCH_IF( expr, isFalse, stopOnFailure, macroName ) \
|
||||
INTERNAL_CATCH_TEST( expr, isFalse, stopOnFailure, macroName ); \
|
||||
if( Catch::getCurrentContext().getResultCapture().getLastResult()->ok() )
|
||||
#define INTERNAL_CATCH_TEST( expr, shouldNegate, stopOnFailure, macroName ) \
|
||||
do { \
|
||||
INTERNAL_CATCH_ACCEPT_INFO( #expr, macroName, shouldNegate ); \
|
||||
try { \
|
||||
INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionDecomposer()->*expr ).negate( shouldNegate ), stopOnFailure, expr ); \
|
||||
} catch( Catch::TestFailureException& ) { \
|
||||
throw; \
|
||||
} catch( ... ) { \
|
||||
INTERNAL_CATCH_ACCEPT_EXPR( Catch::ExpressionResultBuilder( Catch::ResultWas::ThrewException ) << Catch::translateActiveException(), false, expr ); \
|
||||
throw; \
|
||||
} \
|
||||
} while( Catch::isTrue( false ) )
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#define INTERNAL_CATCH_ELSE( expr, isFalse, stopOnFailure, macroName ) \
|
||||
INTERNAL_CATCH_TEST( expr, isFalse, stopOnFailure, macroName ); \
|
||||
if( !Catch::getCurrentContext().getResultCapture().getLastResult()->ok() )
|
||||
#define INTERNAL_CATCH_IF( expr, shouldNegate, stopOnFailure, macroName ) \
|
||||
INTERNAL_CATCH_TEST( expr, shouldNegate, stopOnFailure, macroName ); \
|
||||
if( Catch::getResultCapture().getLastResult()->ok() )
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#define INTERNAL_CATCH_ELSE( expr, shouldNegate, stopOnFailure, macroName ) \
|
||||
INTERNAL_CATCH_TEST( expr, shouldNegate, stopOnFailure, macroName ); \
|
||||
if( !Catch::getResultCapture().getLastResult()->ok() )
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#define INTERNAL_CATCH_NO_THROW( expr, stopOnFailure, macroName ) \
|
||||
try { \
|
||||
expr; \
|
||||
INTERNAL_CATCH_ACCEPT_EXPR( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr ).setResultType( Catch::ResultWas::Ok ), stopOnFailure, false ); \
|
||||
} \
|
||||
catch( ... ) { \
|
||||
INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr ) << Catch::getRegistryHub().getExceptionTranslatorRegistry().translateActiveException() ).setResultType( Catch::ResultWas::ThrewException ), stopOnFailure, false ); \
|
||||
}
|
||||
do { \
|
||||
INTERNAL_CATCH_ACCEPT_INFO( #expr, macroName, false ); \
|
||||
try { \
|
||||
expr; \
|
||||
INTERNAL_CATCH_ACCEPT_EXPR( Catch::ExpressionResultBuilder( Catch::ResultWas::Ok ), stopOnFailure, false ); \
|
||||
} \
|
||||
catch( ... ) { \
|
||||
INTERNAL_CATCH_ACCEPT_EXPR( Catch::ExpressionResultBuilder( Catch::ResultWas::ThrewException ) << Catch::translateActiveException(), stopOnFailure, false ); \
|
||||
} \
|
||||
} while( Catch::isTrue( false ) )
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#define INTERNAL_CATCH_THROWS( expr, exceptionType, stopOnFailure, macroName ) \
|
||||
#define INTERNAL_CATCH_THROWS_IMPL( expr, exceptionType, stopOnFailure ) \
|
||||
try { \
|
||||
if( Catch::getCurrentContext().getConfig()->allowThrows() ) { \
|
||||
expr; \
|
||||
INTERNAL_CATCH_ACCEPT_EXPR( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr ).setResultType( Catch::ResultWas::DidntThrowException ), stopOnFailure, false ); \
|
||||
INTERNAL_CATCH_ACCEPT_EXPR( Catch::ExpressionResultBuilder( Catch::ResultWas::DidntThrowException ), stopOnFailure, false ); \
|
||||
} \
|
||||
} \
|
||||
catch( Catch::TestFailureException& ) { \
|
||||
throw; \
|
||||
} \
|
||||
catch( exceptionType ) { \
|
||||
INTERNAL_CATCH_ACCEPT_EXPR( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr ).setResultType( Catch::ResultWas::Ok ), stopOnFailure, false ); \
|
||||
INTERNAL_CATCH_ACCEPT_EXPR( Catch::ExpressionResultBuilder( Catch::ResultWas::Ok ), stopOnFailure, false ); \
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#define INTERNAL_CATCH_THROWS( expr, exceptionType, stopOnFailure, macroName ) \
|
||||
do { \
|
||||
INTERNAL_CATCH_ACCEPT_INFO( #expr, macroName, false ); \
|
||||
INTERNAL_CATCH_THROWS_IMPL( expr, exceptionType, stopOnFailure ) \
|
||||
} while( Catch::isTrue( false ) )
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#define INTERNAL_CATCH_THROWS_AS( expr, exceptionType, stopOnFailure, macroName ) \
|
||||
INTERNAL_CATCH_THROWS( expr, exceptionType, stopOnFailure, macroName ) \
|
||||
catch( ... ) { \
|
||||
INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr ) << Catch::getRegistryHub().getExceptionTranslatorRegistry() ).setResultType( Catch::ResultWas::ThrewException ), stopOnFailure, false ); \
|
||||
}
|
||||
do { \
|
||||
INTERNAL_CATCH_ACCEPT_INFO( #expr, macroName, false ); \
|
||||
INTERNAL_CATCH_THROWS_IMPL( expr, exceptionType, stopOnFailure ) \
|
||||
catch( ... ) { \
|
||||
INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionResultBuilder( Catch::ResultWas::ThrewException ) << Catch::translateActiveException() ), stopOnFailure, false ); \
|
||||
} \
|
||||
} while( Catch::isTrue( false ) )
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#define INTERNAL_CATCH_MSG( reason, resultType, stopOnFailure, macroName ) \
|
||||
Catch::getCurrentContext().getResultCapture().acceptExpression( ( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName ) << reason ).setResultType( resultType ) );
|
||||
INTERNAL_CATCH_ACCEPT_INFO( "", macroName, false ); \
|
||||
INTERNAL_CATCH_ACCEPT_EXPR( Catch::ExpressionResultBuilder( resultType ) << reason, stopOnFailure, true );
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#define INTERNAL_CATCH_SCOPED_INFO( log ) \
|
||||
#define INTERNAL_CATCH_SCOPED_INFO( log, macroName ) \
|
||||
INTERNAL_CATCH_ACCEPT_INFO( "", macroName, false ); \
|
||||
Catch::ScopedInfo INTERNAL_CATCH_UNIQUE_NAME( info ); \
|
||||
INTERNAL_CATCH_UNIQUE_NAME( info ) << log
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#define INTERNAL_CHECK_THAT( arg, matcher, stopOnFailure, macroName ) \
|
||||
do { try { \
|
||||
INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName, #arg " " #matcher, false ).acceptMatcher( ::Catch::Matchers::matcher, arg, #matcher ) ), stopOnFailure, false ); \
|
||||
} catch( Catch::TestFailureException& ) { \
|
||||
throw; \
|
||||
} catch( ... ) { \
|
||||
INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName, #arg " " #matcher ) << Catch::getRegistryHub().getExceptionTranslatorRegistry().translateActiveException() ).setResultType( Catch::ResultWas::ThrewException ), false, false ); \
|
||||
throw; \
|
||||
}}while( Catch::isTrue( false ) )
|
||||
do { \
|
||||
INTERNAL_CATCH_ACCEPT_INFO( #arg " " #matcher, macroName, false ); \
|
||||
try { \
|
||||
INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::expressionResultBuilderFromMatcher( ::Catch::Matchers::matcher, arg, #matcher ) ), stopOnFailure, false ); \
|
||||
} catch( Catch::TestFailureException& ) { \
|
||||
throw; \
|
||||
} catch( ... ) { \
|
||||
INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionResultBuilder( Catch::ResultWas::ThrewException ) << Catch::translateActiveException() ), false, false ); \
|
||||
throw; \
|
||||
} \
|
||||
} while( Catch::isTrue( false ) )
|
||||
|
||||
#endif // TWOBLUECUBES_CATCH_CAPTURE_HPP_INCLUDED
|
||||
|
@@ -122,6 +122,9 @@ namespace Catch {
|
||||
file.swap( other.file );
|
||||
std::swap( line, other.line );
|
||||
}
|
||||
bool empty() const {
|
||||
return file.empty();
|
||||
}
|
||||
|
||||
std::string function;
|
||||
std::string file;
|
||||
|
@@ -10,7 +10,60 @@
|
||||
|
||||
#include "catch_console_colour.hpp"
|
||||
|
||||
#ifdef CATCH_PLATFORM_WINDOWS
|
||||
#if defined( CATCH_CONFIG_USE_ANSI_COLOUR_CODES )
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
namespace Catch {
|
||||
|
||||
// use POSIX/ ANSI console terminal codes
|
||||
// Implementation contributed by Adam Strzelecki (http://github.com/nanoant)
|
||||
// https://github.com/philsquared/Catch/pull/131
|
||||
|
||||
TextColour::TextColour( Colours colour ) {
|
||||
if( colour )
|
||||
set( colour );
|
||||
}
|
||||
|
||||
TextColour::~TextColour() {
|
||||
set( TextColour::None );
|
||||
}
|
||||
|
||||
namespace { const char colourEscape = '\033'; }
|
||||
|
||||
void TextColour::set( Colours colour ) {
|
||||
if( isatty( fileno(stdout) ) ) {
|
||||
switch( colour ) {
|
||||
case TextColour::FileName:
|
||||
std::cout << colourEscape << "[0m"; // white/ normal
|
||||
break;
|
||||
case TextColour::ResultError:
|
||||
std::cout << colourEscape << "[1;31m"; // bold red
|
||||
break;
|
||||
case TextColour::ResultSuccess:
|
||||
std::cout << colourEscape << "[1;32m"; // bold green
|
||||
break;
|
||||
case TextColour::Error:
|
||||
std::cout << colourEscape << "[0;31m"; // red
|
||||
break;
|
||||
case TextColour::Success:
|
||||
std::cout << colourEscape << "[0;32m"; // green
|
||||
break;
|
||||
case TextColour::OriginalExpression:
|
||||
std::cout << colourEscape << "[0;36m"; // cyan
|
||||
break;
|
||||
case TextColour::ReconstructedExpression:
|
||||
std::cout << colourEscape << "[0;33m"; // yellow
|
||||
break;
|
||||
case TextColour::None:
|
||||
std::cout << colourEscape << "[0m"; // reset
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Catch
|
||||
|
||||
#elif defined ( CATCH_PLATFORM_WINDOWS )
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
@@ -78,16 +131,17 @@ namespace Catch {
|
||||
void TextColour::set( Colours colour ) {
|
||||
m_impl->set( colour );
|
||||
}
|
||||
|
||||
|
||||
} // end namespace Catch
|
||||
|
||||
#else
|
||||
|
||||
namespace Catch {
|
||||
|
||||
TextColour::TextColour( Colours ){}
|
||||
TextColour::~TextColour(){}
|
||||
void TextColour::set( Colours ){}
|
||||
|
||||
|
||||
} // end namespace Catch
|
||||
|
||||
#endif
|
||||
|
@@ -1,90 +0,0 @@
|
||||
/*
|
||||
* Created by Phil on 11/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_EXPRESSION_HPP_INCLUDED
|
||||
#define TWOBLUECUBES_CATCH_EXPRESSION_HPP_INCLUDED
|
||||
|
||||
#include "catch_resultinfo_builder.h"
|
||||
#include "catch_evaluate.hpp"
|
||||
|
||||
namespace Catch {
|
||||
|
||||
template<typename T>
|
||||
class Expression {
|
||||
void operator = ( const Expression& );
|
||||
|
||||
public:
|
||||
Expression( ResultInfoBuilder& result, T lhs )
|
||||
: m_result( result.setLhs( Catch::toString( lhs ) ) ),
|
||||
m_lhs( lhs )
|
||||
{}
|
||||
|
||||
template<typename RhsT>
|
||||
ResultInfoBuilder& operator == ( const RhsT& rhs ) {
|
||||
return captureExpression<Internal::IsEqualTo>( rhs );
|
||||
}
|
||||
|
||||
template<typename RhsT>
|
||||
ResultInfoBuilder& operator != ( const RhsT& rhs ) {
|
||||
return captureExpression<Internal::IsNotEqualTo>( rhs );
|
||||
}
|
||||
|
||||
template<typename RhsT>
|
||||
ResultInfoBuilder& operator < ( const RhsT& rhs ) {
|
||||
return captureExpression<Internal::IsLessThan>( rhs );
|
||||
}
|
||||
|
||||
template<typename RhsT>
|
||||
ResultInfoBuilder& operator > ( const RhsT& rhs ) {
|
||||
return captureExpression<Internal::IsGreaterThan>( rhs );
|
||||
}
|
||||
|
||||
template<typename RhsT>
|
||||
ResultInfoBuilder& operator <= ( const RhsT& rhs ) {
|
||||
return captureExpression<Internal::IsLessThanOrEqualTo>( rhs );
|
||||
}
|
||||
|
||||
template<typename RhsT>
|
||||
ResultInfoBuilder& operator >= ( const RhsT& rhs ) {
|
||||
return captureExpression<Internal::IsGreaterThanOrEqualTo>( rhs );
|
||||
}
|
||||
|
||||
ResultInfoBuilder& operator == ( bool rhs ) {
|
||||
return captureExpression<Internal::IsEqualTo>( rhs );
|
||||
}
|
||||
|
||||
ResultInfoBuilder& operator != ( bool rhs ) {
|
||||
return captureExpression<Internal::IsNotEqualTo>( rhs );
|
||||
}
|
||||
|
||||
operator ResultInfoBuilder& () {
|
||||
return m_result.setResultType( m_lhs ? ResultWas::Ok : ResultWas::ExpressionFailed );
|
||||
}
|
||||
|
||||
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:
|
||||
template<Internal::Operator Op, typename RhsT>
|
||||
ResultInfoBuilder& captureExpression( const RhsT& rhs ) {
|
||||
return m_result
|
||||
.setResultType( Internal::compare<Op>( m_lhs, rhs ) ? ResultWas::Ok : ResultWas::ExpressionFailed )
|
||||
.setRhs( Catch::toString( rhs ) )
|
||||
.setOp( Internal::OperatorTraits<Op>::getName() );
|
||||
}
|
||||
|
||||
private:
|
||||
ResultInfoBuilder& m_result;
|
||||
T m_lhs;
|
||||
};
|
||||
|
||||
} // end namespace Catch
|
||||
|
||||
#endif // TWOBLUECUBES_CATCH_EXPRESSION_HPP_INCLUDED
|
@@ -1,102 +0,0 @@
|
||||
/*
|
||||
* Created by Phil on 11/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_EXPRESSION_BUILDER_HPP_INCLUDED
|
||||
#define TWOBLUECUBES_CATCH_EXPRESSION_BUILDER_HPP_INCLUDED
|
||||
|
||||
#include "catch_expression.hpp"
|
||||
#include "catch_resultinfo_builder.h"
|
||||
#include "catch_tostring.hpp"
|
||||
#include "catch_resultinfo.h"
|
||||
#include "catch_result_type.h"
|
||||
#include "catch_context.h"
|
||||
#include "catch_common.h"
|
||||
#include <sstream>
|
||||
|
||||
namespace Catch {
|
||||
|
||||
class ExpressionBuilder {
|
||||
public:
|
||||
|
||||
ExpressionBuilder( const SourceLineInfo& lineInfo,
|
||||
const char* macroName,
|
||||
const char* expr = "",
|
||||
bool isFalse = false )
|
||||
: m_messageStream()
|
||||
{
|
||||
m_result
|
||||
.setCapturedExpression( expr )
|
||||
.setIsFalse( isFalse )
|
||||
.setLineInfo( lineInfo )
|
||||
.setMacroName( macroName );
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Expression<const T&> operator->* ( const T & operand ) {
|
||||
Expression<const T&> expr( m_result, operand );
|
||||
return expr;
|
||||
}
|
||||
|
||||
Expression<bool> operator->* ( bool value ) {
|
||||
Expression<bool> expr( m_result, value );
|
||||
return expr;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ExpressionBuilder& operator << ( const T & value ) {
|
||||
m_messageStream << Catch::toString( value );
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename MatcherT, typename ArgT>
|
||||
ExpressionBuilder& acceptMatcher( const MatcherT& matcher,
|
||||
const ArgT& arg,
|
||||
const std::string& matcherCallAsString ) {
|
||||
std::string matcherAsString = matcher.toString();
|
||||
if( matcherAsString == "{?}" )
|
||||
matcherAsString = matcherCallAsString;
|
||||
m_result
|
||||
.setLhs( Catch::toString( arg ) )
|
||||
.setRhs( matcherAsString )
|
||||
.setOp( "matches" )
|
||||
.setResultType( matcher.match( arg ) ? ResultWas::Ok : ResultWas::ExpressionFailed );
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename MatcherT, typename ArgT>
|
||||
ExpressionBuilder& acceptMatcher( const MatcherT& matcher,
|
||||
ArgT* arg,
|
||||
const std::string& matcherCallAsString ) {
|
||||
std::string matcherAsString = matcher.toString();
|
||||
if( matcherAsString == "{?}" )
|
||||
matcherAsString = matcherCallAsString;
|
||||
m_result
|
||||
.setLhs( Catch::toString( arg ) )
|
||||
.setRhs( matcherAsString )
|
||||
.setOp( "matches" )
|
||||
.setResultType( matcher.match( arg ) ? ResultWas::Ok : ResultWas::ExpressionFailed );
|
||||
return *this;
|
||||
}
|
||||
|
||||
ExpressionBuilder& setResultType( ResultWas::OfType resultType ) {
|
||||
m_result.setResultType( resultType );
|
||||
return *this;
|
||||
}
|
||||
|
||||
operator ResultInfoBuilder&() {
|
||||
m_result.setMessage( m_messageStream.str() );
|
||||
return m_result;
|
||||
}
|
||||
|
||||
private:
|
||||
ResultInfoBuilder m_result;
|
||||
std::ostringstream m_messageStream;
|
||||
};
|
||||
|
||||
} // end namespace Catch
|
||||
|
||||
#endif // TWOBLUECUBES_CATCH_EXPRESSION_BUILDER_HPP_INCLUDED
|
31
include/internal/catch_expression_decomposer.hpp
Normal file
31
include/internal/catch_expression_decomposer.hpp
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Created by Phil on 11/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_EXPRESSION_DECOMPOSER_HPP_INCLUDED
|
||||
#define TWOBLUECUBES_CATCH_EXPRESSION_DECOMPOSER_HPP_INCLUDED
|
||||
|
||||
#include "catch_expression_lhs.hpp"
|
||||
|
||||
namespace Catch {
|
||||
|
||||
// Captures the LHS of the expression and wraps it in an Expression Lhs object
|
||||
class ExpressionDecomposer {
|
||||
public:
|
||||
|
||||
template<typename T>
|
||||
ExpressionLhs<const T&> operator->* ( const T & operand ) {
|
||||
return ExpressionLhs<const T&>( operand );
|
||||
}
|
||||
|
||||
ExpressionLhs<bool> operator->* ( bool value ) {
|
||||
return ExpressionLhs<bool>( value );
|
||||
}
|
||||
};
|
||||
|
||||
} // end namespace Catch
|
||||
|
||||
#endif // TWOBLUECUBES_CATCH_EXPRESSION_DECOMPOSER_HPP_INCLUDED
|
97
include/internal/catch_expression_lhs.hpp
Normal file
97
include/internal/catch_expression_lhs.hpp
Normal file
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Created by Phil on 11/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_EXPRESSION_LHS_HPP_INCLUDED
|
||||
#define TWOBLUECUBES_CATCH_EXPRESSION_LHS_HPP_INCLUDED
|
||||
|
||||
#include "catch_expressionresult_builder.h"
|
||||
#include "catch_evaluate.hpp"
|
||||
|
||||
namespace Catch {
|
||||
|
||||
struct STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison;
|
||||
|
||||
// Wraps the LHS of an expression and captures the operator and RHS (if any) - wrapping them all
|
||||
// in an ExpressionResultBuilder object
|
||||
template<typename T>
|
||||
class ExpressionLhs {
|
||||
void operator = ( const ExpressionLhs& );
|
||||
|
||||
public:
|
||||
ExpressionLhs( T lhs ) : m_lhs( lhs ) {}
|
||||
|
||||
template<typename RhsT>
|
||||
ExpressionResultBuilder& operator == ( const RhsT& rhs ) {
|
||||
return captureExpression<Internal::IsEqualTo>( rhs );
|
||||
}
|
||||
|
||||
template<typename RhsT>
|
||||
ExpressionResultBuilder& operator != ( const RhsT& rhs ) {
|
||||
return captureExpression<Internal::IsNotEqualTo>( rhs );
|
||||
}
|
||||
|
||||
template<typename RhsT>
|
||||
ExpressionResultBuilder& operator < ( const RhsT& rhs ) {
|
||||
return captureExpression<Internal::IsLessThan>( rhs );
|
||||
}
|
||||
|
||||
template<typename RhsT>
|
||||
ExpressionResultBuilder& operator > ( const RhsT& rhs ) {
|
||||
return captureExpression<Internal::IsGreaterThan>( rhs );
|
||||
}
|
||||
|
||||
template<typename RhsT>
|
||||
ExpressionResultBuilder& operator <= ( const RhsT& rhs ) {
|
||||
return captureExpression<Internal::IsLessThanOrEqualTo>( rhs );
|
||||
}
|
||||
|
||||
template<typename RhsT>
|
||||
ExpressionResultBuilder& operator >= ( const RhsT& rhs ) {
|
||||
return captureExpression<Internal::IsGreaterThanOrEqualTo>( rhs );
|
||||
}
|
||||
|
||||
ExpressionResultBuilder& operator == ( bool rhs ) {
|
||||
return captureExpression<Internal::IsEqualTo>( rhs );
|
||||
}
|
||||
|
||||
ExpressionResultBuilder& operator != ( bool rhs ) {
|
||||
return captureExpression<Internal::IsNotEqualTo>( rhs );
|
||||
}
|
||||
|
||||
ExpressionResultBuilder& negate( bool shouldNegate ) {
|
||||
bool value = m_lhs ? true : false;
|
||||
return m_result
|
||||
.setLhs( Catch::toString( value ) )
|
||||
.setResultType( value )
|
||||
.negate( shouldNegate );
|
||||
}
|
||||
|
||||
// Only simple binary expressions are allowed on the LHS.
|
||||
// If more complex compositions are required then place the sub expression in parentheses
|
||||
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& );
|
||||
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:
|
||||
template<Internal::Operator Op, typename RhsT>
|
||||
ExpressionResultBuilder& captureExpression( const RhsT& rhs ) {
|
||||
return m_result
|
||||
.setResultType( Internal::compare<Op>( m_lhs, rhs ) )
|
||||
.setLhs( Catch::toString( m_lhs ) )
|
||||
.setRhs( Catch::toString( rhs ) )
|
||||
.setOp( Internal::OperatorTraits<Op>::getName() );
|
||||
}
|
||||
|
||||
private:
|
||||
ExpressionResultBuilder m_result;
|
||||
T m_lhs;
|
||||
};
|
||||
|
||||
} // end namespace Catch
|
||||
|
||||
#endif // TWOBLUECUBES_CATCH_EXPRESSION_LHS_HPP_INCLUDED
|
58
include/internal/catch_expressionresult_builder.h
Normal file
58
include/internal/catch_expressionresult_builder.h
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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_ASSERTIONRESULT_BUILDER_H_INCLUDED
|
||||
#define TWOBLUECUBES_CATCH_ASSERTIONRESULT_BUILDER_H_INCLUDED
|
||||
|
||||
#include "catch_tostring.hpp"
|
||||
#include "catch_assertionresult.h"
|
||||
#include "catch_result_type.h"
|
||||
#include "catch_evaluate.hpp"
|
||||
#include "catch_common.h"
|
||||
|
||||
namespace Catch {
|
||||
|
||||
// Wraps the (stringised versions of) the lhs, operator and rhs of an expression - as well as
|
||||
// the result of evaluating it. This is used to build an AssertionResult object
|
||||
class ExpressionResultBuilder {
|
||||
public:
|
||||
|
||||
ExpressionResultBuilder( ResultWas::OfType resultType = ResultWas::Unknown );
|
||||
ExpressionResultBuilder( const ExpressionResultBuilder& other );
|
||||
ExpressionResultBuilder& operator=(const ExpressionResultBuilder& other );
|
||||
|
||||
ExpressionResultBuilder& setResultType( ResultWas::OfType result );
|
||||
ExpressionResultBuilder& setResultType( bool result );
|
||||
ExpressionResultBuilder& setLhs( const std::string& lhs );
|
||||
ExpressionResultBuilder& setRhs( const std::string& rhs );
|
||||
ExpressionResultBuilder& setOp( const std::string& op );
|
||||
|
||||
ExpressionResultBuilder& negate( bool shouldNegate );
|
||||
|
||||
template<typename T>
|
||||
ExpressionResultBuilder& operator << ( const T& value ) {
|
||||
m_stream << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::string reconstructExpression( const AssertionInfo& info ) const;
|
||||
|
||||
AssertionResult buildResult( const AssertionInfo& info ) const;
|
||||
|
||||
private:
|
||||
AssertionResultData m_data;
|
||||
struct ExprComponents {
|
||||
ExprComponents() : shouldNegate( false ) {}
|
||||
bool shouldNegate;
|
||||
std::string lhs, rhs, op;
|
||||
} m_exprComponents;
|
||||
std::ostringstream m_stream;
|
||||
};
|
||||
|
||||
} // end namespace Catch
|
||||
|
||||
#endif // TWOBLUECUBES_CATCH_ASSERTIONRESULT_BUILDER_H_INCLUDED
|
98
include/internal/catch_expressionresult_builder.hpp
Normal file
98
include/internal/catch_expressionresult_builder.hpp
Normal file
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Created by Phil on 8/8/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_EXPRESSIONRESULT_BUILDER_HPP_INCLUDED
|
||||
#define TWOBLUECUBES_CATCH_EXPRESSIONRESULT_BUILDER_HPP_INCLUDED
|
||||
|
||||
#include "catch_expressionresult_builder.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
namespace Catch {
|
||||
|
||||
ExpressionResultBuilder::ExpressionResultBuilder( ResultWas::OfType resultType ) {
|
||||
m_data.resultType = resultType;
|
||||
}
|
||||
ExpressionResultBuilder::ExpressionResultBuilder( const ExpressionResultBuilder& other )
|
||||
: m_data( other.m_data ),
|
||||
m_exprComponents( other.m_exprComponents )
|
||||
{
|
||||
m_stream << other.m_stream.str();
|
||||
}
|
||||
ExpressionResultBuilder& ExpressionResultBuilder::operator=(const ExpressionResultBuilder& other ) {
|
||||
m_data = other.m_data;
|
||||
m_exprComponents = other.m_exprComponents;
|
||||
m_stream.str("");
|
||||
m_stream << other.m_stream.str();
|
||||
return *this;
|
||||
}
|
||||
ExpressionResultBuilder& ExpressionResultBuilder::setResultType( ResultWas::OfType result ) {
|
||||
m_data.resultType = result;
|
||||
return *this;
|
||||
}
|
||||
ExpressionResultBuilder& ExpressionResultBuilder::setResultType( bool result ) {
|
||||
m_data.resultType = result ? ResultWas::Ok : ResultWas::ExpressionFailed;
|
||||
return *this;
|
||||
}
|
||||
ExpressionResultBuilder& ExpressionResultBuilder::negate( bool shouldNegate ) {
|
||||
m_exprComponents.shouldNegate = shouldNegate;
|
||||
return *this;
|
||||
}
|
||||
ExpressionResultBuilder& ExpressionResultBuilder::setLhs( const std::string& lhs ) {
|
||||
m_exprComponents.lhs = lhs;
|
||||
return *this;
|
||||
}
|
||||
ExpressionResultBuilder& ExpressionResultBuilder::setRhs( const std::string& rhs ) {
|
||||
m_exprComponents.rhs = rhs;
|
||||
return *this;
|
||||
}
|
||||
ExpressionResultBuilder& ExpressionResultBuilder::setOp( const std::string& op ) {
|
||||
m_exprComponents.op = op;
|
||||
return *this;
|
||||
}
|
||||
AssertionResult ExpressionResultBuilder::buildResult( const AssertionInfo& info ) const
|
||||
{
|
||||
assert( m_data.resultType != ResultWas::Unknown );
|
||||
|
||||
AssertionResultData data = m_data;
|
||||
|
||||
// Flip bool results if shouldNegate is set
|
||||
if( m_exprComponents.shouldNegate && data.resultType == ResultWas::Ok )
|
||||
data.resultType = ResultWas::ExpressionFailed;
|
||||
else if( m_exprComponents.shouldNegate && data.resultType == ResultWas::ExpressionFailed )
|
||||
data.resultType = ResultWas::Ok;
|
||||
|
||||
data.message = m_stream.str();
|
||||
data.reconstructedExpression = reconstructExpression( info );
|
||||
if( m_exprComponents.shouldNegate ) {
|
||||
if( m_exprComponents.op == "" )
|
||||
data.reconstructedExpression = "!" + data.reconstructedExpression;
|
||||
else
|
||||
data.reconstructedExpression = "!(" + data.reconstructedExpression + ")";
|
||||
}
|
||||
return AssertionResult( info, data );
|
||||
}
|
||||
std::string ExpressionResultBuilder::reconstructExpression( const AssertionInfo& info ) const {
|
||||
if( m_exprComponents.op == "" )
|
||||
return m_exprComponents.lhs.empty() ? info.capturedExpression : m_exprComponents.op + m_exprComponents.lhs;
|
||||
else if( m_exprComponents.op == "matches" )
|
||||
return m_exprComponents.lhs + " " + m_exprComponents.rhs;
|
||||
else if( m_exprComponents.op != "!" ) {
|
||||
if( m_exprComponents.lhs.size() + m_exprComponents.rhs.size() < 30 )
|
||||
return m_exprComponents.lhs + " " + m_exprComponents.op + " " + m_exprComponents.rhs;
|
||||
else if( m_exprComponents.lhs.size() < 70 && m_exprComponents.rhs.size() < 70 )
|
||||
return "\n\t" + m_exprComponents.lhs + "\n\t" + m_exprComponents.op + "\n\t" + m_exprComponents.rhs;
|
||||
else
|
||||
return "\n" + m_exprComponents.lhs + "\n" + m_exprComponents.op + "\n" + m_exprComponents.rhs + "\n\n";
|
||||
}
|
||||
else
|
||||
return "{can't expand - use " + info.macroName + "_FALSE( " + info.capturedExpression.substr(1) + " ) instead of " + info.macroName + "( " + info.capturedExpression + " ) for better diagnostics}";
|
||||
}
|
||||
|
||||
} // end namespace Catch
|
||||
|
||||
#endif // TWOBLUECUBES_CATCH_EXPRESSIONRESULT_BUILDER_HPP_INCLUDED
|
@@ -22,8 +22,8 @@
|
||||
#include "catch_context_impl.hpp"
|
||||
#include "catch_console_colour_impl.hpp"
|
||||
#include "catch_generators_impl.hpp"
|
||||
#include "catch_resultinfo.hpp"
|
||||
#include "catch_resultinfo_builder.hpp"
|
||||
#include "catch_assertionresult.hpp"
|
||||
#include "catch_expressionresult_builder.hpp"
|
||||
#include "catch_test_case_info.hpp"
|
||||
#include "catch_tags.hpp"
|
||||
|
||||
|
@@ -17,14 +17,15 @@ namespace Catch {
|
||||
|
||||
class TestCaseInfo;
|
||||
class ScopedInfo;
|
||||
class ResultInfoBuilder;
|
||||
class ResultInfo;
|
||||
class ExpressionResultBuilder;
|
||||
class AssertionResult;
|
||||
struct AssertionInfo;
|
||||
|
||||
struct IResultCapture {
|
||||
|
||||
virtual ~IResultCapture();
|
||||
|
||||
virtual void testEnded( const ResultInfo& result ) = 0;
|
||||
virtual void testEnded( const AssertionResult& result ) = 0;
|
||||
virtual bool sectionStarted( const std::string& name,
|
||||
const std::string& description,
|
||||
const SourceLineInfo& lineInfo,
|
||||
@@ -34,13 +35,11 @@ namespace Catch {
|
||||
virtual void popScopedInfo( ScopedInfo* scopedInfo ) = 0;
|
||||
virtual bool shouldDebugBreak() const = 0;
|
||||
|
||||
virtual ResultAction::Value acceptResult( bool result ) = 0;
|
||||
virtual ResultAction::Value acceptResult( ResultWas::OfType result ) = 0;
|
||||
virtual ResultAction::Value acceptExpression( const ResultInfoBuilder& resultInfo ) = 0;
|
||||
virtual void acceptMessage( const std::string& msg ) = 0;
|
||||
virtual void acceptAssertionInfo( const AssertionInfo& assertionInfo ) = 0;
|
||||
virtual ResultAction::Value acceptExpression( const ExpressionResultBuilder& assertionResult, const AssertionInfo& assertionInfo ) = 0;
|
||||
|
||||
virtual std::string getCurrentTestName() const = 0;
|
||||
virtual const ResultInfo* getLastResult() const = 0;
|
||||
virtual const AssertionResult* getLastResult() const = 0;
|
||||
};
|
||||
}
|
||||
|
||||
|
@@ -38,6 +38,8 @@ namespace Catch {
|
||||
IRegistryHub& getRegistryHub();
|
||||
IMutableRegistryHub& getMutableRegistryHub();
|
||||
void cleanUp();
|
||||
std::string translateActiveException();
|
||||
|
||||
}
|
||||
|
||||
#endif // TWOBLUECUBES_CATCH_INTERFACES_REGISTRY_HUB_H_INCLUDED
|
||||
|
@@ -49,23 +49,37 @@ namespace Catch
|
||||
};
|
||||
|
||||
class TestCaseInfo;
|
||||
class ResultInfo;
|
||||
class AssertionResult;
|
||||
|
||||
struct IReporter : IShared {
|
||||
virtual ~IReporter();
|
||||
virtual bool shouldRedirectStdout() const = 0;
|
||||
|
||||
virtual bool shouldRedirectStdout() const = 0;
|
||||
|
||||
virtual void StartTesting() = 0;
|
||||
virtual void EndTesting( const Totals& totals ) = 0;
|
||||
virtual void StartGroup( const std::string& groupName ) = 0;
|
||||
|
||||
virtual void StartGroup( const std::string& groupName ) = 0;
|
||||
virtual void EndGroup( const std::string& groupName, const Totals& totals ) = 0;
|
||||
|
||||
virtual void StartTestCase( const TestCaseInfo& testInfo ) = 0;
|
||||
// TestCaseResult
|
||||
virtual void EndTestCase( const TestCaseInfo& testInfo, const Totals& totals, const std::string& stdOut, const std::string& stdErr ) = 0;
|
||||
|
||||
// SectionInfo
|
||||
virtual void StartSection( const std::string& sectionName, const std::string& description ) = 0;
|
||||
// Section Result
|
||||
virtual void EndSection( const std::string& sectionName, const Counts& assertions ) = 0;
|
||||
|
||||
// - merge into SectionResult ?
|
||||
virtual void NoAssertionsInSection( const std::string& sectionName ) = 0;
|
||||
virtual void NoAssertionsInTestCase( const std::string& testName ) = 0;
|
||||
virtual void EndSection( const std::string& sectionName, const Counts& assertions ) = 0;
|
||||
virtual void StartTestCase( const TestCaseInfo& testInfo ) = 0;
|
||||
|
||||
// - merge into SectionResult, TestCaseResult, GroupResult & TestRunResult
|
||||
virtual void Aborted() = 0;
|
||||
virtual void EndTestCase( const TestCaseInfo& testInfo, const Totals& totals, const std::string& stdOut, const std::string& stdErr ) = 0;
|
||||
virtual void Result( const ResultInfo& result ) = 0;
|
||||
|
||||
// AssertionReslt
|
||||
virtual void Result( const AssertionResult& result ) = 0;
|
||||
};
|
||||
|
||||
struct IReporterFactory {
|
||||
|
@@ -73,6 +73,10 @@ namespace Catch {
|
||||
getTheRegistryHub() = NULL;
|
||||
cleanUpContext();
|
||||
}
|
||||
std::string translateActiveException() {
|
||||
return getRegistryHub().getExceptionTranslatorRegistry().translateActiveException();
|
||||
}
|
||||
|
||||
|
||||
} // end namespace Catch
|
||||
|
||||
|
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
* Created by Phil on 28/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_RESULTINFO_H_INCLUDED
|
||||
#define TWOBLUECUBES_CATCH_RESULTINFO_H_INCLUDED
|
||||
|
||||
#include <string>
|
||||
#include "catch_result_type.h"
|
||||
|
||||
namespace Catch {
|
||||
|
||||
struct ResultData
|
||||
{
|
||||
ResultData() : resultType( ResultWas::Unknown ) {}
|
||||
|
||||
std::string macroName;
|
||||
SourceLineInfo lineInfo;
|
||||
std::string capturedExpression;
|
||||
std::string reconstructedExpression;
|
||||
std::string message;
|
||||
ResultWas::OfType resultType;
|
||||
};
|
||||
|
||||
class ResultInfo {
|
||||
public:
|
||||
ResultInfo();
|
||||
ResultInfo( const ResultData& data );
|
||||
~ResultInfo();
|
||||
|
||||
bool ok() const;
|
||||
ResultWas::OfType getResultType() const;
|
||||
bool hasExpression() const;
|
||||
bool hasMessage() const;
|
||||
std::string getExpression() const;
|
||||
bool hasExpandedExpression() const;
|
||||
std::string getExpandedExpression() const;
|
||||
std::string getMessage() const;
|
||||
std::string getFilename() const;
|
||||
std::size_t getLine() const;
|
||||
std::string getTestMacroName() const;
|
||||
|
||||
protected:
|
||||
ResultData m_data;
|
||||
};
|
||||
|
||||
} // end namespace Catch
|
||||
|
||||
#endif // TWOBLUECUBES_CATCH_RESULTINFO_H_INCLUDED
|
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
* Created by Phil on 8/8/12
|
||||
* 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_HPP_INCLUDED
|
||||
#define TWOBLUECUBES_CATCH_RESULTINFO_HPP_INCLUDED
|
||||
|
||||
#include "catch_resultinfo.h"
|
||||
|
||||
namespace Catch {
|
||||
|
||||
ResultInfo::ResultInfo() {}
|
||||
|
||||
ResultInfo::ResultInfo( const ResultData& data ) : m_data( data ) {}
|
||||
|
||||
ResultInfo::~ResultInfo() {}
|
||||
|
||||
bool ResultInfo::ok() const {
|
||||
return isOk( m_data.resultType );
|
||||
}
|
||||
|
||||
ResultWas::OfType ResultInfo::getResultType() const {
|
||||
return m_data.resultType;
|
||||
}
|
||||
|
||||
bool ResultInfo::hasExpression() const {
|
||||
return !m_data.capturedExpression.empty();
|
||||
}
|
||||
|
||||
bool ResultInfo::hasMessage() const {
|
||||
return !m_data.message.empty();
|
||||
}
|
||||
|
||||
std::string ResultInfo::getExpression() const {
|
||||
return m_data.capturedExpression;
|
||||
}
|
||||
|
||||
bool ResultInfo::hasExpandedExpression() const {
|
||||
return hasExpression() && getExpandedExpression() != getExpression();
|
||||
}
|
||||
|
||||
std::string ResultInfo::getExpandedExpression() const {
|
||||
return m_data.reconstructedExpression;
|
||||
}
|
||||
|
||||
std::string ResultInfo::getMessage() const {
|
||||
return m_data.message;
|
||||
}
|
||||
|
||||
std::string ResultInfo::getFilename() const {
|
||||
return m_data.lineInfo.file;
|
||||
}
|
||||
|
||||
std::size_t ResultInfo::getLine() const {
|
||||
return m_data.lineInfo.line;
|
||||
}
|
||||
|
||||
std::string ResultInfo::getTestMacroName() const {
|
||||
return m_data.macroName;
|
||||
}
|
||||
|
||||
} // end namespace Catch
|
||||
|
||||
#endif // TWOBLUECUBES_CATCH_RESULTINFO_HPP_INCLUDED
|
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* 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:
|
||||
|
||||
ResultInfoBuilder();
|
||||
|
||||
ResultInfoBuilder& setResultType( ResultWas::OfType result );
|
||||
ResultInfoBuilder& setCapturedExpression( const std::string& capturedExpression );
|
||||
ResultInfoBuilder& setIsFalse( bool isFalse );
|
||||
ResultInfoBuilder& setMessage( const std::string& message );
|
||||
ResultInfoBuilder& setLineInfo( const SourceLineInfo& lineInfo );
|
||||
ResultInfoBuilder& setLhs( const std::string& lhs );
|
||||
ResultInfoBuilder& setRhs( const std::string& rhs );
|
||||
ResultInfoBuilder& setOp( const std::string& op );
|
||||
ResultInfoBuilder& setMacroName( const std::string& macroName );
|
||||
|
||||
std::string reconstructExpression() const;
|
||||
|
||||
ResultInfo build() const;
|
||||
|
||||
// Disable attempts to use || and && in expressions (without parantheses)
|
||||
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& );
|
||||
|
||||
bool getIsFalse() const {
|
||||
return m_isFalse;
|
||||
}
|
||||
|
||||
private:
|
||||
ResultData m_data;
|
||||
std::string m_lhs, m_rhs, m_op;
|
||||
bool m_isFalse;
|
||||
};
|
||||
|
||||
} // end namespace Catch
|
||||
|
||||
#endif // TWOBLUECUBES_CATCH_RESULTINFO_BUILDER_H_INCLUDED
|
@@ -1,102 +0,0 @@
|
||||
/*
|
||||
* Created by Phil on 8/8/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_HPP_INCLUDED
|
||||
#define TWOBLUECUBES_CATCH_RESULTINFO_BUILDER_HPP_INCLUDED
|
||||
|
||||
#include "catch_resultinfo_builder.h"
|
||||
|
||||
namespace Catch {
|
||||
|
||||
ResultInfoBuilder::ResultInfoBuilder() {}
|
||||
|
||||
ResultInfoBuilder& ResultInfoBuilder::setResultType( ResultWas::OfType result ) {
|
||||
// Flip bool results if isFalse is set
|
||||
if( m_isFalse && result == ResultWas::Ok )
|
||||
m_data.resultType = ResultWas::ExpressionFailed;
|
||||
else if( m_isFalse && result == ResultWas::ExpressionFailed )
|
||||
m_data.resultType = ResultWas::Ok;
|
||||
else
|
||||
m_data.resultType = result;
|
||||
return *this;
|
||||
}
|
||||
ResultInfoBuilder& ResultInfoBuilder::setCapturedExpression( const std::string& capturedExpression ) {
|
||||
m_data.capturedExpression = capturedExpression;
|
||||
return *this;
|
||||
}
|
||||
ResultInfoBuilder& ResultInfoBuilder::setIsFalse( bool isFalse ) {
|
||||
m_isFalse = isFalse;
|
||||
return *this;
|
||||
}
|
||||
|
||||
ResultInfoBuilder& ResultInfoBuilder::setMessage( const std::string& message ) {
|
||||
m_data.message = message;
|
||||
return *this;
|
||||
}
|
||||
|
||||
ResultInfoBuilder& ResultInfoBuilder::setLineInfo( const SourceLineInfo& lineInfo ) {
|
||||
m_data.lineInfo = lineInfo;
|
||||
return *this;
|
||||
}
|
||||
|
||||
ResultInfoBuilder& ResultInfoBuilder::setMacroName( const std::string& macroName ) {
|
||||
m_data.macroName = macroName;
|
||||
return *this;
|
||||
}
|
||||
|
||||
ResultInfoBuilder& ResultInfoBuilder::setLhs( const std::string& lhs ) {
|
||||
m_lhs = lhs;
|
||||
return *this;
|
||||
}
|
||||
|
||||
ResultInfoBuilder& ResultInfoBuilder::setRhs( const std::string& rhs ) {
|
||||
m_rhs = rhs;
|
||||
return *this;
|
||||
}
|
||||
|
||||
ResultInfoBuilder& ResultInfoBuilder::setOp( const std::string& op ) {
|
||||
m_op = op;
|
||||
return *this;
|
||||
}
|
||||
|
||||
ResultInfo ResultInfoBuilder::build() const
|
||||
{
|
||||
ResultData data = m_data;
|
||||
data.reconstructedExpression = reconstructExpression();
|
||||
if( m_isFalse ) {
|
||||
if( m_op == "" ) {
|
||||
data.capturedExpression = "!" + data.capturedExpression;
|
||||
data.reconstructedExpression = "!" + data.reconstructedExpression;
|
||||
}
|
||||
else {
|
||||
data.capturedExpression = "!(" + data.capturedExpression + ")";
|
||||
data.reconstructedExpression = "!(" + data.reconstructedExpression + ")";
|
||||
}
|
||||
}
|
||||
return ResultInfo( data );
|
||||
}
|
||||
|
||||
std::string ResultInfoBuilder::reconstructExpression() const {
|
||||
if( m_op == "" )
|
||||
return m_lhs.empty() ? m_data.capturedExpression : m_op + m_lhs;
|
||||
else if( m_op == "matches" )
|
||||
return m_lhs + " " + m_rhs;
|
||||
else if( m_op != "!" ) {
|
||||
if( m_lhs.size() + m_rhs.size() < 30 )
|
||||
return m_lhs + " " + m_op + " " + m_rhs;
|
||||
else if( m_lhs.size() < 70 && m_rhs.size() < 70 )
|
||||
return "\n\t" + m_lhs + "\n\t" + m_op + "\n\t" + m_rhs;
|
||||
else
|
||||
return "\n" + m_lhs + "\n" + m_op + "\n" + m_rhs + "\n\n";
|
||||
}
|
||||
else
|
||||
return "{can't expand - use " + m_data.macroName + "_FALSE( " + m_data.capturedExpression.substr(1) + " ) instead of " + m_data.macroName + "( " + m_data.capturedExpression + " ) for better diagnostics}";
|
||||
}
|
||||
|
||||
} // end namespace Catch
|
||||
|
||||
#endif // TWOBLUECUBES_CATCH_RESULTINFO_BUILDER_HPP_INCLUDED
|
@@ -109,7 +109,7 @@ namespace Catch {
|
||||
|
||||
do {
|
||||
do {
|
||||
m_currentResult.setLineInfo( m_runningTest->getTestCaseInfo().getLineInfo() );
|
||||
m_assertionInfo.lineInfo = m_runningTest->getTestCaseInfo().getLineInfo();
|
||||
runCurrentTest( redirectedCout, redirectedCerr );
|
||||
}
|
||||
while( m_runningTest->hasUntestedSections() && !aborting() );
|
||||
@@ -131,25 +131,17 @@ namespace Catch {
|
||||
|
||||
private: // IResultCapture
|
||||
|
||||
virtual ResultAction::Value acceptResult( bool result ) {
|
||||
return acceptResult( result ? ResultWas::Ok : ResultWas::ExpressionFailed );
|
||||
virtual void acceptAssertionInfo( const AssertionInfo& assertionInfo ) {
|
||||
m_assertionInfo = assertionInfo;
|
||||
}
|
||||
|
||||
virtual ResultAction::Value acceptResult( ResultWas::OfType result ) {
|
||||
m_currentResult.setResultType( result );
|
||||
|
||||
virtual ResultAction::Value acceptExpression( const ExpressionResultBuilder& assertionResult, const AssertionInfo& assertionInfo ) {
|
||||
m_assertionInfo = assertionInfo;
|
||||
m_currentResult = assertionResult;
|
||||
return actOnCurrentResult();
|
||||
}
|
||||
|
||||
virtual ResultAction::Value acceptExpression( const ResultInfoBuilder& resultInfo ) {
|
||||
m_currentResult = resultInfo;
|
||||
return actOnCurrentResult();
|
||||
}
|
||||
|
||||
virtual void acceptMessage( const std::string& msg ) {
|
||||
m_currentResult.setMessage( msg );
|
||||
}
|
||||
|
||||
virtual void testEnded( const ResultInfo& result ) {
|
||||
virtual void testEnded( const AssertionResult& result ) {
|
||||
if( result.getResultType() == ResultWas::Ok ) {
|
||||
m_totals.assertions.passed++;
|
||||
}
|
||||
@@ -160,19 +152,19 @@ namespace Catch {
|
||||
std::vector<ScopedInfo*>::const_iterator it = m_scopedInfos.begin();
|
||||
std::vector<ScopedInfo*>::const_iterator itEnd = m_scopedInfos.end();
|
||||
for(; it != itEnd; ++it )
|
||||
m_reporter->Result( (*it)->getInfo() );
|
||||
m_reporter->Result( (*it)->buildResult( m_assertionInfo ) );
|
||||
}
|
||||
{
|
||||
std::vector<ResultInfo>::const_iterator it = m_info.begin();
|
||||
std::vector<ResultInfo>::const_iterator itEnd = m_info.end();
|
||||
std::vector<AssertionResult>::const_iterator it = m_assertionResults.begin();
|
||||
std::vector<AssertionResult>::const_iterator itEnd = m_assertionResults.end();
|
||||
for(; it != itEnd; ++it )
|
||||
m_reporter->Result( *it );
|
||||
}
|
||||
m_info.clear();
|
||||
m_assertionResults.clear();
|
||||
}
|
||||
|
||||
if( result.getResultType() == ResultWas::Info )
|
||||
m_info.push_back( result );
|
||||
m_assertionResults.push_back( result );
|
||||
else
|
||||
m_reporter->Result( result );
|
||||
}
|
||||
@@ -190,7 +182,7 @@ namespace Catch {
|
||||
if( !m_runningTest->addSection( oss.str() ) )
|
||||
return false;
|
||||
|
||||
m_currentResult.setLineInfo( lineInfo );
|
||||
m_assertionInfo.lineInfo = lineInfo;
|
||||
m_reporter->StartSection( name, description );
|
||||
assertions = m_totals.assertions;
|
||||
|
||||
@@ -229,7 +221,7 @@ namespace Catch {
|
||||
: "";
|
||||
}
|
||||
|
||||
virtual const ResultInfo* getLastResult() const {
|
||||
virtual const AssertionResult* getLastResult() const {
|
||||
return &m_lastResult;
|
||||
}
|
||||
|
||||
@@ -242,10 +234,11 @@ namespace Catch {
|
||||
private:
|
||||
|
||||
ResultAction::Value actOnCurrentResult() {
|
||||
m_lastResult = m_currentResult.build();
|
||||
m_lastResult = m_currentResult.buildResult( m_assertionInfo );
|
||||
testEnded( m_lastResult );
|
||||
|
||||
m_currentResult = ResultInfoBuilder();
|
||||
m_currentResult = ExpressionResultBuilder();
|
||||
m_assertionInfo = AssertionInfo();
|
||||
|
||||
ResultAction::Value action = ResultAction::None;
|
||||
|
||||
@@ -284,26 +277,29 @@ namespace Catch {
|
||||
// This just means the test was aborted due to failure
|
||||
}
|
||||
catch(...) {
|
||||
acceptMessage( getRegistryHub().getExceptionTranslatorRegistry().translateActiveException() );
|
||||
acceptResult( ResultWas::ThrewException );
|
||||
m_currentResult
|
||||
.setResultType( ResultWas::ThrewException )
|
||||
<< translateActiveException();
|
||||
actOnCurrentResult();
|
||||
}
|
||||
m_info.clear();
|
||||
m_assertionResults.clear();
|
||||
}
|
||||
|
||||
private:
|
||||
IMutableContext& m_context;
|
||||
RunningTest* m_runningTest;
|
||||
ResultInfoBuilder m_currentResult;
|
||||
ResultInfo m_lastResult;
|
||||
ExpressionResultBuilder m_currentResult;
|
||||
AssertionResult m_lastResult;
|
||||
|
||||
const Config& m_config;
|
||||
Totals m_totals;
|
||||
Ptr<IReporter> m_reporter;
|
||||
std::vector<ScopedInfo*> m_scopedInfos;
|
||||
std::vector<ResultInfo> m_info;
|
||||
std::vector<AssertionResult> m_assertionResults;
|
||||
IRunner* m_prevRunner;
|
||||
IResultCapture* m_prevResultCapture;
|
||||
const IConfig* m_prevConfig;
|
||||
AssertionInfo m_assertionInfo;
|
||||
};
|
||||
|
||||
} // end namespace Catch
|
||||
|
@@ -74,10 +74,8 @@ namespace Catch {
|
||||
m_remainder += c;
|
||||
}
|
||||
|
||||
// Suppress assignment operator to avoid warnings from MSVC saying that
|
||||
// it can't be implicitly synthesized.
|
||||
TagExtracter& operator=(const TagExtracter&);
|
||||
|
||||
|
||||
std::set<std::string>& m_tags;
|
||||
std::string m_remainder;
|
||||
};
|
||||
@@ -181,8 +179,6 @@ namespace Catch {
|
||||
m_exp.m_tagSets.push_back( m_currentTagSet );
|
||||
}
|
||||
|
||||
// Suppress assignment operator to avoid warnings from MSVC saying that
|
||||
// it can't be implicitly synthesized.
|
||||
TagExpressionParser& operator=(const TagExpressionParser&);
|
||||
|
||||
bool m_isNegated;
|
||||
|
Reference in New Issue
Block a user