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

Document the arguments number limit of 15 in documentation #4608

Open
PiotrNycz opened this issue Sep 2, 2024 · 3 comments
Open

Document the arguments number limit of 15 in documentation #4608

PiotrNycz opened this issue Sep 2, 2024 · 3 comments

Comments

@PiotrNycz
Copy link
Contributor

Does the feature exist in the most recent commit?

No

Why do we need this feature?

This is just for documentation. I recently spent some time of investigation why MOCK_METHOD stops compiling after adding new argument to function type. It occured that limit for arguments number is 15 which is nowhere documented (maybe it is but I cannot find it.

Describe the proposal.

Add information that MOCK_METHOD macro has limit when talking about number of arguments.
And that this limit current is 15.
This can be in form of FAQ and just short info in MOCK_METHOD doc.

For FAQ I'd propose to add this QA:

Q: I encounter this error .... while adding new argument to function mocked by MOCK_METHOD macro. What does it mean and how to work around this issue?

A:
You crossed the limit of 15 arguments in function mocked by MOCK_METHOD macro.
You can work around this limit by the following methods:

  1. The best is to refactor your code - 15 is quite the enough number as for function arguments...
  2. Other solution - if you have arguments that are irrelevant - always substituted by any matcher ::testing::_ - then your mocked function can just have subset of arguments:
    void func(int a1, ..., int a16) override { mocked_func(a1, ... , a15); }
    MOCK_METHOD(mocked_func, void, (int a1, .., int a15), ());
  3. OR - you can have MOCK_METHOD that takes std::tuple of its arguments:
    Ret func(T1 a1, ...., T19 a19) override { return mocked_func(std::tuple<T1, ..., T19>(a1, ..., a19)); }
    MOCK_METHOD(mocked_func, Ret, ((std::tuple<T1, ..., T19>)), ());
    And use FieldsAre to match this packed arguments - but here again - we have limit of 19 when using FieldsAre (as I can see in the code)

Is the feature specific to an operating system, compiler, or build system version?

No

@miacodehub
Copy link

Hi can i work on this issue?

@PiotrNycz
Copy link
Contributor Author

@miacodehub sure, it'd be great, if you are asking me

@miacodehub
Copy link

Awesome! I'll take it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants