Commit 680a5aa3 by Abseil Team Committed by Derek Mauro

Googletest export

Move matchers reference from cheat sheet into its own document PiperOrigin-RevId: 370749693
parent 719fd2d3
......@@ -21,6 +21,8 @@ nav:
url: "/gmock_cheat_sheet.html"
- section: "References"
items:
- title: "Matchers"
url: "/reference/matchers.html"
- title: "Testing FAQ"
url: "/faq.html"
- title: "Mocking FAQ"
......
......@@ -364,11 +364,9 @@ Verifies that `val1` is less than, or almost equal to, `val2`. You can replace
### Asserting Using gMock Matchers
[gMock](gmock_for_dummies.md) comes with
[a library of matchers](gmock_cheat_sheet.md#MatcherList) for
validating arguments passed to mock objects. A gMock *matcher* is basically a
predicate that knows how to describe itself. It can be used in these assertion
macros:
gMock comes with a library of *matchers* for validating arguments passed to mock
objects. A gMock matcher is basically a predicate that knows how to describe
itself. It can be used in these assertion macros:
| Fatal assertion | Nonfatal assertion | Verifies |
......@@ -386,14 +384,11 @@ using ::testing::StartsWith;
EXPECT_THAT(Foo(), StartsWith("Hello"));
```
Read this
[recipe](gmock_cook_book.md#using-matchers-in-googletest-assertions)
in the gMock Cookbook for more details.
gMock has a rich set of matchers. You can do many things googletest cannot do
alone with them. For a list of matchers gMock provides, read
[this](gmock_cook_book.md##using-matchers). It's easy to write
your [own matchers](gmock_cook_book.md#NewMatchers) too.
See
[Using Matchers in googletest Assertions](gmock_cook_book.md#using-matchers-in-googletest-assertions)
in the gMock Cookbook for more details. For a list of built-in matchers, see the
[Matchers Reference](reference/matchers.md). You can also write your own
matchers—see [Writing New Matchers Quickly](gmock_cook_book.md#NewMatchers).
gMock is bundled with googletest, so you don't need to add any build dependency
in order to take advantage of this. Just include `"gmock/gmock.h"`
......
......@@ -1184,11 +1184,12 @@ Hamcrest project, which adds `assertThat()` to JUnit.
### Using Predicates as Matchers
gMock provides a [built-in set](gmock_cheat_sheet.md#MatcherList) of matchers.
In case you find them lacking, you can use an arbitrary unary predicate function
or functor as a matcher - as long as the predicate accepts a value of the type
you want. You do this by wrapping the predicate inside the `Truly()` function,
for example:
gMock provides a set of built-in matchers for matching arguments with expected
values—see the [Matchers Reference](reference/matchers.md) for more information.
In case you find the built-in set lacking, you can use an arbitrary unary
predicate function or functor as a matcher - as long as the predicate accepts a
value of the type you want. You do this by wrapping the predicate inside the
`Truly()` function, for example:
```cpp
using ::testing::Truly;
......
......@@ -371,8 +371,8 @@ convenient way of saying "any value".
In the above examples, `100` and `50` are also matchers; implicitly, they are
the same as `Eq(100)` and `Eq(50)`, which specify that the argument must be
equal (using `operator==`) to the matcher argument. There are many
[built-in matchers](gmock_cheat_sheet.md#MatcherList) for common types (as well
as [custom matchers](gmock_cook_book.md#NewMatchers)); for example:
[built-in matchers](reference/matchers.md) for common types (as well as
[custom matchers](gmock_cook_book.md#NewMatchers)); for example:
```cpp
using ::testing::Ge;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment