diff options
| author | lbckmnn | 2022-12-12 00:40:47 +0100 |
|---|---|---|
| committer | GitHub | 2022-12-12 00:40:47 +0100 |
| commit | 9c0533a90504b2b1c308dc7cc77ff194f81046e2 (patch) | |
| tree | 8cd45ddd221a06f4df00b2f977ee6436cd2fe724 /docs | |
| parent | ed02710b83c2a3ddbca20b86f3d26d2fb99d2d02 (diff) | |
| download | catch3-9c0533a90504b2b1c308dc7cc77ff194f81046e2.tar.gz | |
Add MessageMatches matcher for exception (#2570)
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/matchers.md | 12 |
1 files changed, 10 insertions, 2 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 |