diff --git a/include/internal/catch_capture.hpp b/include/internal/catch_capture.hpp index b882c05b..120883ba 100644 --- a/include/internal/catch_capture.hpp +++ b/include/internal/catch_capture.hpp @@ -364,35 +364,21 @@ private: class ScopedInfo { public: - /////////////////////////////////////////////////////////////////////////// - ScopedInfo - () : m_oss() - { + ScopedInfo() : m_oss() { Hub::getResultCapture().pushScopedInfo( this ); } - /////////////////////////////////////////////////////////////////////////// - ~ScopedInfo - () - { + ~ScopedInfo() { Hub::getResultCapture().popScopedInfo( this ); } - /////////////////////////////////////////////////////////////////////////// - ScopedInfo& operator << - ( - const char* str - ) - { - m_oss << str; + template + ScopedInfo& operator << ( const T& value ) { + m_oss << value; return *this; } - /////////////////////////////////////////////////////////////////////////// - std::string getInfo - () - const - { + std::string getInfo () const { return m_oss.str(); } @@ -400,35 +386,28 @@ private: std::ostringstream m_oss; }; -/////////////////////////////////////////////////////////////////////////////// // This is just here to avoid compiler warnings with macro constants -inline bool isTrue -( - bool value -) -{ - return value; -} +inline bool isTrue( bool value ){ return value; } } // end namespace Catch /////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CATCH_ACCEPT_EXPR( expr, stopOnFailure ) \ +#define INTERNAL_CATCH_ACCEPT_EXPR( expr, stopOnFailure, originalExpr ) \ if( Catch::ResultAction::Value internal_catch_action = Catch::Hub::getResultCapture().acceptExpression( expr ) ) \ { \ if( internal_catch_action == Catch::ResultAction::DebugFailed ) BreakIntoDebugger(); \ if( Catch::isTrue( stopOnFailure ) ) throw Catch::TestFailureException(); \ + if( Catch::isTrue( false ) ){ bool this_is_here_to_invoke_warnings = ( originalExpr ); Catch::isTrue( this_is_here_to_invoke_warnings ); } \ } /////////////////////////////////////////////////////////////////////////////// #define INTERNAL_CATCH_TEST( expr, isNot, stopOnFailure, macroName ) \ do{ try{ \ - INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ResultBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr, isNot )->*expr ), stopOnFailure ); \ - if( Catch::isTrue( false ) ){ bool internal_catch_dummyResult = ( expr ); Catch::isTrue( internal_catch_dummyResult ); } \ + INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ResultBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr, isNot )->*expr ), stopOnFailure, expr ); \ }catch( Catch::TestFailureException& ){ \ throw; \ } catch( ... ){ \ - INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ResultBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr ) << Catch::Hub::getExceptionTranslatorRegistry().translateActiveException() ).setResultType( Catch::ResultWas::ThrewException ), false ); \ + INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ResultBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr ) << Catch::Hub::getExceptionTranslatorRegistry().translateActiveException() ).setResultType( Catch::ResultWas::ThrewException ), false, expr ); \ throw; \ }}while( Catch::isTrue( false ) ) @@ -447,11 +426,11 @@ inline bool isTrue try \ { \ expr; \ - INTERNAL_CATCH_ACCEPT_EXPR( Catch::ResultBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr ).setResultType( Catch::ResultWas::Ok ), stopOnFailure ); \ + INTERNAL_CATCH_ACCEPT_EXPR( Catch::ResultBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr ).setResultType( Catch::ResultWas::Ok ), stopOnFailure, false ); \ } \ catch( ... ) \ { \ - INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ResultBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr ) << Catch::Hub::getExceptionTranslatorRegistry().translateActiveException() ).setResultType( Catch::ResultWas::ThrewException ), stopOnFailure ); \ + INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ResultBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr ) << Catch::Hub::getExceptionTranslatorRegistry().translateActiveException() ).setResultType( Catch::ResultWas::ThrewException ), stopOnFailure, false ); \ } /////////////////////////////////////////////////////////////////////////////// @@ -459,7 +438,7 @@ inline bool isTrue try \ { \ expr; \ - INTERNAL_CATCH_ACCEPT_EXPR( Catch::ResultBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr ).setResultType( Catch::ResultWas::DidntThrowException ), stopOnFailure ); \ + INTERNAL_CATCH_ACCEPT_EXPR( Catch::ResultBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr ).setResultType( Catch::ResultWas::DidntThrowException ), stopOnFailure, false ); \ } \ catch( Catch::TestFailureException& ) \ { \ @@ -467,7 +446,7 @@ inline bool isTrue } \ catch( exceptionType ) \ { \ - INTERNAL_CATCH_ACCEPT_EXPR( Catch::ResultBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr ).setResultType( Catch::ResultWas::Ok ), stopOnFailure ); \ + INTERNAL_CATCH_ACCEPT_EXPR( Catch::ResultBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr ).setResultType( Catch::ResultWas::Ok ), stopOnFailure, false ); \ } /////////////////////////////////////////////////////////////////////////////// @@ -475,7 +454,7 @@ inline bool isTrue INTERNAL_CATCH_THROWS( expr, exceptionType, stopOnFailure, macroName ) \ catch( ... ) \ { \ - INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ResultBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr ) << Catch::Hub::getExceptionTranslatorRegistry().translateActiveException() ).setResultType( Catch::ResultWas::ThrewException ), stopOnFailure ); \ + INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ResultBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr ) << Catch::Hub::getExceptionTranslatorRegistry().translateActiveException() ).setResultType( Catch::ResultWas::ThrewException ), stopOnFailure, false ); \ } /////////////////////////////////////////////////////////////////////////////// @@ -490,11 +469,11 @@ inline bool isTrue /////////////////////////////////////////////////////////////////////////////// #define INTERNAL_CHECK_THAT( arg, matcher, stopOnFailure, macroName ) \ do{ try{ \ - INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ResultBuilder( CATCH_INTERNAL_LINEINFO, macroName, #arg " " #matcher, false ).acceptMatcher( matcher, arg, #matcher ) ), stopOnFailure ); \ + INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ResultBuilder( CATCH_INTERNAL_LINEINFO, macroName, #arg " " #matcher, false ).acceptMatcher( matcher, arg, #matcher ) ), stopOnFailure, false ); \ }catch( Catch::TestFailureException& ){ \ throw; \ } catch( ... ){ \ - INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ResultBuilder( CATCH_INTERNAL_LINEINFO, macroName, #arg " " #matcher ) << Catch::Hub::getExceptionTranslatorRegistry().translateActiveException() ).setResultType( Catch::ResultWas::ThrewException ), false ); \ + INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ResultBuilder( CATCH_INTERNAL_LINEINFO, macroName, #arg " " #matcher ) << Catch::Hub::getExceptionTranslatorRegistry().translateActiveException() ).setResultType( Catch::ResultWas::ThrewException ), false, false ); \ throw; \ }}while( Catch::isTrue( false ) ) diff --git a/include/internal/catch_common.h b/include/internal/catch_common.h index e28b58ec..3b69959f 100644 --- a/include/internal/catch_common.h +++ b/include/internal/catch_common.h @@ -94,7 +94,7 @@ namespace Catch } ATTRIBUTE_NORETURN - inline void throwLogicError( const std::string& message, const std::string& file, long line ) { + inline void throwLogicError( const std::string& message, const std::string& file, std::size_t line ) { std::ostringstream oss; oss << "Internal Catch error: '" << message << "' at: " << SourceLineInfo( file, line ); throw std::logic_error( oss.str() ); diff --git a/include/internal/catch_evaluate.hpp b/include/internal/catch_evaluate.hpp index 38e14f1a..a17b3341 100644 --- a/include/internal/catch_evaluate.hpp +++ b/include/internal/catch_evaluate.hpp @@ -58,7 +58,7 @@ namespace Internal { static bool evaluate( const T1& lhs, const T2& rhs) { - return const_cast( lhs ) == const_cast( rhs ); + return const_cast( lhs ) == const_cast( rhs ); } }; template diff --git a/include/internal/catch_generators.hpp b/include/internal/catch_generators.hpp index c0701714..2d0cdbe0 100644 --- a/include/internal/catch_generators.hpp +++ b/include/internal/catch_generators.hpp @@ -68,7 +68,7 @@ public: () const { - return 1+m_to-m_from; + return static_cast( 1+m_to-m_from ); } private: diff --git a/include/internal/catch_interfaces_reporter.h b/include/internal/catch_interfaces_reporter.h index fd0e87bf..03f2439a 100644 --- a/include/internal/catch_interfaces_reporter.h +++ b/include/internal/catch_interfaces_reporter.h @@ -1,15 +1,10 @@ /* - * catch_interfaces_reporter.h - * Test - * * Created by Phil on 31/12/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_IREPORTERREGISTRY_INCLUDED #define TWOBLUECUBES_CATCH_IREPORTERREGISTRY_INCLUDED @@ -23,115 +18,45 @@ namespace Catch { - /////////////////////////////////////////////////////////////////////////// - struct IReporterConfig - { - virtual ~IReporterConfig - () - {} - - virtual std::ostream& stream - () const = 0; - - virtual bool includeSuccessfulResults - () const = 0; - - virtual std::string getName - () const = 0; + struct IReporterConfig { + virtual ~IReporterConfig() {} + virtual std::ostream& stream () const = 0; + virtual bool includeSuccessfulResults () const = 0; + virtual std::string getName () const = 0; }; class TestCaseInfo; class ResultInfo; - /////////////////////////////////////////////////////////////////////////// - struct IReporter : IShared - { - virtual ~IReporter - (){} - - 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 EndGroup - ( const std::string& groupName, - const Totals& totals - ) = 0; - - virtual void StartSection - ( const std::string& sectionName, - const std::string description - ) = 0; - - virtual void EndSection - ( const std::string& sectionName, - const Counts& assertions - ) = 0; - - virtual void StartTestCase - ( const TestCaseInfo& testInfo - ) = 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; + struct IReporter : IShared { + virtual ~IReporter() {} + 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 EndGroup( const std::string& groupName, const Totals& totals ) = 0; + virtual void StartSection( const std::string& sectionName, const std::string description ) = 0; + virtual void EndSection( const std::string& sectionName, const Counts& assertions ) = 0; + virtual void StartTestCase( const TestCaseInfo& testInfo ) = 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; }; - /////////////////////////////////////////////////////////////////////////// - struct IReporterFactory - { - virtual ~IReporterFactory - (){} - - virtual IReporter* create - ( const IReporterConfig& config - ) const = 0; - - virtual std::string getDescription - () const = 0; + struct IReporterFactory { + virtual ~IReporterFactory() {} + virtual IReporter* create( const IReporterConfig& config ) const = 0; + virtual std::string getDescription() const = 0; }; - /////////////////////////////////////////////////////////////////////////// - struct IReporterRegistry - { + struct IReporterRegistry { typedef std::map FactoryMap; - virtual ~IReporterRegistry - (){} - - virtual IReporter* create - ( const std::string& name, - const IReporterConfig& config - ) const = 0; - - virtual void registerReporter - ( const std::string& name, - IReporterFactory* factory - ) = 0; - - virtual const FactoryMap& getFactories - () const = 0; - + virtual ~IReporterRegistry() {} + virtual IReporter* create( const std::string& name, const IReporterConfig& config ) const = 0; + virtual void registerReporter( const std::string& name, IReporterFactory* factory ) = 0; + virtual const FactoryMap& getFactories() const = 0; }; - /////////////////////////////////////////////////////////////////////////// inline std::string trim( const std::string& str ) { std::string::size_type start = str.find_first_not_of( "\n\r\t " ); @@ -139,8 +64,6 @@ namespace Catch return start != std::string::npos ? str.substr( start, 1+end-start ) : ""; } - - } #endif // TWOBLUECUBES_CATCH_IREPORTERREGISTRY_INCLUDED diff --git a/include/internal/catch_stream.hpp b/include/internal/catch_stream.hpp index 7717a798..e26b2f33 100644 --- a/include/internal/catch_stream.hpp +++ b/include/internal/catch_stream.hpp @@ -64,7 +64,7 @@ namespace Catch { if( pbase() != pptr() ) { - m_writer( std::string( pbase(), pptr() - pbase() ) ); + m_writer( std::string( pbase(), static_cast( pptr() - pbase() ) ) ); setp( pbase(), epptr() ); } return 0; diff --git a/projects/SelfTest/ConditionTests.cpp b/projects/SelfTest/ConditionTests.cpp index e9a8f685..41ce392d 100644 --- a/projects/SelfTest/ConditionTests.cpp +++ b/projects/SelfTest/ConditionTests.cpp @@ -247,7 +247,7 @@ TEST_CASE( "./succeeding/conditions/ptr", REQUIRE( returnsNull() == NULL ); REQUIRE( returnsConstNull() == NULL ); -// REQUIRE( NULL != p ); // gives warning, but should compile and run ok + REQUIRE( NULL != p ); } // Not (!) tests diff --git a/projects/SelfTest/GeneratorTests.cpp b/projects/SelfTest/GeneratorTests.cpp index 522e3f2c..2f8fec84 100644 --- a/projects/SelfTest/GeneratorTests.cpp +++ b/projects/SelfTest/GeneratorTests.cpp @@ -12,7 +12,7 @@ #include "catch.hpp" -inline size_t multiply( size_t a, size_t b ) +inline int multiply( int a, int b ) { return a*b; } @@ -21,8 +21,8 @@ TEST_CASE( "./succeeding/generators/1", "Generators over two ranges" ) { using namespace Catch::Generators; - size_t i = GENERATE( between( 1, 5 ).then( values( 15, 20, 21 ).then( 36 ) ) ); - size_t j = GENERATE( between( 100, 107 ) ); + int i = GENERATE( between( 1, 5 ).then( values( 15, 20, 21 ).then( 36 ) ) ); + int j = GENERATE( between( 100, 107 ) ); REQUIRE( multiply( i, 2 ) == i*2 ); REQUIRE( multiply( j, 2 ) == j*2 ); diff --git a/projects/SelfTest/TestMain.cpp b/projects/SelfTest/TestMain.cpp index 48932dca..97bdb6a2 100644 --- a/projects/SelfTest/TestMain.cpp +++ b/projects/SelfTest/TestMain.cpp @@ -43,7 +43,7 @@ TEST_CASE( "selftest/main", "Runs all Catch self tests and checks their results" "Number of 'succeeding' tests is fixed" ) { runner.runMatching( "./succeeding/*" ); - CHECK( runner.getTotals().assertions.passed == 275 ); + CHECK( runner.getTotals().assertions.passed == 276 ); CHECK( runner.getTotals().assertions.failed == 0 ); } diff --git a/projects/SelfTest/TrickyTests.cpp b/projects/SelfTest/TrickyTests.cpp index b5b72a42..bcfe9b03 100644 --- a/projects/SelfTest/TrickyTests.cpp +++ b/projects/SelfTest/TrickyTests.cpp @@ -209,7 +209,7 @@ namespace ObjectWithNonConstEqualityOperator TEST_CASE("./succeeding/non-const==", "Demonstrate that a non-const == is not used") { Test t( 1 ); - REQUIRE( t == 1 ); + REQUIRE( t == 1u ); } } diff --git a/projects/XCode4/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj b/projects/XCode4/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj index d879996a..79f9ccd0 100644 --- a/projects/XCode4/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj +++ b/projects/XCode4/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj @@ -292,6 +292,7 @@ buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; ARCHS = "$(ARCHS_STANDARD_64_BIT)"; + CLANG_WARN_IMPLICIT_SIGN_CONVERSION = YES; COPY_PHASE_STRIP = NO; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; @@ -318,6 +319,7 @@ buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; ARCHS = "$(ARCHS_STANDARD_64_BIT)"; + CLANG_WARN_IMPLICIT_SIGN_CONVERSION = YES; COPY_PHASE_STRIP = YES; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; GCC_C_LANGUAGE_STANDARD = gnu99;