From beb552fb47e9e8a6ddab20526663c2dddd601ec6 Mon Sep 17 00:00:00 2001 From: Dino Radakovic Date: Tue, 3 Oct 2023 11:41:17 -0700 Subject: [PATCH] gmock_cook_book: Document `DoAll`'s return type requirement The requirement is vaguely documented by "Only the return value of the last action in the sequence will be used.". However, this can be misleading, as users could potentially expect default-constructed values to be returned in absence of a matching return type. PiperOrigin-RevId: 570450839 Change-Id: Ibd98a6e6b2aaf2a8cfc15ed6aeab442526eab98e --- docs/gmock_cook_book.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/gmock_cook_book.md b/docs/gmock_cook_book.md index da10918c..5e9b6647 100644 --- a/docs/gmock_cook_book.md +++ b/docs/gmock_cook_book.md @@ -1927,6 +1927,12 @@ class MockFoo : public Foo { action_n)); ``` +The return value of the last action **must** match the return type of the mocked +method. In the example above, `action_n` could be `Return(true)`, or a lambda +that returns a `bool`, but not `SaveArg`, which returns `void`. Otherwise the +signature of `DoAll` would not match the signature expected by `WillOnce`, which +is the signature of the mocked method, and it wouldn't compile. + ### Verifying Complex Arguments {#SaveArgVerify} If you want to verify that a method is called with a particular argument but the