catch3
Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.
Clonegit clone https://git.progmasoft.com/catch3
Added generator copy ctor to fix bug when NRVO is not used. Some exception handling improvements, too
- Commit
331188f6b3db571de0ca394d5a6d6a56350f0917- Author
- Phil Nash ·
- Parents
6bfc1b6016e1
Changes
.../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 @@ <Tool Name="VCCLCompilerTool" Optimization="0" + AdditionalIncludeDirectories="\\psf\Host\TwoBlueCubes\Dev\GitHub\Catch" PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE" MinimalRebuild="true" BasicRuntimeChecks="3" @@ -202,10 +203,18 @@ RelativePath="..\..\..\ExceptionTests.cpp" > </File> + <File + RelativePath="..\..\..\GeneratorTests.cpp" + > + </File> <File RelativePath="..\..\..\MessageTests.cpp" > </File> + <File + RelativePath="..\..\..\MiscTests.cpp" + > + </File> <File RelativePath="..\..\..\TrickyTests.cpp" > 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 <sstream> +#include <stdexcept> + 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" );