From 207b27b3c5ff52782c9af651b29bfb73f35d9a51 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Sat, 2 Feb 2013 19:58:04 +0000 Subject: [PATCH] Changed the way info messages are handled. This fixes issue with SCOPED_INFO and makes output more readable. Needs some refactoring. --- approvalTests.py | 5 +- include/catch.hpp | 8 +- include/internal/catch_capture.hpp | 38 +-- include/internal/catch_commandline.hpp | 2 +- include/internal/catch_impl.hpp | 1 + include/internal/catch_interfaces_capture.h | 12 +- include/internal/catch_interfaces_reporter.h | 14 +- include/internal/catch_message.h | 66 ++++ include/internal/catch_message.hpp | 57 ++++ include/internal/catch_result_type.h | 3 + include/internal/catch_runner_impl.hpp | 61 ++-- include/reporters/catch_reporter_console.hpp | 38 ++- .../SelfTest/Baselines/approvedResults.txt | 318 +++++------------- .../SelfTest/SurrogateCpps/catch_message.cpp | 2 + projects/SelfTest/catch_self_test.hpp | 2 +- .../CatchSelfTest.xcodeproj/project.pbxproj | 8 + 16 files changed, 334 insertions(+), 301 deletions(-) create mode 100644 include/internal/catch_message.h create mode 100644 include/internal/catch_message.hpp create mode 100644 projects/SelfTest/SurrogateCpps/catch_message.cpp diff --git a/approvalTests.py b/approvalTests.py index b0bf4845..c6ede479 100644 --- a/approvalTests.py +++ b/approvalTests.py @@ -11,7 +11,10 @@ baselinesPath = os.path.join( catchPath, 'projects/SelfTest/Baselines/approvedRe rawResultsPath = os.path.join( catchPath, 'projects/SelfTest/Baselines/_rawResults.tmp' ) filteredResultsPath = os.path.join( catchPath, 'projects/SelfTest/Baselines/unapprovedResults.txt' ) -cmdPath = sys.argv[1] +if len(sys.argv) == 2: + cmdPath = sys.argv[1] +else: + cmdPath = "projects/XCode4/CatchSelfTest/DerivedData/CatchSelfTest/Build/Products/Debug/CatchSelfTest" f = open( rawResultsPath, 'w' ) subprocess.call([ cmdPath, "~dummy", "-s", "-w", "NoAssertions", "-r", "console" ], stdout=f, stderr=f ) diff --git a/include/catch.hpp b/include/catch.hpp index 6fb0fd10..2519ebf6 100644 --- a/include/catch.hpp +++ b/include/catch.hpp @@ -68,12 +68,12 @@ #define CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( arg, matcher, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECK_THAT" ) #define CATCH_REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( arg, matcher, Catch::ResultDisposition::Normal, "CATCH_REQUIRE_THAT" ) -#define CATCH_INFO( msg ) INTERNAL_CATCH_MSG( msg, Catch::ResultWas::Info, Catch::ResultDisposition::ContinueOnFailure, "CATCH_INFO" ) +#define CATCH_INFO( msg ) INTERNAL_CATCH_INFO( msg, "CATCH_INFO" ) #define CATCH_WARN( msg ) INTERNAL_CATCH_MSG( msg, Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, "CATCH_WARN" ) #define CATCH_FAIL( msg ) INTERNAL_CATCH_MSG( msg, Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, "CATCH_FAIL" ) #define CATCH_SUCCEED( msg ) INTERNAL_CATCH_MSG( msg, Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, "CATCH_SUCCEED" ) #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, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CAPTURE" ) +#define CATCH_CAPTURE( msg ) INTERNAL_CATCH_INFO( #msg " := " << msg, "CATCH_CAPTURE" ) #define CATCH_SCOPED_CAPTURE( msg ) INTERNAL_CATCH_SCOPED_INFO( #msg " := " << msg, "CATCH_SCOPED_CAPTURE" ) #define CATCH_SECTION( name, description ) INTERNAL_CATCH_SECTION( name, description ) @@ -111,12 +111,12 @@ #define CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( arg, matcher, Catch::ResultDisposition::ContinueOnFailure, "CHECK_THAT" ) #define REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( arg, matcher, Catch::ResultDisposition::Normal, "REQUIRE_THAT" ) -#define INFO( msg ) INTERNAL_CATCH_MSG( msg, Catch::ResultWas::Info, Catch::ResultDisposition::ContinueOnFailure, "INFO" ) +#define INFO( msg ) INTERNAL_CATCH_INFO( msg, "INFO" ) #define WARN( msg ) INTERNAL_CATCH_MSG( msg, Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, "WARN" ) #define FAIL( msg ) INTERNAL_CATCH_MSG( msg, Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, "FAIL" ) #define SUCCEED( msg ) INTERNAL_CATCH_MSG( msg, Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, "SUCCEED" ) #define SCOPED_INFO( msg ) INTERNAL_CATCH_SCOPED_INFO( msg, "SCOPED_INFO" ) -#define CAPTURE( msg ) INTERNAL_CATCH_MSG( #msg " := " << msg, Catch::ResultWas::Info, Catch::ResultDisposition::ContinueOnFailure, "CAPTURE" ) +#define CAPTURE( msg ) INTERNAL_CATCH_INFO( #msg " := " << msg, "CAPTURE" ) #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_capture.hpp b/include/internal/catch_capture.hpp index e2919848..a32528a9 100644 --- a/include/internal/catch_capture.hpp +++ b/include/internal/catch_capture.hpp @@ -10,6 +10,7 @@ #include "catch_expression_decomposer.hpp" #include "catch_expressionresult_builder.h" +#include "catch_message.h" #include "catch_interfaces_capture.h" #include "catch_debugger.hpp" #include "catch_context.h" @@ -54,26 +55,6 @@ namespace Catch { struct TestFailureException{}; -class ScopedInfo { -public: - ScopedInfo() : m_resultBuilder( ResultWas::Info ) { - getResultCapture().pushScopedInfo( this ); - } - ~ScopedInfo() { - getResultCapture().popScopedInfo( this ); - } - template - ScopedInfo& operator << ( const T& value ) { - m_resultBuilder << value; - return *this; - } - AssertionResult buildResult( const AssertionInfo& assertionInfo ) const { - return m_resultBuilder.buildResult( assertionInfo ); - } - -private: - ExpressionResultBuilder m_resultBuilder; -}; // This is just here to avoid compiler warnings with macro constants and boolean literals inline bool isTrue( bool value ){ return value; } @@ -168,17 +149,24 @@ inline bool isTrue( bool value ){ return value; } } while( Catch::isTrue( false ) ) /////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CATCH_MSG( reason, resultType, resultDisposition, macroName ) \ +#define INTERNAL_CATCH_INFO( log, macroName ) \ + do { \ + Catch::getResultCapture().acceptMessage( Catch::MessageBuilder( macroName, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log ); \ + } while( Catch::isTrue( false ) ) + +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CATCH_MSG( log, messageType, resultDisposition, macroName ) \ do { \ INTERNAL_CATCH_ACCEPT_INFO( "", macroName, resultDisposition ); \ - INTERNAL_CATCH_ACCEPT_EXPR( Catch::ExpressionResultBuilder( resultType ) << reason, resultDisposition, true ) \ + INTERNAL_CATCH_ACCEPT_EXPR( Catch::ExpressionResultBuilder( messageType ) << log, resultDisposition, true ) \ } while( Catch::isTrue( false ) ) /////////////////////////////////////////////////////////////////////////////// #define INTERNAL_CATCH_SCOPED_INFO( log, macroName ) \ - INTERNAL_CATCH_ACCEPT_INFO( "", macroName, Catch::ResultDisposition::Normal ); \ - Catch::ScopedInfo INTERNAL_CATCH_UNIQUE_NAME( info ); \ - INTERNAL_CATCH_UNIQUE_NAME( info ) << log + Catch::ScopedMessageBuilder INTERNAL_CATCH_UNIQUE_NAME( scopedMessage )( macroName, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ); \ + INTERNAL_CATCH_UNIQUE_NAME( scopedMessage ) << log; \ + Catch::getResultCapture().pushScopedMessage( INTERNAL_CATCH_UNIQUE_NAME( scopedMessage ) ) + /////////////////////////////////////////////////////////////////////////////// #define INTERNAL_CHECK_THAT( arg, matcher, resultDisposition, macroName ) \ diff --git a/include/internal/catch_commandline.hpp b/include/internal/catch_commandline.hpp index 660cbffe..f95eaca8 100644 --- a/include/internal/catch_commandline.hpp +++ b/include/internal/catch_commandline.hpp @@ -148,7 +148,7 @@ namespace Catch { virtual void parseIntoConfig( const Command& cmd, ConfigData& config ) = 0; virtual std::string argsSynopsis() const = 0; virtual std::string optionSummary() const = 0; - virtual std::string optionDescription() const { return ""; }; + virtual std::string optionDescription() const { return ""; } std::string optionNames() const { std::string names; diff --git a/include/internal/catch_impl.hpp b/include/internal/catch_impl.hpp index f8f2baa4..fc610748 100644 --- a/include/internal/catch_impl.hpp +++ b/include/internal/catch_impl.hpp @@ -28,6 +28,7 @@ #include "catch_tags.hpp" #include "catch_version.hpp" #include "catch_line_wrap.hpp" +#include "catch_message.hpp" #include "../reporters/catch_reporter_basic.hpp" #include "../reporters/catch_reporter_xml.hpp" diff --git a/include/internal/catch_interfaces_capture.h b/include/internal/catch_interfaces_capture.h index 08147055..2c52e90f 100644 --- a/include/internal/catch_interfaces_capture.h +++ b/include/internal/catch_interfaces_capture.h @@ -21,19 +21,25 @@ namespace Catch { class AssertionResult; struct AssertionInfo; struct SectionInfo; + class MessageBuilder; + class ScopedMessageBuilder; struct IResultCapture { virtual ~IResultCapture(); - virtual void testEnded( AssertionResult const& result ) = 0; + virtual void assertionEnded( AssertionResult const& result ) = 0; virtual bool sectionStarted( SectionInfo const& sectionInfo, Counts& assertions ) = 0; virtual void sectionEnded( SectionInfo const& name, Counts const& assertions ) = 0; - virtual void pushScopedInfo( ScopedInfo* scopedInfo ) = 0; - virtual void popScopedInfo( ScopedInfo* scopedInfo ) = 0; + virtual void pushScopedInfo( ScopedInfo* scopedInfo ) = 0; // !TBD Deprecated + virtual void popScopedInfo( ScopedInfo* scopedInfo ) = 0; // !TBD Deprecated + virtual void pushScopedMessage( ScopedMessageBuilder const& _builder ) = 0; + virtual void popScopedMessage( ScopedMessageBuilder const& _builder ) = 0; + virtual bool shouldDebugBreak() const = 0; + virtual void acceptMessage( const MessageBuilder& messageBuilder ) = 0; virtual ResultAction::Value acceptExpression( ExpressionResultBuilder const& assertionResult, AssertionInfo const& assertionInfo ) = 0; virtual std::string getCurrentTestName() const = 0; diff --git a/include/internal/catch_interfaces_reporter.h b/include/internal/catch_interfaces_reporter.h index e6743f06..8fa7cf1a 100644 --- a/include/internal/catch_interfaces_reporter.h +++ b/include/internal/catch_interfaces_reporter.h @@ -14,6 +14,7 @@ #include "catch_config.hpp" #include "catch_test_case_info.h" #include "catch_assertionresult.h" +#include "catch_message.h" #include "catch_option.hpp" #include @@ -89,13 +90,24 @@ namespace Catch struct AssertionStats { AssertionStats( AssertionResult const& _assertionResult, + std::vector const& _infoMessages, Totals const& _totals ) : assertionResult( _assertionResult ), + infoMessages( _infoMessages ), totals( _totals ) - {} + { + if( assertionResult.hasMessage() ) { + // Copy message into messages list. + // !TBD This should have been done earlier, somewhere + MessageBuilder builder( assertionResult.getTestMacroName(), assertionResult.getSourceInfo(), assertionResult.getResultType() ); + builder << assertionResult.getMessage(); + infoMessages.push_back( builder.build() ); + } + } virtual ~AssertionStats(); AssertionResult assertionResult; + std::vector infoMessages; Totals totals; }; diff --git a/include/internal/catch_message.h b/include/internal/catch_message.h new file mode 100644 index 00000000..b3d4af1e --- /dev/null +++ b/include/internal/catch_message.h @@ -0,0 +1,66 @@ +/* + * Created by Phil Nash on 1/2/2013. + * Copyright 2013 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_MESSAGE_H_INCLUDED +#define TWOBLUECUBES_CATCH_MESSAGE_H_INCLUDED + +#include +#include "catch_result_type.h" +#include "catch_common.h" + +namespace Catch { + + struct MessageInfo { + MessageInfo( std::string const& _macroName, + SourceLineInfo const& _lineInfo, + ResultWas::OfType _type ); + + std::string macroName; + SourceLineInfo lineInfo; + ResultWas::OfType type; + std::string message; + unsigned int sequence; + + bool operator == ( MessageInfo const& other ) const { + return sequence == other.sequence; + } + bool operator < ( MessageInfo const& other ) const { + return sequence < other.sequence; + } + private: + static unsigned int globalCount; + }; + + + class MessageBuilder : public MessageInfo { + public: + MessageBuilder( std::string const& _macroName, + SourceLineInfo const& _lineInfo, + ResultWas::OfType _type ); + + MessageInfo build() const; + + template + MessageBuilder& operator << ( T const& _value ) { + stream << _value; + return *this; + } + private: + std::ostringstream stream; + }; + + class ScopedMessageBuilder : public MessageBuilder { + public: + ScopedMessageBuilder( std::string const& _macroName, + SourceLineInfo const& _lineInfo, + ResultWas::OfType _type ); + ~ScopedMessageBuilder(); + }; + +} // end namespace Catch + +#endif // TWOBLUECUBES_CATCH_MESSAGE_H_INCLUDED diff --git a/include/internal/catch_message.hpp b/include/internal/catch_message.hpp new file mode 100644 index 00000000..c6996aa9 --- /dev/null +++ b/include/internal/catch_message.hpp @@ -0,0 +1,57 @@ +/* + * Created by Phil Nash on 1/2/2013. + * Copyright 2013 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_MESSAGE_HPP_INCLUDED +#define TWOBLUECUBES_CATCH_MESSAGE_HPP_INCLUDED + +#include "catch_message.h" + +namespace Catch { + + MessageInfo::MessageInfo( std::string const& _macroName, + SourceLineInfo const& _lineInfo, + ResultWas::OfType _type ) + : macroName( _macroName ), + lineInfo( _lineInfo ), + type( _type ), + sequence( ++globalCount ) + {} + + // This may need protecting if threading support is added + unsigned int MessageInfo::globalCount = 0; + + //////////////////////////////////////////////////////////////////////////// + + MessageBuilder::MessageBuilder( std::string const& _macroName, + SourceLineInfo const& _lineInfo, + ResultWas::OfType _type ) + : MessageInfo( _macroName, _lineInfo, _type ) + {} + + MessageInfo MessageBuilder::build() const { + MessageInfo message = *this; + message.message = stream.str(); + return message; + } + + //////////////////////////////////////////////////////////////////////////// + + ScopedMessageBuilder::ScopedMessageBuilder + ( std::string const& _macroName, + SourceLineInfo const& _lineInfo, + ResultWas::OfType _type ) + : MessageBuilder( _macroName, _lineInfo, _type ) + {} + + ScopedMessageBuilder::~ScopedMessageBuilder() { + getResultCapture().popScopedMessage( *this ); + } + + +} // end namespace Catch + +#endif // TWOBLUECUBES_CATCH_MESSAGE_HPP_INCLUDED diff --git a/include/internal/catch_result_type.h b/include/internal/catch_result_type.h index 5492531e..36aab4c9 100644 --- a/include/internal/catch_result_type.h +++ b/include/internal/catch_result_type.h @@ -32,6 +32,9 @@ namespace Catch { inline bool isOk( ResultWas::OfType resultType ) { return ( resultType & ResultWas::FailureBit ) == 0; } + inline bool isJustInfo( int flags ) { + return flags == ResultWas::Info; + } // ResultAction::Value enum struct ResultAction { enum Value { diff --git a/include/internal/catch_runner_impl.hpp b/include/internal/catch_runner_impl.hpp index 03f1fcde..eceb92cf 100644 --- a/include/internal/catch_runner_impl.hpp +++ b/include/internal/catch_runner_impl.hpp @@ -155,43 +155,49 @@ namespace Catch { private: // IResultCapture + virtual void acceptMessage( const MessageBuilder& messageBuilder ) { + m_messages.push_back( messageBuilder.build() ); + } + virtual ResultAction::Value acceptExpression( const ExpressionResultBuilder& assertionResult, const AssertionInfo& assertionInfo ) { m_lastAssertionInfo = assertionInfo; return actOnCurrentResult( assertionResult.buildResult( assertionInfo ) ); } - virtual void testEnded( const AssertionResult& result ) { + virtual void assertionEnded( const AssertionResult& result ) { if( result.getResultType() == ResultWas::Ok ) { m_totals.assertions.passed++; } else if( !result.isOk() ) { m_totals.assertions.failed++; - { - std::vector::const_iterator it = m_scopedInfos.begin(); - std::vector::const_iterator itEnd = m_scopedInfos.end(); - for(; it != itEnd; ++it ) - m_reporter->assertionEnded( AssertionStats( (*it)->buildResult( m_lastAssertionInfo ), m_totals ) ); - } - { - std::vector::const_iterator it = m_assertionResults.begin(); - std::vector::const_iterator itEnd = m_assertionResults.end(); - for(; it != itEnd; ++it ) - m_reporter->assertionEnded( AssertionStats( *it, m_totals ) ); - } - m_assertionResults.clear(); +// { +// std::vector::const_iterator it = m_scopedInfos.begin(); +// std::vector::const_iterator itEnd = m_scopedInfos.end(); +// for(; it != itEnd; ++it ) +// m_reporter->assertionEnded( AssertionStats( (*it)->buildResult( m_lastAssertionInfo ), m_totals ) ); +// } +// { +// std::vector::const_iterator it = m_assertionResults.begin(); +// std::vector::const_iterator itEnd = m_assertionResults.end(); +// for(; it != itEnd; ++it ) +// m_reporter->assertionEnded( AssertionStats( *it, m_totals ) ); +// } +// m_assertionResults.clear(); } - if( result.getResultType() == ResultWas::Info ) - { + if( result.getResultType() == ResultWas::Info ) { + // !TBD: deprecated? - what does this even do? m_assertionResults.push_back( result ); m_totals.assertions.info++; } - else - m_reporter->assertionEnded( AssertionStats( result, m_totals ) ); + else { + m_reporter->assertionEnded( AssertionStats( result, m_messages, m_totals ) ); + } // Reset AssertionInfo - m_lastAssertionInfo = AssertionInfo( "", m_lastAssertionInfo.lineInfo, "{Unknown expression after this line}" , m_lastAssertionInfo.resultDisposition ); + m_lastAssertionInfo = AssertionInfo( "", m_lastAssertionInfo.lineInfo, "{Unknown expression after the reported line}" , m_lastAssertionInfo.resultDisposition ); + m_messages.clear(); } virtual bool sectionStarted ( @@ -229,6 +235,7 @@ namespace Catch { m_runningTest->endSection( info.name ); m_reporter->sectionEnded( SectionStats( info, assertions, missingAssertions ) ); + m_messages.clear(); } virtual void pushScopedInfo( ScopedInfo* scopedInfo ) { @@ -239,8 +246,15 @@ namespace Catch { if( m_scopedInfos.back() == scopedInfo ) m_scopedInfos.pop_back(); } + virtual void pushScopedMessage( ScopedMessageBuilder const& _builder ) { + m_messages.push_back( _builder.build() ); + } + + virtual void popScopedMessage( ScopedMessageBuilder const& _builder ) { + m_messages.erase( std::remove( m_messages.begin(), m_messages.end(), _builder ), m_messages.end() ); + } - virtual bool shouldDebugBreak() const { + virtual bool shouldDebugBreak() const { return m_config.shouldDebugBreak(); } @@ -264,7 +278,7 @@ namespace Catch { ResultAction::Value actOnCurrentResult( const AssertionResult& result ) { m_lastResult = result; - testEnded( m_lastResult ); + assertionEnded( m_lastResult ); ResultAction::Value action = ResultAction::None; @@ -312,8 +326,9 @@ namespace Catch { const Config& m_config; Totals m_totals; Ptr m_reporter; - std::vector m_scopedInfos; - std::vector m_assertionResults; + std::vector m_scopedInfos; // !TBD: deprecated + std::vector m_assertionResults; // !TBD: deprecated + std::vector m_messages; IRunner* m_prevRunner; IResultCapture* m_prevResultCapture; const IConfig* m_prevConfig; diff --git a/include/reporters/catch_reporter_console.hpp b/include/reporters/catch_reporter_console.hpp index 3101dab9..3acfb8e9 100644 --- a/include/reporters/catch_reporter_console.hpp +++ b/include/reporters/catch_reporter_console.hpp @@ -98,14 +98,18 @@ namespace Catch { stats( _stats ), result( _stats.assertionResult ), colour( TextColour::None ), - message( result.getMessage() ) + message( result.getMessage() ), + messages( _stats.infoMessages ) { switch( result.getResultType() ) { case ResultWas::Ok: colour = TextColour::Success; passOrFail = "PASSED"; - if( result.hasMessage() ) + //if( result.hasMessage() ) + if( _stats.infoMessages.size() == 1 ) messageLabel = "with message"; + if( _stats.infoMessages.size() > 1 ) + messageLabel = "with messages"; break; case ResultWas::ExpressionFailed: if( result.isOk() ) { @@ -116,9 +120,13 @@ namespace Catch { colour = TextColour::Error; passOrFail = "FAILED"; } - if( result.hasMessage() ){ + if( _stats.infoMessages.size() == 1 ) messageLabel = "with message"; - } + if( _stats.infoMessages.size() > 1 ) + messageLabel = "with messages"; +// if( result.hasMessage() ){ +// messageLabel = "with message"; +// } break; case ResultWas::ThrewException: colour = TextColour::Error; @@ -139,13 +147,21 @@ namespace Catch { case ResultWas::ExplicitFailure: passOrFail = "FAILED"; colour = TextColour::Error; - messageLabel = "explicitly with message"; +// messageLabel = "explicitly with message"; + if( _stats.infoMessages.size() == 1 ) + messageLabel = "explicitly with message"; + if( _stats.infoMessages.size() > 1 ) + messageLabel = "explicitly with messages"; break; case ResultWas::Exception: passOrFail = "FAILED"; colour = TextColour::Error; - if( result.hasMessage() ) + if( _stats.infoMessages.size() == 1 ) messageLabel = "with message"; + if( _stats.infoMessages.size() > 1 ) + messageLabel = "with messages"; +// if( result.hasMessage() ) +// messageLabel = "with message"; break; // These cases are here to prevent compiler warnings @@ -196,8 +212,13 @@ namespace Catch { void printMessage() const { if( !messageLabel.empty() ) stream << messageLabel << ":" << "\n"; - if( !message.empty() ) - stream << wrapLongStrings( message ) << "\n"; + for( std::vector::const_iterator it = messages.begin(), itEnd = messages.end(); + it != itEnd; + ++it ) { + stream << wrapLongStrings( it->message ) << "\n"; + } +// if( !message.empty() ) +// stream << wrapLongStrings( message ) << "\n"; } void printSourceInfo() const { TextColour colourGuard( TextColour::FileName ); @@ -215,6 +236,7 @@ namespace Catch { std::string passOrFail; std::string messageLabel; std::string message; + std::vector messages; }; void lazyPrint() { diff --git a/projects/SelfTest/Baselines/approvedResults.txt b/projects/SelfTest/Baselines/approvedResults.txt index 78475fcb..9f20d66e 100644 --- a/projects/SelfTest/Baselines/approvedResults.txt +++ b/projects/SelfTest/Baselines/approvedResults.txt @@ -1,5 +1,5 @@ -CatchSelfTest is a CATCH v0.9 b15 (integration) host application. +CatchSelfTest is a CATCH v0.9 b16 (integration) host application. Run with -? for options ------------------------------------------------------------------------------- @@ -1055,7 +1055,7 @@ PASSED: ExceptionTests.cpp:60: FAILED: - {Unknown expression after this line} + {Unknown expression after the reported line} due to unexpected exception with message: unexpected exception ExceptionTests.cpp:60: @@ -2002,6 +2002,7 @@ GeneratorTests.cpp:40: ............................................................................... warning: + this is a message this is a warning MessageTests.cpp:14: @@ -2021,18 +2022,13 @@ MessageTests.cpp:18: ./failing/message/info/1 ............................................................................... -info: - this message should be logged -MessageTests.cpp:23: - -info: - so should this -MessageTests.cpp:24: - FAILED: REQUIRE( a == 1 ) with expansion: 2 == 1 +with messages: + this message should be logged + so should this MessageTests.cpp:26: ------------------------------------------------------------------------------- @@ -2043,36 +2039,32 @@ PASSED: CHECK( a == 2 ) with expansion: 2 == 2 -MessageTests.cpp:33: - -info: +with message: this message should be logged -MessageTests.cpp:31: - -info: - this message should be logged, too -MessageTests.cpp:35: +MessageTests.cpp:33: FAILED: CHECK( a == 1 ) with expansion: 2 == 1 +with message: + this message should be logged, too MessageTests.cpp:37: -info: - and this, but later -MessageTests.cpp:39: - FAILED: CHECK( a == 0 ) with expansion: 2 == 0 +with message: + and this, but later MessageTests.cpp:41: PASSED: CHECK( a == 2 ) with expansion: 2 == 2 +with message: + but not this MessageTests.cpp:45: ------------------------------------------------------------------------------- @@ -2130,76 +2122,99 @@ PASSED: REQUIRE( i < 10 ) with expansion: 0 < 10 +with messages: + current counter 0 + i := 0 MessageTests.cpp:86: PASSED: REQUIRE( i < 10 ) with expansion: 1 < 10 +with messages: + current counter 1 + i := 1 MessageTests.cpp:86: PASSED: REQUIRE( i < 10 ) with expansion: 2 < 10 +with messages: + current counter 2 + i := 2 MessageTests.cpp:86: PASSED: REQUIRE( i < 10 ) with expansion: 3 < 10 +with messages: + current counter 3 + i := 3 MessageTests.cpp:86: PASSED: REQUIRE( i < 10 ) with expansion: 4 < 10 +with messages: + current counter 4 + i := 4 MessageTests.cpp:86: PASSED: REQUIRE( i < 10 ) with expansion: 5 < 10 +with messages: + current counter 5 + i := 5 MessageTests.cpp:86: PASSED: REQUIRE( i < 10 ) with expansion: 6 < 10 +with messages: + current counter 6 + i := 6 MessageTests.cpp:86: PASSED: REQUIRE( i < 10 ) with expansion: 7 < 10 +with messages: + current counter 7 + i := 7 MessageTests.cpp:86: PASSED: REQUIRE( i < 10 ) with expansion: 8 < 10 +with messages: + current counter 8 + i := 8 MessageTests.cpp:86: PASSED: REQUIRE( i < 10 ) with expansion: 9 < 10 -MessageTests.cpp:86: - - REQUIRE( i < 10 ) -info: - current counter 10 -MessageTests.cpp:86: - - REQUIRE( i < 10 ) -info: - i := 10 +with messages: + current counter 9 + i := 9 MessageTests.cpp:86: FAILED: REQUIRE( i < 10 ) with expansion: 10 < 10 +with messages: + current counter 10 + i := 10 MessageTests.cpp:86: ------------------------------------------------------------------------------- @@ -2347,84 +2362,68 @@ MiscTests.cpp:103: ./mixed/Misc/loops ............................................................................... -info: +FAILED: + CHECK( ( fib[i] % 2 ) == 0 ) +with expansion: + 1 == 0 +with message: Testing if fib[0] (1) is even -MiscTests.cpp:114: +MiscTests.cpp:115: FAILED: CHECK( ( fib[i] % 2 ) == 0 ) with expansion: 1 == 0 -MiscTests.cpp:115: - -info: +with message: Testing if fib[1] (1) is even -MiscTests.cpp:114: - -FAILED: - CHECK( ( fib[i] % 2 ) == 0 ) -with expansion: - 1 == 0 MiscTests.cpp:115: PASSED: CHECK( ( fib[i] % 2 ) == 0 ) with expansion: 0 == 0 -MiscTests.cpp:115: - -info: +with message: Testing if fib[2] (2) is even -MiscTests.cpp:114: - -info: - Testing if fib[3] (3) is even -MiscTests.cpp:114: - -FAILED: - CHECK( ( fib[i] % 2 ) == 0 ) -with expansion: - 1 == 0 MiscTests.cpp:115: -info: - Testing if fib[4] (5) is even -MiscTests.cpp:114: +FAILED: + CHECK( ( fib[i] % 2 ) == 0 ) +with expansion: + 1 == 0 +with message: + Testing if fib[3] (3) is even +MiscTests.cpp:115: FAILED: CHECK( ( fib[i] % 2 ) == 0 ) with expansion: 1 == 0 +with message: + Testing if fib[4] (5) is even MiscTests.cpp:115: PASSED: CHECK( ( fib[i] % 2 ) == 0 ) with expansion: 0 == 0 -MiscTests.cpp:115: - -info: +with message: Testing if fib[5] (8) is even -MiscTests.cpp:114: - -info: - Testing if fib[6] (13) is even -MiscTests.cpp:114: - -FAILED: - CHECK( ( fib[i] % 2 ) == 0 ) -with expansion: - 1 == 0 MiscTests.cpp:115: -info: - Testing if fib[7] (21) is even -MiscTests.cpp:114: +FAILED: + CHECK( ( fib[i] % 2 ) == 0 ) +with expansion: + 1 == 0 +with message: + Testing if fib[6] (13) is even +MiscTests.cpp:115: FAILED: CHECK( ( fib[i] % 2 ) == 0 ) with expansion: 1 == 0 +with message: + Testing if fib[7] (21) is even MiscTests.cpp:115: Some information @@ -2456,16 +2455,11 @@ MiscTests.cpp:134: ./failing/info ............................................................................... -info: - hi -MiscTests.cpp:139: - -info: - i := 7 -MiscTests.cpp:141: - FAILED: REQUIRE( false ) +with messages: + hi + i := 7 MiscTests.cpp:142: ------------------------------------------------------------------------------- @@ -2552,12 +2546,10 @@ No assertions in section, 'encoded chars' ./manual/onechar ............................................................................... -info: - 3 -MiscTests.cpp:195: - FAILED: REQUIRE( false ) +with message: + 3 MiscTests.cpp:196: ------------------------------------------------------------------------------- @@ -4246,7 +4238,7 @@ BDDTests.cpp:29: 96 test cases - 45 failed (610 assertions - 102 failed) -CatchSelfTest is a CATCH v0.9 b15 (integration) host application. +CatchSelfTest is a CATCH v0.9 b16 (integration) host application. Run with -? for options ------------------------------------------------------------------------------- @@ -4715,7 +4707,7 @@ ExceptionTests.cpp:52 - + ExceptionTests.cpp:60 @@ -4750,29 +4742,14 @@ MessageTests.cpp:14 - -MessageTests.cpp:23 - - -MessageTests.cpp:24 - MessageTests.cpp:26 - -MessageTests.cpp:31 - - -MessageTests.cpp:35 - MessageTests.cpp:37 - -MessageTests.cpp:39 - MessageTests.cpp:41 @@ -4797,12 +4774,6 @@ Message from section two - -MessageTests.cpp:86 - - -MessageTests.cpp:86 - MessageTests.cpp:86 @@ -4826,45 +4797,21 @@ MiscTests.cpp:103 - -MiscTests.cpp:114 - MiscTests.cpp:115 - -MiscTests.cpp:114 - MiscTests.cpp:115 - -MiscTests.cpp:114 - - -MiscTests.cpp:114 - MiscTests.cpp:115 - -MiscTests.cpp:114 - MiscTests.cpp:115 - -MiscTests.cpp:114 - - -MiscTests.cpp:114 - MiscTests.cpp:115 - -MiscTests.cpp:114 - MiscTests.cpp:115 @@ -4879,12 +4826,6 @@ An error - -MiscTests.cpp:139 - - -MiscTests.cpp:141 - MiscTests.cpp:142 @@ -4909,9 +4850,6 @@ MiscTests.cpp:178 - -MiscTests.cpp:195 - MiscTests.cpp:196 @@ -6403,10 +6341,10 @@ ExceptionTests.cpp" line="60"> ExceptionTests.cpp" line="60"> - {Unknown expression after this line} + {Unknown expression after the reported line} - {Unknown expression after this line} + {Unknown expression after the reported line} ExceptionTests.cpp" line="60"> unexpected exception @@ -7652,12 +7590,6 @@ GeneratorTests.cpp" line="40"> - - this message should be logged - - - so should this - MessageTests.cpp" line="26"> a == 1 @@ -7677,12 +7609,6 @@ MessageTests.cpp" line="33"> 2 == 2 - - this message should be logged - - - this message should be logged, too - MessageTests.cpp" line="37"> a == 1 @@ -7691,9 +7617,6 @@ MessageTests.cpp" line="37"> 2 == 1 - - and this, but later - MessageTests.cpp" line="41"> a == 0 @@ -7823,28 +7746,6 @@ MessageTests.cpp" line="86"> 9 < 10 -MessageTests.cpp" line="86"> - - i < 10 - - - i < 10 - - - current counter 10 - - -MessageTests.cpp" line="86"> - - i < 10 - - - i < 10 - - - i := 10 - - MessageTests.cpp" line="86"> i < 10 @@ -8013,9 +7914,6 @@ MiscTests.cpp" line="103"> - - Testing if fib[0] (1) is even - MiscTests.cpp" line="115"> ( fib[i] % 2 ) == 0 @@ -8024,9 +7922,6 @@ MiscTests.cpp" line="115"> 1 == 0 - - Testing if fib[1] (1) is even - MiscTests.cpp" line="115"> ( fib[i] % 2 ) == 0 @@ -8043,12 +7938,6 @@ MiscTests.cpp" line="115"> 0 == 0 - - Testing if fib[2] (2) is even - - - Testing if fib[3] (3) is even - MiscTests.cpp" line="115"> ( fib[i] % 2 ) == 0 @@ -8057,9 +7946,6 @@ MiscTests.cpp" line="115"> 1 == 0 - - Testing if fib[4] (5) is even - MiscTests.cpp" line="115"> ( fib[i] % 2 ) == 0 @@ -8076,12 +7962,6 @@ MiscTests.cpp" line="115"> 0 == 0 - - Testing if fib[5] (8) is even - - - Testing if fib[6] (13) is even - MiscTests.cpp" line="115"> ( fib[i] % 2 ) == 0 @@ -8090,9 +7970,6 @@ MiscTests.cpp" line="115"> 1 == 0 - - Testing if fib[7] (21) is even - MiscTests.cpp" line="115"> ( fib[i] % 2 ) == 0 @@ -8126,12 +8003,6 @@ MiscTests.cpp" line="134"> - - hi - - - i := 7 - MiscTests.cpp" line="142"> false @@ -8228,9 +8099,6 @@ MiscTests.cpp" line="178"> - - 3 - MiscTests.cpp" line="196"> false @@ -10136,7 +10004,7 @@ ExceptionTests.cpp:52: Unexpected exception with message: 'unexpected exception' [Running: ./failing/exceptions/implicit/2] ExceptionTests.cpp:60: 1 == 1 succeeded -ExceptionTests.cpp:60: {Unknown expression after this line} failed with unexpected exception with message: 'unexpected exception' +ExceptionTests.cpp:60: {Unknown expression after the reported line} failed with unexpected exception with message: 'unexpected exception' [Finished: './failing/exceptions/implicit/2' 1 test case failed (1 of 2 assertions failed)] [Running: ./succeeding/exceptions/implicit] @@ -10330,17 +10198,12 @@ MessageTests.cpp:18: succeeded [Finished: './succeeding/succeed' All tests passed (1 assertion in 1 test case)] [Running: ./failing/message/info/1] -MessageTests.cpp:23: [info: this message should be logged] -MessageTests.cpp:24: [info: so should this] MessageTests.cpp:26: a == 1 failed for: 2 == 1 [Finished: './failing/message/info/1' 1 test case failed (1 assertion failed)] [Running: ./mixed/message/info/2] MessageTests.cpp:33: a == 2 succeeded for: 2 == 2 -MessageTests.cpp:31: [info: this message should be logged] -MessageTests.cpp:35: [info: this message should be logged, too] MessageTests.cpp:37: a == 1 failed for: 2 == 1 -MessageTests.cpp:39: [info: and this, but later] MessageTests.cpp:41: a == 0 failed for: 2 == 0 MessageTests.cpp:45: a == 2 succeeded for: 2 == 2 [Finished: './mixed/message/info/2' 1 test case failed (2 of 4 assertions failed)] @@ -10389,8 +10252,6 @@ MessageTests.cpp:86: i < 10 succeeded for: 6 < 10 MessageTests.cpp:86: i < 10 succeeded for: 7 < 10 MessageTests.cpp:86: i < 10 succeeded for: 8 < 10 MessageTests.cpp:86: i < 10 succeeded for: 9 < 10 -MessageTests.cpp:86: i < 10 succeeded[info: current counter 10] -MessageTests.cpp:86: i < 10 succeeded[info: i := 10] MessageTests.cpp:86: i < 10 failed for: 10 < 10 [Finished: './mixed/message/scoped' 1 test case failed (1 of 11 assertions failed)] @@ -10484,21 +10345,13 @@ MiscTests.cpp:103: b > a failed for: 0 > 1 [Finished: './mixed/Misc/Sections/loops' 1 test case failed (1 assertion failed)] [Running: ./mixed/Misc/loops] -MiscTests.cpp:114: [info: Testing if fib[0] (1) is even] MiscTests.cpp:115: ( fib[i] % 2 ) == 0 failed for: 1 == 0 -MiscTests.cpp:114: [info: Testing if fib[1] (1) is even] MiscTests.cpp:115: ( fib[i] % 2 ) == 0 failed for: 1 == 0 MiscTests.cpp:115: ( fib[i] % 2 ) == 0 succeeded for: 0 == 0 -MiscTests.cpp:114: [info: Testing if fib[2] (2) is even] -MiscTests.cpp:114: [info: Testing if fib[3] (3) is even] MiscTests.cpp:115: ( fib[i] % 2 ) == 0 failed for: 1 == 0 -MiscTests.cpp:114: [info: Testing if fib[4] (5) is even] MiscTests.cpp:115: ( fib[i] % 2 ) == 0 failed for: 1 == 0 MiscTests.cpp:115: ( fib[i] % 2 ) == 0 succeeded for: 0 == 0 -MiscTests.cpp:114: [info: Testing if fib[5] (8) is even] -MiscTests.cpp:114: [info: Testing if fib[6] (13) is even] MiscTests.cpp:115: ( fib[i] % 2 ) == 0 failed for: 1 == 0 -MiscTests.cpp:114: [info: Testing if fib[7] (21) is even] MiscTests.cpp:115: ( fib[i] % 2 ) == 0 failed for: 1 == 0 [Finished: './mixed/Misc/loops' 1 test case failed (6 of 8 assertions failed)] Some information @@ -10516,8 +10369,6 @@ MiscTests.cpp:134: makeString( true ) == static_cast(__null) succeeded fo [Finished: './succeeding/Misc/null strings' All tests passed (2 assertions in 1 test case)] [Running: ./failing/info] -MiscTests.cpp:139: [info: hi] -MiscTests.cpp:141: [info: i := 7] MiscTests.cpp:142: false failed [Finished: './failing/info' 1 test case failed (1 assertion failed)] @@ -10557,7 +10408,6 @@ No assertions in section, 'encoded chars' [Finished: './misc/xmlentitycheck' 1 test case failed (All 2 assertions failed)] [Running: ./manual/onechar] -MiscTests.cpp:195: [info: 3] MiscTests.cpp:196: false failed [Finished: './manual/onechar' 1 test case failed (1 assertion failed)] diff --git a/projects/SelfTest/SurrogateCpps/catch_message.cpp b/projects/SelfTest/SurrogateCpps/catch_message.cpp new file mode 100644 index 00000000..257c8b06 --- /dev/null +++ b/projects/SelfTest/SurrogateCpps/catch_message.cpp @@ -0,0 +1,2 @@ +// This file is only here to verify (to the extent possible) the self sufficiency of the header +#include "catch_message.h" diff --git a/projects/SelfTest/catch_self_test.hpp b/projects/SelfTest/catch_self_test.hpp index cb62187f..44293e0c 100644 --- a/projects/SelfTest/catch_self_test.hpp +++ b/projects/SelfTest/catch_self_test.hpp @@ -115,7 +115,7 @@ namespace Catch { } break; } - }; + } private: Expected::Result m_expectedResult; diff --git a/projects/XCode4/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj b/projects/XCode4/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj index a8d139bb..f2777cb7 100644 --- a/projects/XCode4/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj +++ b/projects/XCode4/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 26847E5F16BBADB40043B9C1 /* catch_message.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26847E5D16BBADB40043B9C1 /* catch_message.cpp */; }; 2694A1FD16A0000E004816E3 /* catch_line_wrap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2694A1FB16A0000E004816E3 /* catch_line_wrap.cpp */; }; 4A45DA2416161EF9004F8D6B /* catch_console_colour.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4A45DA2316161EF9004F8D6B /* catch_console_colour.cpp */; }; 4A45DA2716161F1F004F8D6B /* catch_ptr.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4A45DA2616161F1F004F8D6B /* catch_ptr.cpp */; }; @@ -53,6 +54,9 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 26847E5B16BBAB790043B9C1 /* catch_message.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = catch_message.h; sourceTree = ""; }; + 26847E5C16BBACB60043B9C1 /* catch_message.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = catch_message.hpp; sourceTree = ""; }; + 26847E5D16BBADB40043B9C1 /* catch_message.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = catch_message.cpp; path = ../../../SelfTest/SurrogateCpps/catch_message.cpp; sourceTree = ""; }; 2694A1F8169FFF9B004816E3 /* catch_line_wrap.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = catch_line_wrap.h; sourceTree = ""; }; 2694A1FA169FFFEC004816E3 /* catch_line_wrap.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = catch_line_wrap.hpp; sourceTree = ""; }; 2694A1FB16A0000E004816E3 /* catch_line_wrap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = catch_line_wrap.cpp; sourceTree = ""; }; @@ -275,6 +279,7 @@ 4AB3D9A1161621B500C9A0F8 /* catch_interfaces_generators.cpp */, 4ACE21CA166CA1B300FB5509 /* catch_option.cpp */, 2694A1FB16A0000E004816E3 /* catch_line_wrap.cpp */, + 26847E5D16BBADB40043B9C1 /* catch_message.cpp */, ); name = SurrogateCpps; sourceTree = ""; @@ -294,6 +299,7 @@ 4A90B59E15D2521E00EF71BC /* catch_expressionresult_builder.hpp */, 4A084F1C15DACEEA0027E631 /* catch_test_case_info.hpp */, 2694A1FA169FFFEC004816E3 /* catch_line_wrap.hpp */, + 26847E5C16BBACB60043B9C1 /* catch_message.hpp */, ); name = impl; sourceTree = ""; @@ -314,6 +320,7 @@ 4AC91CCE155CF02800DC5117 /* catch_expression_lhs.hpp */, 4AC91CD0155D8DA600DC5117 /* catch_expression_decomposer.hpp */, 4A4B0F9A15CEF84800AE2392 /* catch_notimplemented_exception.h */, + 26847E5B16BBAB790043B9C1 /* catch_message.h */, ); name = Assertions; sourceTree = ""; @@ -473,6 +480,7 @@ 4AB3D9A2161621B500C9A0F8 /* catch_interfaces_generators.cpp in Sources */, 4ACE21CC166CA1B300FB5509 /* catch_option.cpp in Sources */, 2694A1FD16A0000E004816E3 /* catch_line_wrap.cpp in Sources */, + 26847E5F16BBADB40043B9C1 /* catch_message.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; };