uber-go / mock

GoMock is a mocking framework for the Go programming language.
Apache License 2.0
1.81k stars 103 forks source link

Add call stack to unexpected mock call #145

Open feldentm-SAP opened 5 months ago

feldentm-SAP commented 5 months ago

Make identification of unexpected calls easier.

Note, this is a copy of https://github.com/uber-go/mock/pull/110 which is miraculously permanently closed.

JacobOaks commented 5 months ago

Hey @feldentm-SAP, sorry for the confusion on the other PR. Not sure why github insists on it remaining closed.

I think this could be a helpful addition. I'm not too worried about performance implications of collecting stack traces since this is for testing code. One thing we may want to do is use https://pkg.go.dev/runtime#Callers instead and skip the first couple of frames since these are irrelevant and point to internal gomock code.

@tchung1118 what do you think?

tchung1118 commented 5 months ago

I agree with @JacobOaks that skipping internal callers could be better.

feldentm-SAP commented 5 months ago

@JacobOaks My understanding is that the code is executed for failed tests, only. Hence, performance considerations are almost irrelevant. I also agree that skipping callers would improve the output, but the benefit over the current proposal does not justify spending the required time as I no longer understand the change. Hence, I'd propose that this is either merged or one of you takes an educated guess on how many callers need to be skipped and if this can be determined statically. Getting this wrong by one reduces the benefit of the change to almost zero.