Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assume Times(1) by default for a return_once expectation #523

Open
mic006 opened this issue Nov 20, 2023 · 1 comment
Open

Assume Times(1) by default for a return_once expectation #523

mic006 opened this issue Nov 20, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@mic006
Copy link

mic006 commented Nov 20, 2023

When creating an expectation with return_once(), I was expecting that Times(1) was the default, but it is not.
So creating two expectations with return_once() (and no Times constraint) fails due to the first expectation being called twice.

BTW, Gmock does this: WillOnce implies Times(1) by default.

@asomers
Copy link
Owner

asomers commented Nov 22, 2023

When creating an expectation with return_once(), I was expecting that Times(1) was the default, but it is not. So creating two expectations with return_once() (and no Times constraint) fails due to the first expectation being called twice.

Yes, I've sometimes thought that I should change that. This impact would be slight; just a different panic message mostly. But I didn't think about the user who sets multiple expectations, expecting them to be called in sequence, without adding a .times constraint. That's the best argument I've heard for changing it.

BTW, Gmock does this: WillOnce implies Times(1) by default.

That's because in C++ non-copyable types are very rare and return by move is considered exotic. So Gmock has no need for a .return_once method like Mockall does. With Mockall, it's essential because non-copy types are common. So the "once" doesn't really mean the exact same thing in GMock.

@asomers asomers added the enhancement New feature or request label Nov 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants