From 331188f6b3db571de0ca394d5a6d6a56350f0917 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Wed, 23 Feb 2011 09:06:05 +0000 Subject: [PATCH] Added generator copy ctor to fix bug when NRVO is not used. Some exception handling improvements, too --- .../TestCatch/TestCatch/TestCatch.vcproj | 9 +++++++ internal/catch_common.h | 25 ++++++++++++++----- internal/catch_generators.hpp | 11 +++++++- internal/catch_runner_impl.hpp | 10 ++++++++ 4 files changed, 48 insertions(+), 7 deletions(-) diff --git a/Test/VisualStudio/TestCatch/TestCatch/TestCatch.vcproj b/Test/VisualStudio/TestCatch/TestCatch/TestCatch.vcproj index 854685d7..139de602 100644 --- a/Test/VisualStudio/TestCatch/TestCatch/TestCatch.vcproj +++ b/Test/VisualStudio/TestCatch/TestCatch/TestCatch.vcproj @@ -41,6 +41,7 @@ + + + + diff --git a/internal/catch_common.h b/internal/catch_common.h index 27bbae16..3282044d 100644 --- a/internal/catch_common.h +++ b/internal/catch_common.h @@ -17,6 +17,15 @@ #define INTERNAL_CATCH_UNIQUE_NAME_LINE( name, line ) INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) #define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __LINE__ ) +#ifdef __GNUC__ +#define ATTRIBUTE_NORETURN __attribute__ ((noreturn)) +#else +#define ATTRIBUTE_NORETURN +#endif + +#include +#include + namespace Catch { class NonCopyable @@ -53,13 +62,17 @@ namespace Catch delete it->second; } } - + + ATTRIBUTE_NORETURN + inline void throwLogicError( const std::string& message, const std::string& file, long line ) + { + std::ostringstream oss; + oss << "Internal Catch error: '" << message << "' at: " << file << "(" << line << ")"; + throw std::logic_error( oss.str() ); + } } -#ifdef __GNUC__ -#define ATTRIBUTE_NORETURN __attribute__ ((noreturn)) -#else -#define ATTRIBUTE_NORETURN -#endif + +#define CATCH_INTERNAL_ERROR( msg ) throwLogicError( msg, __FILE__, __LINE__ ); #endif // TWOBLUECUBES_CATCH_COMMON_H_INCLUDED diff --git a/internal/catch_generators.hpp b/internal/catch_generators.hpp index ccb6b6d4..6623cb2d 100644 --- a/internal/catch_generators.hpp +++ b/internal/catch_generators.hpp @@ -129,6 +129,15 @@ public: { } + /////////////////////////////////////////////////////////////////////////// + // *** Move semantics, similar to auto_ptr *** + CompositeGenerator( CompositeGenerator& other ) + : m_fileInfo( other.m_fileInfo ), + m_totalSize( 0 ) + { + move( other ); + } + /////////////////////////////////////////////////////////////////////////// CompositeGenerator& setFileInfo ( @@ -164,7 +173,7 @@ public: } index += generator->size(); } - throw "this should never happen!"; + CATCH_INTERNAL_ERROR( "Indexed past end of generated range" ); } /////////////////////////////////////////////////////////////////////////// diff --git a/internal/catch_runner_impl.hpp b/internal/catch_runner_impl.hpp index 3ef5a25e..acf9a41a 100644 --- a/internal/catch_runner_impl.hpp +++ b/internal/catch_runner_impl.hpp @@ -596,6 +596,16 @@ namespace Catch acceptMessage( ex.what() ); acceptResult( ResultWas::ThrewException ); } + catch( std::string& msg ) + { + acceptMessage( msg ); + acceptResult( ResultWas::ThrewException ); + } + catch( const char* msg ) + { + acceptMessage( msg ); + acceptResult( ResultWas::ThrewException ); + } catch(...) { acceptMessage( "unknown exception" );