From 76cd89bcf1633177f42d9ddee2aab70112640e50 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Tue, 6 Jan 2026 00:08:54 -0800 Subject: [PATCH] Point from the "Defining Matchers" section in the reference doc to the cookbook, which is much more detailed. PiperOrigin-RevId: 852639172 Change-Id: Ia39a01702c7c64404950a1be19b1ebdfdff8f010 --- docs/gmock_cook_book.md | 6 +++--- docs/reference/matchers.md | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/docs/gmock_cook_book.md b/docs/gmock_cook_book.md index 22ad0214..b53cbd59 100644 --- a/docs/gmock_cook_book.md +++ b/docs/gmock_cook_book.md @@ -3566,7 +3566,7 @@ general leads to better compiler error messages that pay off in the long run. They also allow overloading matchers based on parameter types (as opposed to just based on the number of parameters). -### Writing New Monomorphic Matchers +### Writing New Monomorphic Matchers {#MonomorphicMatchers} A matcher of type `testing::Matcher` implements the matcher interface for `T` and does two things: it tests whether a value of type `T` matches the matcher, @@ -3666,11 +3666,11 @@ Expected: is divisible by 7 Tip: for convenience, `MatchAndExplain()` can take a `MatchResultListener*` instead of `std::ostream*`. -### Writing New Polymorphic Matchers +### Writing New Polymorphic Matchers {#PolymorphicMatchers} Unlike a monomorphic matcher, which can only be used to match a value of a particular type, a *polymorphic* matcher is one that can be used to match values -of multiple types. For example, `Eq(5)` is a polymorhpic matcher as it can be +of multiple types. For example, `Eq(5)` is a polymorphic matcher as it can be used to match an `int`, a `double`, a `float`, and so on. You should think of a polymorphic matcher as a *matcher factory* as opposed to a `testing::Matcher` - itself is not an actual matcher, but can be diff --git a/docs/reference/matchers.md b/docs/reference/matchers.md index 4c234e17..665feee9 100644 --- a/docs/reference/matchers.md +++ b/docs/reference/matchers.md @@ -1,5 +1,7 @@ # Matchers Reference + + A **matcher** matches a *single* argument. You can use it inside `ON_CALL()` or `EXPECT_CALL()`, or use it to validate a value directly using two macros: @@ -297,6 +299,13 @@ which must be a permanent callback. ## Defining Matchers +{: .callout .note} +Note: full details about defining new matchers are in the +[cookbook](../gmock_cook_book.md#NewMatchers). In particular, if `MATCHER` +macros are not sufficient, you can directly implement +[monomorphic](../gmock_cook_book.md#MonomorphicMatchers) or +[polymorphic](../gmock_cook_book.md#PolymorphicMatchers) matchers. + | Macro | Description | | :----------------------------------- | :------------------------------------ | | `MATCHER(IsEven, "") { return (arg % 2) == 0; }` | Defines a matcher `IsEven()` to match an even number. |