Progmasoft Git

catch3

Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.

Clonegit clone https://git.progmasoft.com/catch3

Add MessageMatches matcher for exception (#2570)

Commit
9c0533a90504b2b1c308dc7cc77ff194f81046e2
Author
lbckmnn ·
Committer
GitHub
Parents
ed02710b83c2

Files · Download .tar.gz

Changes

 docs/matchers.md                                   | 12 +++++--
 src/catch2/matchers/catch_matchers_exception.hpp   | 26 +++++++++++++++
 tests/SelfTest/Baselines/automake.sw.approved.txt  |  1 +
 .../Baselines/automake.sw.multi.approved.txt       |  1 +
 tests/SelfTest/Baselines/compact.sw.approved.txt   |  8 +++--
 .../Baselines/compact.sw.multi.approved.txt        |  8 +++--
 tests/SelfTest/Baselines/console.std.approved.txt  |  4 +--
 tests/SelfTest/Baselines/console.sw.approved.txt   | 30 +++++++++++++++--
 .../Baselines/console.sw.multi.approved.txt        | 30 +++++++++++++++--
 tests/SelfTest/Baselines/junit.sw.approved.txt     |  3 +-
 .../SelfTest/Baselines/junit.sw.multi.approved.txt |  3 +-
 tests/SelfTest/Baselines/sonarqube.sw.approved.txt |  1 +
 .../Baselines/sonarqube.sw.multi.approved.txt      |  1 +
 tests/SelfTest/Baselines/tap.sw.approved.txt       | 10 +++++-
 tests/SelfTest/Baselines/tap.sw.multi.approved.txt | 10 +++++-
 tests/SelfTest/Baselines/teamcity.sw.approved.txt  |  2 ++
 .../Baselines/teamcity.sw.multi.approved.txt       |  2 ++
 tests/SelfTest/Baselines/xml.sw.approved.txt       | 39 ++++++++++++++++++++--
 tests/SelfTest/Baselines/xml.sw.multi.approved.txt | 39 ++++++++++++++++++++--
 tests/SelfTest/UsageTests/Matchers.tests.cpp       | 15 +++++++++
 20 files changed, 225 insertions(+), 20 deletions(-)

diff --git a/docs/matchers.md b/docs/matchers.md
index d3afe0f4..8940b6ad 100644
--- a/docs/matchers.md
+++ b/docs/matchers.md
@@ -190,13 +190,21 @@ properties. The macro is `REQUIRE_THROWS_MATCHES(expr, ExceptionType, Matcher)`.
 > `REQUIRE_THROWS_MATCHES` macro lives in `catch2/matchers/catch_matchers.hpp`
 
 
-Catch2 currently provides only one matcher for exceptions,
-`Message(std::string message)`. `Message` checks that the exception's
+Catch2 currently provides two matchers for exceptions.
+These are:
+* `Message(std::string message)`.
+* `MessageMatches(Matcher matcher)`.
+
+`Message` checks that the exception's
 message, as returned from `what` is exactly equal to `message`.
 
+`MessageMatches` applies the provided matcher on the exception's
+message, as returned from `what`. This is useful in conjunctions with the `std::string` matchers (e.g. `StartsWith`)
+
 Example use:
 ```cpp
 REQUIRE_THROWS_MATCHES(throwsDerivedException(),  DerivedException,  Message("DerivedException::what"));
+REQUIRE_THROWS_MATCHES(throwsDerivedException(),  DerivedException,  MessageMatches(StartsWith("DerivedException")));
 ```
 
 Note that `DerivedException` in the example above has to derive from
diff --git a/src/catch2/matchers/catch_matchers_exception.hpp b/src/catch2/matchers/catch_matchers_exception.hpp
index 27e1b932..e7c3a636 100644
--- a/src/catch2/matchers/catch_matchers_exception.hpp
+++ b/src/catch2/matchers/catch_matchers_exception.hpp
@@ -29,6 +29,32 @@ public:
 //! Creates a matcher that checks whether a std derived exception has the provided message
 ExceptionMessageMatcher Message(std::string const& message);
 
+template <typename StringMatcherType>
+class ExceptionMessageMatchesMatcher final
+    : public MatcherBase<std::exception> {
+    StringMatcherType m_matcher;
+
+public:
+    ExceptionMessageMatchesMatcher( StringMatcherType matcher ):
+        m_matcher( CATCH_MOVE( matcher ) ) {}
+
+    bool match( std::exception const& ex ) const override {
+        return m_matcher.match( ex.what() );
+    }
+
+    std::string describe() const override {
+        return " matches \"" + m_matcher.describe() + '"';
+    }
+};
+
+//! Creates a matcher that checks whether a message from an std derived
+//! exception matches a provided matcher
+template <typename StringMatcherType>
+ExceptionMessageMatchesMatcher<StringMatcherType>
+MessageMatches( StringMatcherType&& matcher ) {
+    return { CATCH_FORWARD( matcher ) };
+}
+
 } // namespace Matchers
 } // namespace Catch
 
diff --git a/tests/SelfTest/Baselines/automake.sw.approved.txt b/tests/SelfTest/Baselines/automake.sw.approved.txt
index e29de92b..332439a7 100644
--- a/tests/SelfTest/Baselines/automake.sw.approved.txt
+++ b/tests/SelfTest/Baselines/automake.sw.approved.txt
@@ -142,6 +142,7 @@ Nor would this
 :test-result: PASS Exception as a value (e.g. in REQUIRE_THROWS_MATCHES) can be stringified
 :test-result: FAIL Exception matchers that fail
 :test-result: PASS Exception matchers that succeed
+:test-result: PASS Exception message can be matched
 :test-result: PASS Exception messages can be tested for
 :test-result: PASS Exceptions matchers
 :test-result: FAIL Expected exceptions that don't throw or unexpected exceptions fail the test
diff --git a/tests/SelfTest/Baselines/automake.sw.multi.approved.txt b/tests/SelfTest/Baselines/automake.sw.multi.approved.txt
index 3ac53920..a7461ae5 100644
--- a/tests/SelfTest/Baselines/automake.sw.multi.approved.txt
+++ b/tests/SelfTest/Baselines/automake.sw.multi.approved.txt
@@ -140,6 +140,7 @@
 :test-result: PASS Exception as a value (e.g. in REQUIRE_THROWS_MATCHES) can be stringified
 :test-result: FAIL Exception matchers that fail
 :test-result: PASS Exception matchers that succeed
+:test-result: PASS Exception message can be matched
 :test-result: PASS Exception messages can be tested for
 :test-result: PASS Exceptions matchers
 :test-result: FAIL Expected exceptions that don't throw or unexpected exceptions fail the test
diff --git a/tests/SelfTest/Baselines/compact.sw.approved.txt b/tests/SelfTest/Baselines/compact.sw.approved.txt
index 5073c080..ff6b2875 100644
--- a/tests/SelfTest/Baselines/compact.sw.approved.txt
+++ b/tests/SelfTest/Baselines/compact.sw.approved.txt
@@ -572,6 +572,10 @@ Matchers.tests.cpp:<line number>: failed: throwsSpecialException( 3 ), SpecialEx
 Matchers.tests.cpp:<line number>: failed: throwsSpecialException( 4 ), SpecialException, ExceptionMatcher{ 1 } for: SpecialException::what special exception has value of 1
 Matchers.tests.cpp:<line number>: passed: throwsSpecialException( 1 ), SpecialException, ExceptionMatcher{ 1 } for: SpecialException::what special exception has value of 1
 Matchers.tests.cpp:<line number>: passed: throwsSpecialException( 2 ), SpecialException, ExceptionMatcher{ 2 } for: SpecialException::what special exception has value of 2
+Matchers.tests.cpp:<line number>: passed: throwsDerivedException(), DerivedException, MessageMatches( StartsWith( "Derived" ) ) for: DerivedException::what  matches "starts with: "Derived""
+Matchers.tests.cpp:<line number>: passed: throwsDerivedException(), DerivedException, MessageMatches( EndsWith( "::what" ) ) for: DerivedException::what  matches "ends with: "::what""
+Matchers.tests.cpp:<line number>: passed: throwsDerivedException(), DerivedException, MessageMatches( !StartsWith( "::what" ) ) for: DerivedException::what  matches "not starts with: "::what""
+Matchers.tests.cpp:<line number>: passed: throwsSpecialException( 2 ), SpecialException, MessageMatches( StartsWith( "Special" ) ) for: SpecialException::what  matches "starts with: "Special""
 Exception.tests.cpp:<line number>: passed: thisThrows(), "expected exception" for: "expected exception" equals: "expected exception"
 Exception.tests.cpp:<line number>: passed: thisThrows(), Equals( "expecteD Exception", Catch::CaseSensitive::No ) for: "expected exception" equals: "expected exception" (case insensitive)
 Exception.tests.cpp:<line number>: passed: thisThrows(), StartsWith( "expected" ) for: "expected exception" starts with: "expected"
@@ -2459,7 +2463,7 @@ InternalBenchmark.tests.cpp:<line number>: passed: med == 18. for: 18.0 == 18.0
 InternalBenchmark.tests.cpp:<line number>: passed: q3 == 23. for: 23.0 == 23.0
 Misc.tests.cpp:<line number>: passed:
 Misc.tests.cpp:<line number>: passed:
-test cases:  394 |  304 passed |  83 failed |  7 failed as expected
-assertions: 2159 | 1989 passed | 143 failed | 27 failed as expected
+test cases:  395 |  305 passed |  83 failed |  7 failed as expected
+assertions: 2163 | 1993 passed | 143 failed | 27 failed as expected
 
 
diff --git a/tests/SelfTest/Baselines/compact.sw.multi.approved.txt b/tests/SelfTest/Baselines/compact.sw.multi.approved.txt
index af348dda..d11bdbae 100644
--- a/tests/SelfTest/Baselines/compact.sw.multi.approved.txt
+++ b/tests/SelfTest/Baselines/compact.sw.multi.approved.txt
@@ -570,6 +570,10 @@ Matchers.tests.cpp:<line number>: failed: throwsSpecialException( 3 ), SpecialEx
 Matchers.tests.cpp:<line number>: failed: throwsSpecialException( 4 ), SpecialException, ExceptionMatcher{ 1 } for: SpecialException::what special exception has value of 1
 Matchers.tests.cpp:<line number>: passed: throwsSpecialException( 1 ), SpecialException, ExceptionMatcher{ 1 } for: SpecialException::what special exception has value of 1
 Matchers.tests.cpp:<line number>: passed: throwsSpecialException( 2 ), SpecialException, ExceptionMatcher{ 2 } for: SpecialException::what special exception has value of 2
+Matchers.tests.cpp:<line number>: passed: throwsDerivedException(), DerivedException, MessageMatches( StartsWith( "Derived" ) ) for: DerivedException::what  matches "starts with: "Derived""
+Matchers.tests.cpp:<line number>: passed: throwsDerivedException(), DerivedException, MessageMatches( EndsWith( "::what" ) ) for: DerivedException::what  matches "ends with: "::what""
+Matchers.tests.cpp:<line number>: passed: throwsDerivedException(), DerivedException, MessageMatches( !StartsWith( "::what" ) ) for: DerivedException::what  matches "not starts with: "::what""
+Matchers.tests.cpp:<line number>: passed: throwsSpecialException( 2 ), SpecialException, MessageMatches( StartsWith( "Special" ) ) for: SpecialException::what  matches "starts with: "Special""
 Exception.tests.cpp:<line number>: passed: thisThrows(), "expected exception" for: "expected exception" equals: "expected exception"
 Exception.tests.cpp:<line number>: passed: thisThrows(), Equals( "expecteD Exception", Catch::CaseSensitive::No ) for: "expected exception" equals: "expected exception" (case insensitive)
 Exception.tests.cpp:<line number>: passed: thisThrows(), StartsWith( "expected" ) for: "expected exception" starts with: "expected"
@@ -2451,7 +2455,7 @@ InternalBenchmark.tests.cpp:<line number>: passed: med == 18. for: 18.0 == 18.0
 InternalBenchmark.tests.cpp:<line number>: passed: q3 == 23. for: 23.0 == 23.0
 Misc.tests.cpp:<line number>: passed:
 Misc.tests.cpp:<line number>: passed:
-test cases:  394 |  304 passed |  83 failed |  7 failed as expected
-assertions: 2159 | 1989 passed | 143 failed | 27 failed as expected
+test cases:  395 |  305 passed |  83 failed |  7 failed as expected
+assertions: 2163 | 1993 passed | 143 failed | 27 failed as expected
 
 
diff --git a/tests/SelfTest/Baselines/console.std.approved.txt b/tests/SelfTest/Baselines/console.std.approved.txt
index 5ad8447a..39fd845b 100644
--- a/tests/SelfTest/Baselines/console.std.approved.txt
+++ b/tests/SelfTest/Baselines/console.std.approved.txt
@@ -1394,6 +1394,6 @@ due to unexpected exception with message:
   Why would you throw a std::string?
 
 ===============================================================================
-test cases:  394 |  318 passed |  69 failed |  7 failed as expected
-assertions: 2144 | 1989 passed | 128 failed | 27 failed as expected
+test cases:  395 |  319 passed |  69 failed |  7 failed as expected
+assertions: 2148 | 1993 passed | 128 failed | 27 failed as expected
 
diff --git a/tests/SelfTest/Baselines/console.sw.approved.txt b/tests/SelfTest/Baselines/console.sw.approved.txt
index 1ef94ee5..57fa6239 100644
--- a/tests/SelfTest/Baselines/console.sw.approved.txt
+++ b/tests/SelfTest/Baselines/console.sw.approved.txt
@@ -4282,6 +4282,32 @@ Matchers.tests.cpp:<line number>: PASSED:
 with expansion:
   SpecialException::what special exception has value of 2
 
+-------------------------------------------------------------------------------
+Exception message can be matched
+-------------------------------------------------------------------------------
+Matchers.tests.cpp:<line number>
+...............................................................................
+
+Matchers.tests.cpp:<line number>: PASSED:
+  REQUIRE_THROWS_MATCHES( throwsDerivedException(), DerivedException, MessageMatches( StartsWith( "Derived" ) ) )
+with expansion:
+  DerivedException::what  matches "starts with: "Derived""
+
+Matchers.tests.cpp:<line number>: PASSED:
+  REQUIRE_THROWS_MATCHES( throwsDerivedException(), DerivedException, MessageMatches( EndsWith( "::what" ) ) )
+with expansion:
+  DerivedException::what  matches "ends with: "::what""
+
+Matchers.tests.cpp:<line number>: PASSED:
+  REQUIRE_THROWS_MATCHES( throwsDerivedException(), DerivedException, MessageMatches( !StartsWith( "::what" ) ) )
+with expansion:
+  DerivedException::what  matches "not starts with: "::what""
+
+Matchers.tests.cpp:<line number>: PASSED:
+  REQUIRE_THROWS_MATCHES( throwsSpecialException( 2 ), SpecialException, MessageMatches( StartsWith( "Special" ) ) )
+with expansion:
+  SpecialException::what  matches "starts with: "Special""
+
 -------------------------------------------------------------------------------
 Exception messages can be tested for
   exact match
@@ -17518,6 +17544,6 @@ Misc.tests.cpp:<line number>
 Misc.tests.cpp:<line number>: PASSED:
 
 ===============================================================================
-test cases:  394 |  304 passed |  83 failed |  7 failed as expected
-assertions: 2159 | 1989 passed | 143 failed | 27 failed as expected
+test cases:  395 |  305 passed |  83 failed |  7 failed as expected
+assertions: 2163 | 1993 passed | 143 failed | 27 failed as expected
 
diff --git a/tests/SelfTest/Baselines/console.sw.multi.approved.txt b/tests/SelfTest/Baselines/console.sw.multi.approved.txt
index c281374f..6e5faa96 100644
--- a/tests/SelfTest/Baselines/console.sw.multi.approved.txt
+++ b/tests/SelfTest/Baselines/console.sw.multi.approved.txt
@@ -4280,6 +4280,32 @@ Matchers.tests.cpp:<line number>: PASSED:
 with expansion:
   SpecialException::what special exception has value of 2
 
+-------------------------------------------------------------------------------
+Exception message can be matched
+-------------------------------------------------------------------------------
+Matchers.tests.cpp:<line number>
+...............................................................................
+
+Matchers.tests.cpp:<line number>: PASSED:
+  REQUIRE_THROWS_MATCHES( throwsDerivedException(), DerivedException, MessageMatches( StartsWith( "Derived" ) ) )
+with expansion:
+  DerivedException::what  matches "starts with: "Derived""
+
+Matchers.tests.cpp:<line number>: PASSED:
+  REQUIRE_THROWS_MATCHES( throwsDerivedException(), DerivedException, MessageMatches( EndsWith( "::what" ) ) )
+with expansion:
+  DerivedException::what  matches "ends with: "::what""
+
+Matchers.tests.cpp:<line number>: PASSED:
+  REQUIRE_THROWS_MATCHES( throwsDerivedException(), DerivedException, MessageMatches( !StartsWith( "::what" ) ) )
+with expansion:
+  DerivedException::what  matches "not starts with: "::what""
+
+Matchers.tests.cpp:<line number>: PASSED:
+  REQUIRE_THROWS_MATCHES( throwsSpecialException( 2 ), SpecialException, MessageMatches( StartsWith( "Special" ) ) )
+with expansion:
+  SpecialException::what  matches "starts with: "Special""
+
 -------------------------------------------------------------------------------
 Exception messages can be tested for
   exact match
@@ -17510,6 +17536,6 @@ Misc.tests.cpp:<line number>
 Misc.tests.cpp:<line number>: PASSED:
 
 ===============================================================================
-test cases:  394 |  304 passed |  83 failed |  7 failed as expected
-assertions: 2159 | 1989 passed | 143 failed | 27 failed as expected
+test cases:  395 |  305 passed |  83 failed |  7 failed as expected
+assertions: 2163 | 1993 passed | 143 failed | 27 failed as expected
 
diff --git a/tests/SelfTest/Baselines/junit.sw.approved.txt b/tests/SelfTest/Baselines/junit.sw.approved.txt
index bd983051..e521aec6 100644
--- a/tests/SelfTest/Baselines/junit.sw.approved.txt
+++ b/tests/SelfTest/Baselines/junit.sw.approved.txt
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <testsuitesloose text artifact
 >
-  <testsuite name="<exe-name>" errors="17" failures="126" tests="2159" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
+  <testsuite name="<exe-name>" errors="17" failures="126" tests="2163" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
     <properties>
       <property name="random-seed" value="1"/>
       <property name="filters" value="&quot;*&quot; ~[!nonportable] ~[!benchmark] ~[approvals]"/>
@@ -634,6 +634,7 @@ Matchers.tests.cpp:<line number>
       </failure>
     </testcase>
     <testcase classname="<exe-name>.global" name="Exception matchers that succeed" time="{duration}" status="run"/>
+    <testcase classname="<exe-name>.global" name="Exception message can be matched" time="{duration}" status="run"/>
     <testcase classname="<exe-name>.global" name="Exception messages can be tested for/exact match" time="{duration}" status="run"/>
     <testcase classname="<exe-name>.global" name="Exception messages can be tested for/different case" time="{duration}" status="run"/>
     <testcase classname="<exe-name>.global" name="Exception messages can be tested for/wildcarded" time="{duration}" status="run"/>
diff --git a/tests/SelfTest/Baselines/junit.sw.multi.approved.txt b/tests/SelfTest/Baselines/junit.sw.multi.approved.txt
index 3231c3e8..cde93ecf 100644
--- a/tests/SelfTest/Baselines/junit.sw.multi.approved.txt
+++ b/tests/SelfTest/Baselines/junit.sw.multi.approved.txt
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <testsuites>
-  <testsuite name="<exe-name>" errors="17" failures="126" tests="2159" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
+  <testsuite name="<exe-name>" errors="17" failures="126" tests="2163" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
     <properties>
       <property name="random-seed" value="1"/>
       <property name="filters" value="&quot;*&quot; ~[!nonportable] ~[!benchmark] ~[approvals]"/>
@@ -633,6 +633,7 @@ Matchers.tests.cpp:<line number>
       </failure>
     </testcase>
     <testcase classname="<exe-name>.global" name="Exception matchers that succeed" time="{duration}" status="run"/>
+    <testcase classname="<exe-name>.global" name="Exception message can be matched" time="{duration}" status="run"/>
     <testcase classname="<exe-name>.global" name="Exception messages can be tested for/exact match" time="{duration}" status="run"/>
     <testcase classname="<exe-name>.global" name="Exception messages can be tested for/different case" time="{duration}" status="run"/>
     <testcase classname="<exe-name>.global" name="Exception messages can be tested for/wildcarded" time="{duration}" status="run"/>
diff --git a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt
index 122e3dda..e778d549 100644
--- a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt
+++ b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt
@@ -1156,6 +1156,7 @@ Matchers.tests.cpp:<line number>
       </failure>
     </testCase>
     <testCase name="Exception matchers that succeed" duration="{duration}"/>
+    <testCase name="Exception message can be matched" duration="{duration}"/>
     <testCase name="Exceptions matchers" duration="{duration}"/>
     <testCase name="Floating point matchers: double/Relative" duration="{duration}"/>
     <testCase name="Floating point matchers: double/Relative/Some subnormal values" duration="{duration}"/>
diff --git a/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt b/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt
index 8025e455..47fab5b5 100644
--- a/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt
+++ b/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt
@@ -1155,6 +1155,7 @@ Matchers.tests.cpp:<line number>
       </failure>
     </testCase>
     <testCase name="Exception matchers that succeed" duration="{duration}"/>
+    <testCase name="Exception message can be matched" duration="{duration}"/>
     <testCase name="Exceptions matchers" duration="{duration}"/>
     <testCase name="Floating point matchers: double/Relative" duration="{duration}"/>
     <testCase name="Floating point matchers: double/Relative/Some subnormal values" duration="{duration}"/>
diff --git a/tests/SelfTest/Baselines/tap.sw.approved.txt b/tests/SelfTest/Baselines/tap.sw.approved.txt
index 1832282a..595c1ae7 100644
--- a/tests/SelfTest/Baselines/tap.sw.approved.txt
+++ b/tests/SelfTest/Baselines/tap.sw.approved.txt
@@ -1076,6 +1076,14 @@ not ok {test-number} - throwsSpecialException( 4 ), SpecialException, ExceptionM
 ok {test-number} - throwsSpecialException( 1 ), SpecialException, ExceptionMatcher{ 1 } for: SpecialException::what special exception has value of 1
 # Exception matchers that succeed
 ok {test-number} - throwsSpecialException( 2 ), SpecialException, ExceptionMatcher{ 2 } for: SpecialException::what special exception has value of 2
+# Exception message can be matched
+ok {test-number} - throwsDerivedException(), DerivedException, MessageMatches( StartsWith( "Derived" ) ) for: DerivedException::what  matches "starts with: "Derived""
+# Exception message can be matched
+ok {test-number} - throwsDerivedException(), DerivedException, MessageMatches( EndsWith( "::what" ) ) for: DerivedException::what  matches "ends with: "::what""
+# Exception message can be matched
+ok {test-number} - throwsDerivedException(), DerivedException, MessageMatches( !StartsWith( "::what" ) ) for: DerivedException::what  matches "not starts with: "::what""
+# Exception message can be matched
+ok {test-number} - throwsSpecialException( 2 ), SpecialException, MessageMatches( StartsWith( "Special" ) ) for: SpecialException::what  matches "starts with: "Special""
 # Exception messages can be tested for
 ok {test-number} - thisThrows(), "expected exception" for: "expected exception" equals: "expected exception"
 # Exception messages can be tested for
@@ -4322,5 +4330,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0
 ok {test-number} -
 # xmlentitycheck
 ok {test-number} -
-1..2159
+1..2163
 
diff --git a/tests/SelfTest/Baselines/tap.sw.multi.approved.txt b/tests/SelfTest/Baselines/tap.sw.multi.approved.txt
index 4446141d..b0fc4c6c 100644
--- a/tests/SelfTest/Baselines/tap.sw.multi.approved.txt
+++ b/tests/SelfTest/Baselines/tap.sw.multi.approved.txt
@@ -1074,6 +1074,14 @@ not ok {test-number} - throwsSpecialException( 4 ), SpecialException, ExceptionM
 ok {test-number} - throwsSpecialException( 1 ), SpecialException, ExceptionMatcher{ 1 } for: SpecialException::what special exception has value of 1
 # Exception matchers that succeed
 ok {test-number} - throwsSpecialException( 2 ), SpecialException, ExceptionMatcher{ 2 } for: SpecialException::what special exception has value of 2
+# Exception message can be matched
+ok {test-number} - throwsDerivedException(), DerivedException, MessageMatches( StartsWith( "Derived" ) ) for: DerivedException::what  matches "starts with: "Derived""
+# Exception message can be matched
+ok {test-number} - throwsDerivedException(), DerivedException, MessageMatches( EndsWith( "::what" ) ) for: DerivedException::what  matches "ends with: "::what""
+# Exception message can be matched
+ok {test-number} - throwsDerivedException(), DerivedException, MessageMatches( !StartsWith( "::what" ) ) for: DerivedException::what  matches "not starts with: "::what""
+# Exception message can be matched
+ok {test-number} - throwsSpecialException( 2 ), SpecialException, MessageMatches( StartsWith( "Special" ) ) for: SpecialException::what  matches "starts with: "Special""
 # Exception messages can be tested for
 ok {test-number} - thisThrows(), "expected exception" for: "expected exception" equals: "expected exception"
 # Exception messages can be tested for
@@ -4314,5 +4322,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0
 ok {test-number} -
 # xmlentitycheck
 ok {test-number} -
-1..2159
+1..2163
 
diff --git a/tests/SelfTest/Baselines/teamcity.sw.approved.txt b/tests/SelfTest/Baselines/teamcity.sw.approved.txt
index 7049f2b6..58ad2aed 100644
--- a/tests/SelfTest/Baselines/teamcity.sw.approved.txt
+++ b/tests/SelfTest/Baselines/teamcity.sw.approved.txt
@@ -345,6 +345,8 @@ Matchers.tests.cpp:<line number>|nexpression failed|n  REQUIRE_THROWS_MATCHES( t
 ##teamcity[testFinished name='Exception matchers that fail' duration="{duration}"]
 ##teamcity[testStarted name='Exception matchers that succeed']
 ##teamcity[testFinished name='Exception matchers that succeed' duration="{duration}"]
+##teamcity[testStarted name='Exception message can be matched']
+##teamcity[testFinished name='Exception message can be matched' duration="{duration}"]
 ##teamcity[testStarted name='Exception messages can be tested for']
 ##teamcity[testFinished name='Exception messages can be tested for' duration="{duration}"]
 ##teamcity[testStarted name='Exceptions matchers']
diff --git a/tests/SelfTest/Baselines/teamcity.sw.multi.approved.txt b/tests/SelfTest/Baselines/teamcity.sw.multi.approved.txt
index 96de7dd8..2f539ced 100644
--- a/tests/SelfTest/Baselines/teamcity.sw.multi.approved.txt
+++ b/tests/SelfTest/Baselines/teamcity.sw.multi.approved.txt
@@ -345,6 +345,8 @@ Matchers.tests.cpp:<line number>|nexpression failed|n  REQUIRE_THROWS_MATCHES( t
 ##teamcity[testFinished name='Exception matchers that fail' duration="{duration}"]
 ##teamcity[testStarted name='Exception matchers that succeed']
 ##teamcity[testFinished name='Exception matchers that succeed' duration="{duration}"]
+##teamcity[testStarted name='Exception message can be matched']
+##teamcity[testFinished name='Exception message can be matched' duration="{duration}"]
 ##teamcity[testStarted name='Exception messages can be tested for']
 ##teamcity[testFinished name='Exception messages can be tested for' duration="{duration}"]
 ##teamcity[testStarted name='Exceptions matchers']
diff --git a/tests/SelfTest/Baselines/xml.sw.approved.txt b/tests/SelfTest/Baselines/xml.sw.approved.txt
index 4ff2e4f2..cb49412e 100644
--- a/tests/SelfTest/Baselines/xml.sw.approved.txt
+++ b/tests/SelfTest/Baselines/xml.sw.approved.txt
@@ -4794,6 +4794,41 @@ C
     </Expression>
     <OverallResult success="true"/>
   </TestCase>
+  <TestCase name="Exception message can be matched" tags="[!throws][exceptions][matchers]" filename="tests/<exe-name>/UsageTests/Matchers.tests.cpp" >
+    <Expression success="true" type="REQUIRE_THROWS_MATCHES" filename="tests/<exe-name>/UsageTests/Matchers.tests.cpp" >
+      <Original>
+        throwsDerivedException(), DerivedException, MessageMatches( StartsWith( "Derived" ) )
+      </Original>
+      <Expanded>
+        DerivedException::what  matches "starts with: "Derived""
+      </Expanded>
+    </Expression>
+    <Expression success="true" type="REQUIRE_THROWS_MATCHES" filename="tests/<exe-name>/UsageTests/Matchers.tests.cpp" >
+      <Original>
+        throwsDerivedException(), DerivedException, MessageMatches( EndsWith( "::what" ) )
+      </Original>
+      <Expanded>
+        DerivedException::what  matches "ends with: "::what""
+      </Expanded>
+    </Expression>
+    <Expression success="true" type="REQUIRE_THROWS_MATCHES" filename="tests/<exe-name>/UsageTests/Matchers.tests.cpp" >
+      <Original>
+        throwsDerivedException(), DerivedException, MessageMatches( !StartsWith( "::what" ) )
+      </Original>
+      <Expanded>
+        DerivedException::what  matches "not starts with: "::what""
+      </Expanded>
+    </Expression>
+    <Expression success="true" type="REQUIRE_THROWS_MATCHES" filename="tests/<exe-name>/UsageTests/Matchers.tests.cpp" >
+      <Original>
+        throwsSpecialException( 2 ), SpecialException, MessageMatches( StartsWith( "Special" ) )
+      </Original>
+      <Expanded>
+        SpecialException::what  matches "starts with: "Special""
+      </Expanded>
+    </Expression>
+    <OverallResult success="true"/>
+  </TestCase>
   <TestCase name="Exception messages can be tested for" tags="[!throws]" filename="tests/<exe-name>/UsageTests/Exception.tests.cpp" >
     <Section name="exact match" filename="tests/<exe-name>/UsageTests/Exception.tests.cpp" >
       <Expression success="true" type="REQUIRE_THROWS_WITH" filename="tests/<exe-name>/UsageTests/Exception.tests.cpp" >
@@ -20483,6 +20518,6 @@ loose text artifact
     </Section>
     <OverallResult success="true"/>
   </TestCase>
-  <OverallResults successes="1989" failures="143" expectedFailures="27"/>
-  <OverallResultsCases successes="304" failures="83" expectedFailures="7"/>
+  <OverallResults successes="1993" failures="143" expectedFailures="27"/>
+  <OverallResultsCases successes="305" failures="83" expectedFailures="7"/>
 </Catch2TestRun>
diff --git a/tests/SelfTest/Baselines/xml.sw.multi.approved.txt b/tests/SelfTest/Baselines/xml.sw.multi.approved.txt
index a0096170..b6146646 100644
--- a/tests/SelfTest/Baselines/xml.sw.multi.approved.txt
+++ b/tests/SelfTest/Baselines/xml.sw.multi.approved.txt
@@ -4794,6 +4794,41 @@ C
     </Expression>
     <OverallResult success="true"/>
   </TestCase>
+  <TestCase name="Exception message can be matched" tags="[!throws][exceptions][matchers]" filename="tests/<exe-name>/UsageTests/Matchers.tests.cpp" >
+    <Expression success="true" type="REQUIRE_THROWS_MATCHES" filename="tests/<exe-name>/UsageTests/Matchers.tests.cpp" >
+      <Original>
+        throwsDerivedException(), DerivedException, MessageMatches( StartsWith( "Derived" ) )
+      </Original>
+      <Expanded>
+        DerivedException::what  matches "starts with: "Derived""
+      </Expanded>
+    </Expression>
+    <Expression success="true" type="REQUIRE_THROWS_MATCHES" filename="tests/<exe-name>/UsageTests/Matchers.tests.cpp" >
+      <Original>
+        throwsDerivedException(), DerivedException, MessageMatches( EndsWith( "::what" ) )
+      </Original>
+      <Expanded>
+        DerivedException::what  matches "ends with: "::what""
+      </Expanded>
+    </Expression>
+    <Expression success="true" type="REQUIRE_THROWS_MATCHES" filename="tests/<exe-name>/UsageTests/Matchers.tests.cpp" >
+      <Original>
+        throwsDerivedException(), DerivedException, MessageMatches( !StartsWith( "::what" ) )
+      </Original>
+      <Expanded>
+        DerivedException::what  matches "not starts with: "::what""
+      </Expanded>
+    </Expression>
+    <Expression success="true" type="REQUIRE_THROWS_MATCHES" filename="tests/<exe-name>/UsageTests/Matchers.tests.cpp" >
+      <Original>
+        throwsSpecialException( 2 ), SpecialException, MessageMatches( StartsWith( "Special" ) )
+      </Original>
+      <Expanded>
+        SpecialException::what  matches "starts with: "Special""
+      </Expanded>
+    </Expression>
+    <OverallResult success="true"/>
+  </TestCase>
   <TestCase name="Exception messages can be tested for" tags="[!throws]" filename="tests/<exe-name>/UsageTests/Exception.tests.cpp" >
     <Section name="exact match" filename="tests/<exe-name>/UsageTests/Exception.tests.cpp" >
       <Expression success="true" type="REQUIRE_THROWS_WITH" filename="tests/<exe-name>/UsageTests/Exception.tests.cpp" >
@@ -20482,6 +20517,6 @@ There is no extra whitespace here
     </Section>
     <OverallResult success="true"/>
   </TestCase>
-  <OverallResults successes="1989" failures="143" expectedFailures="27"/>
-  <OverallResultsCases successes="304" failures="83" expectedFailures="7"/>
+  <OverallResults successes="1993" failures="143" expectedFailures="27"/>
+  <OverallResultsCases successes="305" failures="83" expectedFailures="7"/>
 </Catch2TestRun>
diff --git a/tests/SelfTest/UsageTests/Matchers.tests.cpp b/tests/SelfTest/UsageTests/Matchers.tests.cpp
index 1ce3158b..b2239572 100644
--- a/tests/SelfTest/UsageTests/Matchers.tests.cpp
+++ b/tests/SelfTest/UsageTests/Matchers.tests.cpp
@@ -660,6 +660,21 @@ TEST_CASE( "Exceptions matchers", "[matchers][exceptions][!throws]" ) {
                             Message( "SpecialException::what" ) );
 }
 
+TEST_CASE( "Exception message can be matched", "[matchers][exceptions][!throws]" ) {
+    REQUIRE_THROWS_MATCHES( throwsDerivedException(),
+                            DerivedException,
+                            MessageMatches( StartsWith( "Derived" ) ) );
+    REQUIRE_THROWS_MATCHES( throwsDerivedException(),
+                            DerivedException,
+                            MessageMatches( EndsWith( "::what" ) ) );
+    REQUIRE_THROWS_MATCHES( throwsDerivedException(),
+                            DerivedException,
+                            MessageMatches( !StartsWith( "::what" ) ) );
+    REQUIRE_THROWS_MATCHES( throwsSpecialException( 2 ),
+                            SpecialException,
+                            MessageMatches( StartsWith( "Special" ) ) );
+}
+
 struct CheckedTestingMatcher : Catch::Matchers::MatcherBase<int> {
     mutable bool matchCalled = false;
     bool matchSucceeds = false;