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

summaryrefslogtreecommitdiffhomepage
path: root/projects/SelfTest/ExceptionTests.cpp
diff options
context:
space:
mode:
authorPhil Nash2015-12-04 10:19:08 +0000
committerPhil Nash2015-12-04 10:19:08 +0000
commitfdc42d0af47f58fa13a42b685bbeaf55a8347673 (patch)
tree779ff3d692eeffd33353d89ad7697a592ab5201e /projects/SelfTest/ExceptionTests.cpp
parentd758428fe297655e558a86cc6a013fcb1bcc8c7d (diff)
parentd274fc571c3980b5ac04cbe1416cf2205e6c99f7 (diff)
downloadcatch3-1.3.0.tar.gz
Merged from develop branchv1.3.0
- now v1.3.0
Diffstat (limited to 'projects/SelfTest/ExceptionTests.cpp')
-rw-r--r--projects/SelfTest/ExceptionTests.cpp51
1 files changed, 50 insertions, 1 deletions
diff --git a/projects/SelfTest/ExceptionTests.cpp b/projects/SelfTest/ExceptionTests.cpp
index 7de1d179..dfcaa4b8 100644
--- a/projects/SelfTest/ExceptionTests.cpp
+++ b/projects/SelfTest/ExceptionTests.cpp
@@ -96,6 +96,23 @@ public:
CustomException( const std::string& msg )
: m_msg( msg )
{}
+
+ std::string getMessage() const
+ {
+ return m_msg;
+ }
+
+private:
+ std::string m_msg;
+};
+
+class CustomStdException : public std::exception
+{
+public:
+ CustomStdException( const std::string& msg )
+ : m_msg( msg )
+ {}
+ ~CustomStdException() CATCH_NOEXCEPT {}
std::string getMessage() const
{
@@ -106,22 +123,34 @@ 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" );
@@ -152,3 +181,23 @@ TEST_CASE( "NotImplemented exception", "" )
{
REQUIRE_THROWS( thisFunctionNotImplemented( 7 ) );
}
+
+TEST_CASE( "Exception messages can be tested for", "" ) {
+ using namespace Catch::Matchers;
+ SECTION( "exact match" )
+ REQUIRE_THROWS_WITH( thisThrows(), "expected exception" );
+ SECTION( "different case" )
+ REQUIRE_THROWS_WITH( thisThrows(), Equals( "expecteD Exception", Catch::CaseSensitive::No ) );
+ SECTION( "wildcarded" ) {
+ REQUIRE_THROWS_WITH( thisThrows(), StartsWith( "expected" ) );
+ REQUIRE_THROWS_WITH( thisThrows(), EndsWith( "exception" ) );
+ REQUIRE_THROWS_WITH( thisThrows(), Contains( "except" ) );
+ REQUIRE_THROWS_WITH( thisThrows(), Contains( "exCept", Catch::CaseSensitive::No ) );
+ }
+}
+
+TEST_CASE( "Mismatching exception messages failing the test", "[.][failing]" ) {
+ REQUIRE_THROWS_WITH( thisThrows(), "expected exception" );
+ REQUIRE_THROWS_WITH( thisThrows(), "should fail" );
+ REQUIRE_THROWS_WITH( thisThrows(), "expected exception" );
+}