mirror of
				https://github.com/catchorg/Catch2.git
				synced 2025-10-31 12:17:11 +01:00 
			
		
		
		
	exception translators considered even for types deriving from std::exception, now
- also added docs for exception translators - updated approvals
This commit is contained in:
		| @@ -356,7 +356,7 @@ due to unexpected exception with message: | ||||
|   expected exception | ||||
|  | ||||
| ------------------------------------------------------------------------------- | ||||
| Unexpected custom exceptions can be translated | ||||
| Non-std exceptions can be translated | ||||
| ------------------------------------------------------------------------------- | ||||
| ExceptionTests.cpp:<line number> | ||||
| ............................................................................... | ||||
| @@ -365,6 +365,16 @@ ExceptionTests.cpp:<line number>: FAILED: | ||||
| due to unexpected exception with message: | ||||
|   custom exception | ||||
|  | ||||
| ------------------------------------------------------------------------------- | ||||
| Custom std-exceptions can be custom translated | ||||
| ------------------------------------------------------------------------------- | ||||
| ExceptionTests.cpp:<line number> | ||||
| ............................................................................... | ||||
|  | ||||
| ExceptionTests.cpp:<line number>: FAILED: | ||||
| due to unexpected exception with message: | ||||
|   custom std exception | ||||
|  | ||||
| ------------------------------------------------------------------------------- | ||||
| Custom exceptions can be translated when testing for nothrow | ||||
| ------------------------------------------------------------------------------- | ||||
| @@ -820,6 +830,6 @@ with expansion: | ||||
|   "first" == "second" | ||||
|  | ||||
| =============================================================================== | ||||
| test cases: 165 | 123 passed | 41 failed |  1 failed as expected | ||||
| assertions: 912 | 817 passed | 82 failed | 13 failed as expected | ||||
| test cases: 166 | 123 passed | 42 failed |  1 failed as expected | ||||
| assertions: 913 | 817 passed | 83 failed | 13 failed as expected | ||||
|  | ||||
|   | ||||
| @@ -1217,7 +1217,7 @@ due to unexpected exception with message: | ||||
|   expected exception | ||||
|  | ||||
| ------------------------------------------------------------------------------- | ||||
| Unexpected custom exceptions can be translated | ||||
| Non-std exceptions can be translated | ||||
| ------------------------------------------------------------------------------- | ||||
| ExceptionTests.cpp:<line number> | ||||
| ............................................................................... | ||||
| @@ -1226,6 +1226,16 @@ ExceptionTests.cpp:<line number>: FAILED: | ||||
| due to unexpected exception with message: | ||||
|   custom exception | ||||
|  | ||||
| ------------------------------------------------------------------------------- | ||||
| Custom std-exceptions can be custom translated | ||||
| ------------------------------------------------------------------------------- | ||||
| ExceptionTests.cpp:<line number> | ||||
| ............................................................................... | ||||
|  | ||||
| ExceptionTests.cpp:<line number>: FAILED: | ||||
| due to unexpected exception with message: | ||||
|   custom std exception | ||||
|  | ||||
| ------------------------------------------------------------------------------- | ||||
| Custom exceptions can be translated when testing for nothrow | ||||
| ------------------------------------------------------------------------------- | ||||
| @@ -9024,6 +9034,6 @@ with expansion: | ||||
|   1 > 0 | ||||
|  | ||||
| =============================================================================== | ||||
| test cases: 165 | 122 passed | 42 failed |  1 failed as expected | ||||
| assertions: 914 | 817 passed | 84 failed | 13 failed as expected | ||||
| test cases: 166 | 122 passed | 43 failed |  1 failed as expected | ||||
| assertions: 915 | 817 passed | 85 failed | 13 failed as expected | ||||
|  | ||||
|   | ||||
| @@ -1,5 +1,5 @@ | ||||
| <testsuites> | ||||
|   <testsuite name="CatchSelfTest" errors="12" failures="72" tests="914" hostname="tbd" time="{duration}" timestamp="tbd"> | ||||
|   <testsuite name="CatchSelfTest" errors="13" failures="72" tests="915" hostname="tbd" time="{duration}" timestamp="tbd"> | ||||
|     <testcase classname="global" name="toString(enum)" time="{duration}"/> | ||||
|     <testcase classname="global" name="toString(enum w/operator<<)" time="{duration}"/> | ||||
|     <testcase classname="global" name="toString(enum class)" time="{duration}"/> | ||||
| @@ -226,9 +226,15 @@ expected exception | ||||
| ExceptionTests.cpp:<line number> | ||||
|       </error> | ||||
|     </testcase> | ||||
|     <testcase classname="global" name="Unexpected custom exceptions can be translated" time="{duration}"> | ||||
|     <testcase classname="global" name="Non-std exceptions can be translated" time="{duration}"> | ||||
|       <error type="TEST_CASE"> | ||||
| custom exception | ||||
| ExceptionTests.cpp:<line number> | ||||
|       </error> | ||||
|     </testcase> | ||||
|     <testcase classname="global" name="Custom std-exceptions can be custom translated" time="{duration}"> | ||||
|       <error type="TEST_CASE"> | ||||
| custom std exception | ||||
| ExceptionTests.cpp:<line number> | ||||
|       </error> | ||||
|     </testcase> | ||||
|   | ||||
| @@ -1545,12 +1545,18 @@ | ||||
|     <TestCase name="When unchecked exceptions are thrown, but caught, they do not affect the test"> | ||||
|       <OverallResult success="true"/> | ||||
|     </TestCase> | ||||
|     <TestCase name="Unexpected custom exceptions can be translated"> | ||||
|     <TestCase name="Non-std exceptions can be translated"> | ||||
|       <Exception filename="projects/SelfTest/ExceptionTests.cpp" > | ||||
|         custom exception | ||||
|       </Exception> | ||||
|       <OverallResult success="false"/> | ||||
|     </TestCase> | ||||
|     <TestCase name="Custom std-exceptions can be custom translated"> | ||||
|       <Exception filename="projects/SelfTest/ExceptionTests.cpp" > | ||||
|         custom std exception | ||||
|       </Exception> | ||||
|       <OverallResult success="false"/> | ||||
|     </TestCase> | ||||
|     <TestCase name="Custom exceptions can be translated when testing for nothrow"> | ||||
|       <Expression success="false" type="REQUIRE_NOTHROW" filename="projects/SelfTest/ExceptionTests.cpp" > | ||||
|         <Original> | ||||
| @@ -9496,7 +9502,7 @@ there" | ||||
|       </Section> | ||||
|       <OverallResult success="true"/> | ||||
|     </TestCase> | ||||
|     <OverallResults successes="817" failures="84" expectedFailures="13"/> | ||||
|     <OverallResults successes="817" failures="85" expectedFailures="13"/> | ||||
|   </Group> | ||||
|   <OverallResults successes="817" failures="84" expectedFailures="13"/> | ||||
|   <OverallResults successes="817" failures="85" expectedFailures="13"/> | ||||
| </Catch> | ||||
|   | ||||
| @@ -106,22 +106,50 @@ private: | ||||
|     std::string m_msg; | ||||
| }; | ||||
|  | ||||
| class CustomStdException : public std::exception | ||||
| { | ||||
| public: | ||||
|     CustomStdException( const std::string& msg ) | ||||
|     : m_msg( msg ) | ||||
|     {} | ||||
|      | ||||
|     std::string getMessage() const | ||||
|     { | ||||
|         return m_msg; | ||||
|     } | ||||
|      | ||||
| private: | ||||
|     std::string m_msg; | ||||
| }; | ||||
|  | ||||
|  | ||||
| CATCH_TRANSLATE_EXCEPTION( CustomException& ex ) | ||||
| { | ||||
|     return ex.getMessage(); | ||||
| } | ||||
|  | ||||
| CATCH_TRANSLATE_EXCEPTION( CustomStdException& ex ) | ||||
| { | ||||
|     return ex.getMessage(); | ||||
| } | ||||
|  | ||||
| CATCH_TRANSLATE_EXCEPTION( double& ex ) | ||||
| { | ||||
|     return Catch::toString( ex ); | ||||
| } | ||||
|  | ||||
| TEST_CASE("Unexpected custom exceptions can be translated", "[.][failing]" ) | ||||
| TEST_CASE("Non-std exceptions can be translated", "[.][failing]" ) | ||||
| { | ||||
| 	if( Catch::alwaysTrue() ) | ||||
| 	    throw CustomException( "custom exception" ); | ||||
| } | ||||
|  | ||||
| TEST_CASE("Custom std-exceptions can be custom translated", "[.][failing]" ) | ||||
| { | ||||
|     if( Catch::alwaysTrue() ) | ||||
|         throw CustomException( "custom std exception" ); | ||||
| } | ||||
|  | ||||
| inline void throwCustom() { | ||||
| 	if( Catch::alwaysTrue() ) | ||||
| 		throw CustomException( "custom exception - not std" ); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Phil Nash
					Phil Nash