mirror of
				https://github.com/catchorg/Catch2.git
				synced 2025-10-31 20:27:11 +01:00 
			
		
		
		
	Removed use of compiler specific techniques for denoting non-returning functions
- use if( Catch::isTrue( true) ) to guard throws instead
This commit is contained in:
		| @@ -15,13 +15,11 @@ | ||||
|  | ||||
| namespace | ||||
| { | ||||
|     CATCH_ATTRIBUTE_NORETURN | ||||
|     int thisThrows(); | ||||
|      | ||||
|     int thisThrows() | ||||
|     inline int thisThrows() | ||||
|     { | ||||
|         throw std::domain_error( "expected exception" ); | ||||
|         /*NOTREACHED*/     | ||||
| 		if( Catch::isTrue( true ) ) | ||||
| 		    throw std::domain_error( "expected exception" ); | ||||
| 		return 1; | ||||
|     } | ||||
|  | ||||
|     int thisDoesntThrow() | ||||
| @@ -37,7 +35,6 @@ TEST_CASE( "./succeeding/exceptions/explicit", "When checked exceptions are thro | ||||
|     REQUIRE_THROWS( thisThrows() ); | ||||
| } | ||||
|  | ||||
| CATCH_ATTRIBUTE_NORETURN | ||||
| TEST_CASE( "./failing/exceptions/explicit", "When checked exceptions are thrown they can be expected or unexpected" ) | ||||
| { | ||||
|     CHECK_THROWS_AS( thisThrows(), std::string ); | ||||
| @@ -45,31 +42,30 @@ TEST_CASE( "./failing/exceptions/explicit", "When checked exceptions are thrown | ||||
|     CHECK_NOTHROW( thisThrows() ); | ||||
| } | ||||
|  | ||||
| TEST_CASE_NORETURN( "./failing/exceptions/implicit", "When unchecked exceptions are thrown they are always failures" ) | ||||
| TEST_CASE( "./failing/exceptions/implicit", "When unchecked exceptions are thrown they are always failures" ) | ||||
| { | ||||
|     throw std::domain_error( "unexpected exception" ); | ||||
|     /*NOTREACHED*/     | ||||
| 	if( Catch::isTrue( true ) ) | ||||
| 	    throw std::domain_error( "unexpected exception" ); | ||||
| } | ||||
|  | ||||
| TEST_CASE_NORETURN( "./failing/exceptions/implicit/2", "An unchecked exception reports the line of the last assertion" ) | ||||
| TEST_CASE( "./failing/exceptions/implicit/2", "An unchecked exception reports the line of the last assertion" ) | ||||
| { | ||||
|     CHECK( 1 == 1 ); | ||||
|     throw std::domain_error( "unexpected exception" ); | ||||
|     /*NOTREACHED*/ | ||||
| 	if( Catch::isTrue( true ) ) | ||||
| 	    throw std::domain_error( "unexpected exception" ); | ||||
| } | ||||
| TEST_CASE( "./failing/exceptions/implicit/3", "When unchecked exceptions are thrown they are always failures" ) | ||||
| { | ||||
|     SECTION( "section name", "" ) | ||||
|     { | ||||
|         throw std::domain_error( "unexpected exception" ); | ||||
|         /*NOTREACHED*/ | ||||
| 		if( Catch::isTrue( true ) ) | ||||
| 			throw std::domain_error( "unexpected exception" ); | ||||
|     } | ||||
| } | ||||
|  | ||||
| TEST_CASE_NORETURN( "./failing/exceptions/implicit/4", "When unchecked exceptions are thrown they are always failures" ) | ||||
| TEST_CASE( "./failing/exceptions/implicit/4", "When unchecked exceptions are thrown they are always failures" ) | ||||
| { | ||||
|     CHECK( thisThrows() == 0 ); | ||||
|     /*NOTREACHED*/     | ||||
| } | ||||
|  | ||||
| TEST_CASE( "./succeeding/exceptions/implicit", "When unchecked exceptions are thrown, but caught, they do not affect the test" ) | ||||
| @@ -109,28 +105,32 @@ CATCH_TRANSLATE_EXCEPTION( double& ex ) | ||||
|     return Catch::toString( ex ); | ||||
| } | ||||
|  | ||||
| TEST_CASE_NORETURN( "./failing/exceptions/custom", "Unexpected custom exceptions can be translated" ) | ||||
| TEST_CASE( "./failing/exceptions/custom", "Unexpected custom exceptions can be translated" ) | ||||
| { | ||||
|     throw CustomException( "custom exception" ); | ||||
| 	if( Catch::isTrue( true ) ) | ||||
| 	    throw CustomException( "custom exception" ); | ||||
| } | ||||
|  | ||||
| inline void throwCustom() { | ||||
| 	if( Catch::isTrue( true ) ) | ||||
| 		throw CustomException( "custom exception - not std" ); | ||||
| } | ||||
| #ifdef _MSC_VER | ||||
| #pragma warning(disable:4702) // unreachable code | ||||
| #endif | ||||
|  | ||||
| TEST_CASE( "./failing/exceptions/custom/nothrow", "Custom exceptions can be translated when testing for nothrow" ) | ||||
| { | ||||
|     REQUIRE_NOTHROW( throw CustomException( "unexpected custom exception" ) ); | ||||
|     REQUIRE_NOTHROW( throwCustom() ); | ||||
| } | ||||
|  | ||||
| TEST_CASE( "./failing/exceptions/custom/throw", "Custom exceptions can be translated when testing for throwing as something else" ) | ||||
| { | ||||
|     REQUIRE_THROWS_AS( throw CustomException( "custom exception - not std" ), std::exception ); | ||||
|     REQUIRE_THROWS_AS( throwCustom(), std::exception ); | ||||
| } | ||||
|  | ||||
|  | ||||
| TEST_CASE_NORETURN( "./failing/exceptions/custom/double", "Unexpected custom exceptions can be translated"  ) | ||||
| TEST_CASE( "./failing/exceptions/custom/double", "Unexpected custom exceptions can be translated"  ) | ||||
| { | ||||
|     throw double( 3.14 ); | ||||
| 	if( Catch::isTrue( true ) ) | ||||
| 	    throw double( 3.14 ); | ||||
| } | ||||
|  | ||||
| inline int thisFunctionNotImplemented( int ) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Phil Nash
					Phil Nash