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: ...@@ -21,6 +21,8 @@ nav:
url: "/gmock_cheat_sheet.html" url: "/gmock_cheat_sheet.html"
- section: "References" - section: "References"
items: items:
- title: "Matchers"
url: "/reference/matchers.html"
- title: "Testing FAQ" - title: "Testing FAQ"
url: "/faq.html" url: "/faq.html"
- title: "Mocking FAQ" - title: "Mocking FAQ"
......
...@@ -364,11 +364,9 @@ Verifies that `val1` is less than, or almost equal to, `val2`. You can replace ...@@ -364,11 +364,9 @@ Verifies that `val1` is less than, or almost equal to, `val2`. You can replace
### Asserting Using gMock Matchers ### Asserting Using gMock Matchers
[gMock](gmock_for_dummies.md) comes with gMock comes with a library of *matchers* for validating arguments passed to mock
[a library of matchers](gmock_cheat_sheet.md#MatcherList) for objects. A gMock matcher is basically a predicate that knows how to describe
validating arguments passed to mock objects. A gMock *matcher* is basically a itself. It can be used in these assertion macros:
predicate that knows how to describe itself. It can be used in these assertion
macros:
| Fatal assertion | Nonfatal assertion | Verifies | | Fatal assertion | Nonfatal assertion | Verifies |
...@@ -386,14 +384,11 @@ using ::testing::StartsWith; ...@@ -386,14 +384,11 @@ using ::testing::StartsWith;
EXPECT_THAT(Foo(), StartsWith("Hello")); EXPECT_THAT(Foo(), StartsWith("Hello"));
``` ```
Read this See
[recipe](gmock_cook_book.md#using-matchers-in-googletest-assertions) [Using Matchers in googletest Assertions](gmock_cook_book.md#using-matchers-in-googletest-assertions)
in the gMock Cookbook for more details. 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
gMock has a rich set of matchers. You can do many things googletest cannot do matchers—see [Writing New Matchers Quickly](gmock_cook_book.md#NewMatchers).
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.
gMock is bundled with googletest, so you don't need to add any build dependency 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"` in order to take advantage of this. Just include `"gmock/gmock.h"`
......
...@@ -1184,11 +1184,12 @@ Hamcrest project, which adds `assertThat()` to JUnit. ...@@ -1184,11 +1184,12 @@ Hamcrest project, which adds `assertThat()` to JUnit.
### Using Predicates as Matchers ### Using Predicates as Matchers
gMock provides a [built-in set](gmock_cheat_sheet.md#MatcherList) of matchers. gMock provides a set of built-in matchers for matching arguments with expected
In case you find them lacking, you can use an arbitrary unary predicate function values—see the [Matchers Reference](reference/matchers.md) for more information.
or functor as a matcher - as long as the predicate accepts a value of the type In case you find the built-in set lacking, you can use an arbitrary unary
you want. You do this by wrapping the predicate inside the `Truly()` function, predicate function or functor as a matcher - as long as the predicate accepts a
for example: value of the type you want. You do this by wrapping the predicate inside the
`Truly()` function, for example:
```cpp ```cpp
using ::testing::Truly; using ::testing::Truly;
......
...@@ -371,8 +371,8 @@ convenient way of saying "any value". ...@@ -371,8 +371,8 @@ convenient way of saying "any value".
In the above examples, `100` and `50` are also matchers; implicitly, they are 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 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 equal (using `operator==`) to the matcher argument. There are many
[built-in matchers](gmock_cheat_sheet.md#MatcherList) for common types (as well [built-in matchers](reference/matchers.md) for common types (as well as
as [custom matchers](gmock_cook_book.md#NewMatchers)); for example: [custom matchers](gmock_cook_book.md#NewMatchers)); for example:
```cpp ```cpp
using ::testing::Ge; 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