Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Conversation

bergotorino
Copy link

The gomock's Call interface allows for setting a value to a specified
argument, making it convinient to work with functions that return data
through pointer arguments. However, this is not possible for variadic
functions, the error is:

SetArg(1, ...) called for a method with 1 args...

The root cause is that the variadic argument in a form of
...interface{} is threated as single value instead of being treated as
slice.

This commit changes this situation by making sure that the variadic
arguments that are a slice are treated as slices. As a consequence it is
now possible to set argument value for variadic functions.

See: #174

The gomock's Call interface allows for setting a value to a specified
argument, making it convinient to work with functions that return data
through pointer arguments. However, this is not possible for variadic
functions, the error is:

  SetArg(1, ...) called for a method with 1 args...

The root cause is that the variadic argument in a form of
...interface{} is threated as single value instead of being treated as
slice.

This commit changes this situation by making sure that the variadic
arguments that are a slice are treated as slices. As a consequence it is
now possible to set argument value for variadic functions.

See: golang#174
@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

1 similar comment
@google-cla
Copy link

google-cla bot commented Oct 15, 2021

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@bergotorino
Copy link
Author

@googlebot I signed it!

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

1 similar comment
@google-cla
Copy link

google-cla bot commented Oct 15, 2021

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

// TODO: This will break on variadic methods.
// We will need to check those at invocation time.
if n < 0 || n >= mt.NumIn() {
if (n < 0 || n >= mt.NumIn()) && !mt.IsVariadic() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add some tests for this. You can either do a traditional tests or a sample code generation like others in the mockgen/internal/test dir.

Copy link
Member

@codyoss codyoss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add tests :)

@bergotorino
Copy link
Author

Sure, will do. Thanks for review and sorry for missing your comments on time

@mvrahden
Copy link

@bergotorino are you still planning to do this?

@codyoss
Copy link
Member

codyoss commented Jul 8, 2022

Closing due to lack of response.

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

Successfully merging this pull request may close these issues.

4 participants