mock icon indicating copy to clipboard operation
mock copied to clipboard

Add call stack to unexpected mock call

Open feldentm-SAP opened this issue 2 years ago • 3 comments

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.

feldentm-SAP avatar Jan 29 '24 12:01 feldentm-SAP

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?

JacobOaks avatar Jan 29 '24 15:01 JacobOaks

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

tchung1118 avatar Jan 29 '24 16:01 tchung1118

@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.

feldentm-SAP avatar Jan 30 '24 07:01 feldentm-SAP