Recently I have been writing many tests for functions with multiple return values. I was hoping to write a single line assertion. Something like the following:
This won’t compile, the method signature for Equal takes interface{} parameters. Understandably the compiler can’t figure it out.
After checking the mailing list it turns out the compiler is smart enough to map multiple return values to function params when their types and order match. e.g:
12345678910
functestableFunc()(int,int,int){return5,6,7}funcanotherFunc(aint,bint,cint)int{returna+b+c}//valid because returned types match argumentsanotherFunc(testableFunc())
With this behavior in mind we can write a shim function to map multiple return values to a slice of values that the assert function can compare. Here is a 2 value shim: