testify icon indicating copy to clipboard operation
testify copied to clipboard

Nil actual type made AnythingOfType matcher panic

Open brackendawson opened this issue 2 years ago • 2 comments

Summary

Passing an actual value of type nil via a Mock into the argument matcher for AnythingOfType in a Mock causes a panic.

Changes

  • Handle nil types up front when checking actual types against mock.AnythingOfType before calling any methods on the reflect.Type, which will be nil if the value was a nil interface.
  • Change formatting of the expected type from Name() to String() because Name is emptystring for pointer and some other types.

Motivation

Someone may expect their mock to be called with a nil interface, we should not panic in this case.

Related issues

Closes #1209

brackendawson avatar Jun 29 '22 17:06 brackendawson

I ran into this issue as well. Is there any activity on this PR fixing this issue?

greenstatic avatar Feb 10 '23 06:02 greenstatic

I ran into this issue as well. Is there any activity on this PR fixing this issue?

I believe the state is that fixing this well would be a breaking change, so not until Testify 2.0, and I think we should do that. But the comments above object to something which is not a regression, so I think this change can be merged into 1.x.

brackendawson avatar Feb 10 '23 18:02 brackendawson