Some more reformatting.

Also fixed some warnings
This commit is contained in:
Phil Nash 2012-05-09 08:17:51 +01:00
parent e83f839741
commit d06dcedfdc
11 changed files with 56 additions and 152 deletions

View File

@ -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<typename T>
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 ) )

View File

@ -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() );

View File

@ -58,7 +58,7 @@ namespace Internal
{
static bool evaluate( const T1& lhs, const T2& rhs)
{
return const_cast<T1&>( lhs ) == const_cast<T2&>( rhs );
return const_cast<T1&>( lhs ) == const_cast<T2&>( rhs );
}
};
template<typename T1, typename T2>

View File

@ -68,7 +68,7 @@ public:
()
const
{
return 1+m_to-m_from;
return static_cast<std::size_t>( 1+m_to-m_from );
}
private:

View File

@ -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<std::string, IReporterFactory*> 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

View File

@ -64,7 +64,7 @@ namespace Catch
{
if( pbase() != pptr() )
{
m_writer( std::string( pbase(), pptr() - pbase() ) );
m_writer( std::string( pbase(), static_cast<std::string::size_type>( pptr() - pbase() ) ) );
setp( pbase(), epptr() );
}
return 0;

View File

@ -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

View File

@ -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 );

View File

@ -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 );
}

View File

@ -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 );
}
}

View File

@ -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;