diff options
Diffstat (limited to 'docs/reference')
-rw-r--r-- | docs/reference/actions.md | 4 | ||||
-rw-r--r-- | docs/reference/matchers.md | 27 | ||||
-rw-r--r-- | docs/reference/testing.md | 2 |
3 files changed, 30 insertions, 3 deletions
diff --git a/docs/reference/actions.md b/docs/reference/actions.md index 0ebdc1e..2ca3a9f 100644 --- a/docs/reference/actions.md +++ b/docs/reference/actions.md @@ -48,8 +48,8 @@ functor, or lambda. | `InvokeWithoutArgs(object_pointer, &class::method)` | Invoke the method on the object, which takes no arguments. | | `InvokeArgument<N>(arg1, arg2, ..., argk)` | Invoke the mock function's `N`-th (0-based) argument, which must be a function or a functor, with the `k` arguments. | -The return value of the invoked function is used as the return value of the -action. +The return value of the invoked function (except `InvokeArgument`) is used as +the return value of the action. When defining a callable to be used with `Invoke*()`, you can declare any unused parameters as `Unused`: diff --git a/docs/reference/matchers.md b/docs/reference/matchers.md index 8ff9e0b..8b3d140 100644 --- a/docs/reference/matchers.md +++ b/docs/reference/matchers.md @@ -111,6 +111,33 @@ use the regular expression syntax defined [here](../advanced.md#regular-expression-syntax). All of these matchers, except `ContainsRegex()` and `MatchesRegex()` work for wide strings as well. +## Exception Matchers + +| Matcher | Description | +| :---------------------------------------- | :------------------------------- | +| `Throws<E>()` | The `argument` is a callable object that, when called, throws an exception of the expected type `E`. | +| `Throws<E>(m)` | The `argument` is a callable object that, when called, throws an exception of type `E` that satisfies the matcher `m`. | +| `ThrowsMessage<E>(m)` | The `argument` is a callable object that, when called, throws an exception of type `E` with a message that satisfies the matcher `m`. | + +Examples: + +```cpp +auto argument = [] { throw std::runtime_error("error msg"); }; + +// Checks if the lambda throws a `std::runtime_error`. +EXPECT_THAT(argument, Throws<std::runtime_error>()); + +// Checks if the lambda throws a `std::runtime_error` with a specific message +// that matches "error msg". +EXPECT_THAT(argument, + Throws<std::runtime_error>(Property(&std::runtime_error::what, + Eq("error msg")))); + +// Checks if the lambda throws a `std::runtime_error` with a message that +// contains "msg". +EXPECT_THAT(argument, ThrowsMessage<std::runtime_error>(HasSubstr("msg"))); +``` + ## Container Matchers Most STL-style containers support `==`, so you can use `Eq(expected_container)` diff --git a/docs/reference/testing.md b/docs/reference/testing.md index d7dc5cf..ea43721 100644 --- a/docs/reference/testing.md +++ b/docs/reference/testing.md @@ -203,7 +203,7 @@ class MyParam { INSTANTIATE_TEST_SUITE_P(MyInstantiation, MyTestSuite, ConvertGenerator(Combine(Values(1, 1.2), Bool()), - [](const std::tuple<int i, bool>& t){ + [](const std::tuple<int, bool>& t){ const auto [i, b] = t; return MyParam(i, b); })); |