@@ -2174,7 +2174,7 @@ own precedence order distinct from the `ON_CALL` precedence order.
21742174### Using Functions/Methods/Functors/Lambdas as Actions {#FunctionsAsActions}
21752175
21762176If the built-in actions don't suit you, you can use an existing callable
2177- (function, `std::function`, method, functor, lambda as an action.
2177+ (function, `std::function`, method, functor, lambda) as an action.
21782178
21792179<!-- GOOGLETEST_CM0024 DO NOT DELETE -->
21802180
@@ -2203,6 +2203,7 @@ class Helper {
22032203 .WillRepeatedly(Invoke(NewPermanentCallback(Sum3, 1)));
22042204 EXPECT_CALL(foo, ComplexJob(_))
22052205 .WillOnce(Invoke(&helper, &Helper::ComplexJob))
2206+ .WillOnce([] { return true; })
22062207 .WillRepeatedly([](int x) { return x > 0; });
22072208
22082209 foo.Sum(5, 6); // Invokes CalculateSum(5, 6).
@@ -2212,11 +2213,11 @@ class Helper {
22122213```
22132214
22142215The only requirement is that the type of the function, etc must be *compatible*
2215- with the signature of the mock function, meaning that the latter's arguments can
2216- be implicitly converted to the corresponding arguments of the former, and the
2217- former's return type can be implicitly converted to that of the latter. So, you
2218- can invoke something whose type is *not* exactly the same as the mock function,
2219- as long as it's safe to do so - nice, huh?
2216+ with the signature of the mock function, meaning that the latter's arguments (if
2217+ it takes any) can be implicitly converted to the corresponding arguments of the
2218+ former, and the former 's return type can be implicitly converted to that of the
2219+ latter. So, you can invoke something whose type is *not* exactly the same as the
2220+ mock function, as long as it's safe to do so - nice, huh?
22202221
22212222**`Note:`{.escaped}**
22222223
@@ -2267,19 +2268,20 @@ TEST_F(FooTest, Test) {
22672268
22682269### Invoking a Function/Method/Functor/Lambda/Callback Without Arguments
22692270
2270- `Invoke()` is very useful for doing actions that are more complex. It passes the
2271- mock function's arguments to the function, etc being invoked such that the
2272- callee has the full context of the call to work with. If the invoked function is
2273- not interested in some or all of the arguments, it can simply ignore them.
2271+ `Invoke()` passes the mock function's arguments to the function, etc being
2272+ invoked such that the callee has the full context of the call to work with. If
2273+ the invoked function is not interested in some or all of the arguments, it can
2274+ simply ignore them.
22742275
22752276Yet, a common pattern is that a test author wants to invoke a function without
2276- the arguments of the mock function. `Invoke()` allows her to do that using a
2277- wrapper function that throws away the arguments before invoking an underlining
2278- nullary function. Needless to say, this can be tedious and obscures the intent
2279- of the test.
2277+ the arguments of the mock function. She could do that using a wrapper function
2278+ that throws away the arguments before invoking an underlining nullary function.
2279+ Needless to say, this can be tedious and obscures the intent of the test.
22802280
2281- `InvokeWithoutArgs()` solves this problem. It's like `Invoke()` except that it
2282- doesn't pass the mock function's arguments to the callee. Here's an example:
2281+ There are two solutions to this problem. First, you can pass any callable of
2282+ zero args as an action. Alternatively, use `InvokeWithoutArgs()`, which is like
2283+ `Invoke()` except that it doesn't pass the mock function's arguments to the
2284+ callee. Here's an example of each:
22832285
22842286```cpp
22852287using ::testing::_;
@@ -2296,7 +2298,7 @@ bool Job2(int n, char c) { ... }
22962298...
22972299 MockFoo foo;
22982300 EXPECT_CALL(foo, ComplexJob(_))
2299- .WillOnce(InvokeWithoutArgs( Job1))
2301+ .WillOnce([] { Job1(); });
23002302 .WillOnce(InvokeWithoutArgs(NewPermanentCallback(Job2, 5, 'a')));
23012303
23022304 foo.ComplexJob(10); // Invokes Job1().
0 commit comments