diff --git a/Test/ExceptionTests.cpp b/Test/ExceptionTests.cpp index db5786cb..5fba0da8 100644 --- a/Test/ExceptionTests.cpp +++ b/Test/ExceptionTests.cpp @@ -17,9 +17,13 @@ namespace { + ATTRIBUTE_NORETURN + int thisThrows(); + int thisThrows() { throw std::domain_error( "expected exception" ); + /*NOTREACHED*/ } int thisDoesntThrow() @@ -42,9 +46,10 @@ TEST_CASE( "./failing/exceptions/explicit", "When checked exceptions are thrown CHECK_NOTHROW( thisThrows() ); } -TEST_CASE( "./failing/exceptions/implicit", "When unchecked exceptions are thrown they are always failures" ) +INTERNAL_CATCH_TESTCASE_NORETURN( "./failing/exceptions/implicit", "When unchecked exceptions are thrown they are always failures" ) { throw std::domain_error( "unexpected exception" ); + /*NOTREACHED*/ } TEST_CASE( "./succeeding/exceptions/implicit", "When unchecked exceptions are thrown, but caught, they do not affect the test" ) diff --git a/catch.hpp b/catch.hpp index 11897d95..440ec253 100644 --- a/catch.hpp +++ b/catch.hpp @@ -53,6 +53,7 @@ #define SECTION( name, description ) INTERNAL_CATCH_SECTION( name, description ) #define TEST_CASE( name, description ) INTERNAL_CATCH_TESTCASE( name, description ) +#define TEST_CASE_NORETURN( name, description ) INTERNAL_CATCH_TESTCASE_NORETURN( name, description ) #define ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE( "", "Anonymous test case" ) #define METHOD_AS_TEST_CASE( method, name, description ) CATCH_METHOD_AS_TEST_CASE( method, name, description ) diff --git a/internal/catch_common.h b/internal/catch_common.h index ac60aaa4..47c32bb0 100644 --- a/internal/catch_common.h +++ b/internal/catch_common.h @@ -55,5 +55,10 @@ namespace Catch } } +#ifdef __GNUC__ +#define ATTRIBUTE_NORETURN __attribute__ ((noreturn)) +#else +#define ATTRIBUTE_NORETURN +#endif #endif // TWOBLUECUBES_CATCH_COMMON_H_INCLUDED \ No newline at end of file diff --git a/internal/catch_section.hpp b/internal/catch_section.hpp index 4cc63931..6a0b8032 100644 --- a/internal/catch_section.hpp +++ b/internal/catch_section.hpp @@ -58,6 +58,6 @@ namespace Catch } // end namespace Catch -#define INTERNAL_CATCH_SECTION( name, desc ) if( Catch::Section catch_internal_Section = Catch::Section( name, desc ) ) +#define INTERNAL_CATCH_SECTION( name, desc ) if( Catch::Section INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::Section( name, desc ) ) #endif // TWOBLUECUBES_CATCH_SECTION_HPP_INCLUDED diff --git a/internal/catch_test_registry.hpp b/internal/catch_test_registry.hpp index 47085da1..9fdc21d1 100644 --- a/internal/catch_test_registry.hpp +++ b/internal/catch_test_registry.hpp @@ -83,6 +83,11 @@ struct FixtureWrapper{}; namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &INTERNAL_CATCH_UNIQUE_NAME( catch_internal_TestFunction ), Name, Desc ); }\ static void INTERNAL_CATCH_UNIQUE_NAME( catch_internal_TestFunction )() +#define INTERNAL_CATCH_TESTCASE_NORETURN( Name, Desc ) \ + static void INTERNAL_CATCH_UNIQUE_NAME( catch_internal_TestFunction )() ATTRIBUTE_NORETURN; \ + namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &INTERNAL_CATCH_UNIQUE_NAME( catch_internal_TestFunction ), Name, Desc ); }\ + static void INTERNAL_CATCH_UNIQUE_NAME( catch_internal_TestFunction )() + #define CATCH_METHOD_AS_TEST_CASE( QualifiedMethod, Name, Desc ) \ namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &QualifiedMethod, Name, Desc ); }