Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/Test/ExceptionTests.cpp
diff options
context:
space:
mode:
authorPhil Nash2011-04-20 19:09:41 +0100
committerPhil Nash2011-04-20 19:09:41 +0100
commit5d7b054f14841b892fb04e27c431addd073959ce (patch)
treef43912fb9e0b4df3631dda06874e3631b4e21f5b /Test/ExceptionTests.cpp
parent9430a2c4c803fcb078204f87533c92dc947f4560 (diff)
downloadcatch3-5d7b054f14841b892fb04e27c431addd073959ce.tar.gz
Improved custom exception handling
Diffstat (limited to 'Test/ExceptionTests.cpp')
-rw-r--r--Test/ExceptionTests.cpp32
1 files changed, 23 insertions, 9 deletions
diff --git a/Test/ExceptionTests.cpp b/Test/ExceptionTests.cpp
index caad6fd8..1d45200e 100644
--- a/Test/ExceptionTests.cpp
+++ b/Test/ExceptionTests.cpp
@@ -79,19 +79,33 @@ private:
std::string m_msg;
};
-
-namespace Catch
+CATCH_TRANSLATE_EXCEPTION( CustomException& ex )
{
- ExceptionTranslator<CustomException> translator;
+ return ex.getMessage();
+}
- template<>
- std::string ExceptionTranslator<CustomException>::translate( CustomException& ex ) const
- {
- return ex.getMessage();
- }
+CATCH_TRANSLATE_EXCEPTION( double& ex )
+{
+ return Catch::toString( ex );
}
-TEST_CASE_NORETURN( "./succeeding/exceptions/custom", "" )
+TEST_CASE_NORETURN( "./failing/exceptions/custom", "Unexpected custom exceptions can be translated" )
{
throw CustomException( "custom exception" );
}
+
+TEST_CASE( "./failing/exceptions/custom/nothrow", "Custom exceptions can be translated when testing for nothrow" )
+{
+ REQUIRE_NOTHROW( throw CustomException( "unexpected custom exception" ) );
+}
+
+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 );
+}
+
+
+TEST_CASE_NORETURN( "./failing/exceptions/custom/double", "Unexpected custom exceptions can be translated" )
+{
+ throw double( 3.14 );
+}