I'm trying to test a function that accepts a parameter of the type "error". The function should panic under certain situations and I'm trying to test scenarios.
However, when I try to use reflect.Call
on a nil
value (which can be passed into a function that accepts something of type "error"), it seems to result in a panic with the following message:
reflect: Call using zero Value argument
I have found the following posts but I am failing to integrate it into my function.
- https://groups.google.com/forum/#!topic/golang-nuts/apNcACpl_fI
- https://groups.google.com/forum/#!topic/golang-nuts/WOUft8EZQ1I
Relevant Go Playground: http://play.golang.org/p/cYQMQ6amPH
In the playground above, I would like the call to InvocationCausedPanic(PanicOnErr, nil)
to return false
, however, the above panic from reflect is causing a false positive.
Are there any modifications I can make to the InvocationCausedPanic
or the invoke
functions to make this work (while retaining its ability to test other functions that cannot accept nil
as an argument - a function that accepts a string for instance)?
Perhaps the issue is in how the function is called?
I've tred things like InvocationCausedPanic(PanicOnErr, new(error))
or InvocationCausedPanic(PanicOnErr, error(nil))
to no avail.
Thanks for any advice.