Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorPhil Nash2012-11-01 08:27:09 +0000
committerPhil Nash2012-11-01 08:27:09 +0000
commitce612bf6562f62236edc5f416a8aabc29e63ebc1 (patch)
tree7bad95748607295fc7c555c0f978059bde4ca879 /include
parentb18d719f9d8a6960379832b13c47baaeffe8183d (diff)
downloadcatch3-ce612bf6562f62236edc5f416a8aabc29e63ebc1.tar.gz
Squashed commit of the following:
commit 2a1e8bfc6ed3bcc1e3746d717726a9e525de6369 Author: Phil Nash <github@philnash.me> Date: Thu Nov 1 08:16:15 2012 +0000 Updated colour comments commit f0f407fc3ebdcbdad50fc1f9a45f15ab3cc54c63 Author: Phil Nash <github@philnash.me> Date: Wed Oct 31 18:28:21 2012 +0000 Manually applied merge #133 from Master commit 355b95fda1de28ba830541768aad32c7b1790290 Author: Phil Nash <github@philnash.me> Date: Wed Oct 31 18:04:22 2012 +0000 Cleaned up ANSI colour code impl a bit commit 778f9c4fc7fa66566679d9f1d8a721079d8589bf Author: Phil Nash <github@philnash.me> Date: Tue Oct 30 09:09:30 2012 +0000 Removed "no-" from Wno-global-constructors when disabling commit 5efa4bcb8a620efa13e8eb5e68d0899681919ca1 Author: Phil Nash <github@philnash.me> Date: Mon Oct 29 20:49:22 2012 +0000 Regenerated single_include commit 108f1937d8cbe04038ab8d2aaf9f6e958fe8168c 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 commit 8f4cc541d55cf55b2a67b5d6b77b5c4ceb4d99ee Author: Phil Nash <github@philnash.me> Date: Mon Oct 29 19:55:34 2012 +0000 Added regression test baselines commit 2e203a183474672e386f4cf840847cf29ccf90b9 Author: Phil Nash <github@philnash.me> Date: Mon Oct 29 19:55:13 2012 +0000 Fixed remaining reporting regressions commit 134e45b3ade922e5cbdb2df6b81830fbd93fe448 Author: Phil Nash <github@philnash.me> Date: Sun Oct 28 20:57:21 2012 +0000 Fixed #132 commit 2f92db9898978ca1ee27c964d8a51fa507391935 Author: Phil Nash <github@philnash.me> Date: Sun Oct 28 12:15:34 2012 +0000 Updated the readme specifically for the Integration branch commit 82acc2ca05459ce353de71469f141ba93e9b63cf Author: Phil Nash <github@philnash.me> Date: Sun Oct 28 12:07:17 2012 +0000 Regenerated single include commit fe1d7c1d08f06c0a83b727e9b2e00cc49e74175d Author: Phil Nash <github@philnash.me> Date: Sun Oct 28 10:27:44 2012 +0000 Small fixes and tweaks commit 355b5e546d2f64dd0abbc0134dd3579ce6c28cea Author: Phil Nash <github@philnash.me> Date: Fri Oct 26 09:05:36 2012 +0100 Some tidy-up commit f847186ebbf0e7eeabd99925574c8988add600fb Author: Phil Nash <github@philnash.me> Date: Fri Oct 26 08:45:23 2012 +0100 AssertionResultBuilder -> ExpressionResultBuilder commit 8cca2f13699aa6aa5cd4a60e293f49a1bae54629 Author: Phil Nash <github@philnash.me> Date: Wed Oct 24 22:09:01 2012 +0100 ExpressionBuilder ->ExpressionDecomposer Expression -> ExpressionLhs commit e04e74f896c714de1f03a9cc006bcd071318ea11 Author: Phil Nash <github@philnash.me> Date: Wed Oct 24 21:59:47 2012 +0100 More AssertionResult refactoring commit 1dd56d4d2b29520cdd62f5f449a28e67f954f5db Author: Phil Nash <github@philnash.me> Date: Fri Oct 19 08:01:34 2012 +0100 AssertionResultBuilder can be constructed from result type commit f2d5f1b3e444055ff02ed0536d5d0610b08ecb9f 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 commit e3b111a39a4edd3bfe4d88290c99c723b8b74417 Author: Phil Nash <github@philnash.me> Date: Thu Oct 18 22:59:16 2012 +0100 streamlined acceptResult commit 3ad13256e1e50a6ee4a2697e7b6d0f669ae82ab5 Author: Phil Nash <github@philnash.me> Date: Thu Oct 18 08:39:44 2012 +0100 Refactored assertion builder stuff out of expression builder commit c96f9330a095f527673de4d8db4f434d38a7e813 Author: Phil Nash <github@philnash.me> Date: Wed Oct 17 08:14:22 2012 +0100 Collect assertion info up front commit a5fa78284d6d95770cd647a2ec10df09d378ba46 Author: Phil Nash <github@philnash.me> Date: Tue Oct 16 08:33:13 2012 +0100 ResultData -> AssertionResultData commit c597a893fa95462b8d2d5029547d4054eda1839f Author: Phil Nash <github@philnash.me> Date: Tue Oct 16 08:31:05 2012 +0100 ResultInfo -> AssertionResult filenames and variables commit d16955f63a4a128221da41602215b5592df39eb9 Author: Phil Nash <github@philnash.me> Date: Tue Oct 16 08:27:21 2012 +0100 Renamed ResultInfo -> AssertionResult commit 175da3ef6454b6fa0465d22c96d21d58dd9d2f90 Author: Phil Nash <github@philnash.me> Date: Fri Oct 12 18:39:22 2012 +0100 regen test 3
Diffstat (limited to 'include')
-rw-r--r--include/catch.hpp10
-rw-r--r--include/internal/catch_assertionresult.h66
-rw-r--r--include/internal/catch_assertionresult.hpp65
-rw-r--r--include/internal/catch_capture.hpp173
-rw-r--r--include/internal/catch_common.h3
-rw-r--r--include/internal/catch_console_colour_impl.hpp60
-rw-r--r--include/internal/catch_expression.hpp90
-rw-r--r--include/internal/catch_expression_builder.hpp102
-rw-r--r--include/internal/catch_expression_decomposer.hpp31
-rw-r--r--include/internal/catch_expression_lhs.hpp97
-rw-r--r--include/internal/catch_expressionresult_builder.h58
-rw-r--r--include/internal/catch_expressionresult_builder.hpp98
-rw-r--r--include/internal/catch_impl.hpp4
-rw-r--r--include/internal/catch_interfaces_capture.h15
-rw-r--r--include/internal/catch_interfaces_registry_hub.h2
-rw-r--r--include/internal/catch_interfaces_reporter.h28
-rw-r--r--include/internal/catch_registry_hub.hpp4
-rw-r--r--include/internal/catch_resultinfo.h52
-rw-r--r--include/internal/catch_resultinfo.hpp67
-rw-r--r--include/internal/catch_resultinfo_builder.h58
-rw-r--r--include/internal/catch_resultinfo_builder.hpp102
-rw-r--r--include/internal/catch_runner_impl.hpp58
-rw-r--r--include/internal/catch_tags.hpp6
-rw-r--r--include/reporters/catch_reporter_basic.hpp81
-rw-r--r--include/reporters/catch_reporter_junit.hpp16
-rw-r--r--include/reporters/catch_reporter_xml.hpp34
26 files changed, 728 insertions, 652 deletions
diff --git a/include/catch.hpp b/include/catch.hpp
index dc66cf00..219b6172 100644
--- a/include/catch.hpp
+++ b/include/catch.hpp
@@ -10,7 +10,7 @@
#define TWOBLUECUBES_CATCH_HPP_INCLUDED
#ifdef __clang__
-#pragma clang diagnostic ignored "-Wno-global-constructors"
+#pragma clang diagnostic ignored "-Wglobal-constructors"
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wpadded"
@@ -71,9 +71,9 @@
#define CATCH_WARN( msg ) INTERNAL_CATCH_MSG( msg, Catch::ResultWas::Warning, false, "CATCH_WARN" )
#define CATCH_FAIL( msg ) INTERNAL_CATCH_MSG( msg, Catch::ResultWas::ExplicitFailure, true, "CATCH_FAIL" )
#define CATCH_SUCCEED( msg ) INTERNAL_CATCH_MSG( msg, Catch::ResultWas::Ok, false, "CATCH_SUCCEED" )
-#define CATCH_SCOPED_INFO( msg ) INTERNAL_CATCH_SCOPED_INFO( msg )
+#define CATCH_SCOPED_INFO( msg ) INTERNAL_CATCH_SCOPED_INFO( msg, "CATCH_SCOPED_INFO" )
#define CATCH_CAPTURE( msg ) INTERNAL_CATCH_MSG( #msg " := " << msg, Catch::ResultWas::Info, false, "CATCH_CAPTURE" )
-#define CATCH_SCOPED_CAPTURE( msg ) INTERNAL_CATCH_SCOPED_INFO( #msg " := " << msg )
+#define CATCH_SCOPED_CAPTURE( msg ) INTERNAL_CATCH_SCOPED_INFO( #msg " := " << msg, "CATCH_SCOPED_CAPTURE" )
#define CATCH_SECTION( name, description ) INTERNAL_CATCH_SECTION( name, description )
@@ -116,9 +116,9 @@
#define WARN( msg ) INTERNAL_CATCH_MSG( msg, Catch::ResultWas::Warning, false, "WARN" )
#define FAIL( msg ) INTERNAL_CATCH_MSG( msg, Catch::ResultWas::ExplicitFailure, true, "FAIL" )
#define SUCCEED( msg ) INTERNAL_CATCH_MSG( msg, Catch::ResultWas::Ok, false, "SUCCEED" )
-#define SCOPED_INFO( msg ) INTERNAL_CATCH_SCOPED_INFO( msg )
+#define SCOPED_INFO( msg ) INTERNAL_CATCH_SCOPED_INFO( msg, "SCOPED_INFO" )
#define CAPTURE( msg ) INTERNAL_CATCH_MSG( #msg " := " << msg, Catch::ResultWas::Info, false, "CAPTURE" )
-#define SCOPED_CAPTURE( msg ) INTERNAL_CATCH_SCOPED_INFO( #msg " := " << msg )
+#define SCOPED_CAPTURE( msg ) INTERNAL_CATCH_SCOPED_INFO( #msg " := " << msg, "SCOPED_CAPTURE" )
#define SECTION( name, description ) INTERNAL_CATCH_SECTION( name, description )
diff --git a/include/internal/catch_assertionresult.h b/include/internal/catch_assertionresult.h
new file mode 100644
index 00000000..b3baff2e
--- /dev/null
+++ b/include/internal/catch_assertionresult.h
@@ -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
diff --git a/include/internal/catch_assertionresult.hpp b/include/internal/catch_assertionresult.hpp
new file mode 100644
index 00000000..f1ef9d18
--- /dev/null
+++ b/include/internal/catch_assertionresult.hpp
@@ -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
diff --git a/include/internal/catch_capture.hpp b/include/internal/catch_capture.hpp
index 381c0dd0..484383c5 100644
--- a/include/internal/catch_capture.hpp
+++ b/include/internal/catch_capture.hpp
@@ -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
diff --git a/include/internal/catch_common.h b/include/internal/catch_common.h
index 49c5918e..cac5d112 100644
--- a/include/internal/catch_common.h
+++ b/include/internal/catch_common.h
@@ -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;
diff --git a/include/internal/catch_console_colour_impl.hpp b/include/internal/catch_console_colour_impl.hpp
index 1830e182..c05fd07f 100644
--- a/include/internal/catch_console_colour_impl.hpp
+++ b/include/internal/catch_console_colour_impl.hpp
@@ -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
diff --git a/include/internal/catch_expression.hpp b/include/internal/catch_expression.hpp
deleted file mode 100644
index 0fa0920c..00000000
--- a/include/internal/catch_expression.hpp
+++ /dev/null
@@ -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::IsLessThan