Closed countcb closed 1 year ago
deep.Equal does behave differently from reflect.DeepEqual when comparing functions.
The documentation of reflect.DeepEqual states for functions:
Func values are deeply equal if both are nil; otherwise they are not deeply equal.
Example Code:
func testFunc(i int) int { return i } func TestEqualForFunctions() { type TestStruct struct { Function func(int) int } t1 := TestStruct{ Function: testFunc, } t2 := TestStruct{ Function: testFunc, } fmt.Println("reflect", reflect.DeepEqual(t1, t2)) fmt.Println("deep", deep.Equal(t1, t2)) t1.Function = nil fmt.Println("reflect", reflect.DeepEqual(t1, t2)) fmt.Println("deep", deep.Equal(t1, t2)) t1.Function = nil t2.Function = nil fmt.Println("reflect", reflect.DeepEqual(t1, t2)) fmt.Println("deep", deep.Equal(t1, t2)) }
Output:
reflect false deep [] // should state that both functions are != nil reflect false deep [] // should state that function 1 is not nil but function 2 is nil reflect true deep []
If this gets added/changed then maybe it would be a good idea to add a field deep.CompareFunctions
deep.CompareFunctions
similar to deep.CompareUnexportedFields
Fixed in https://github.com/go-test/deep/pull/55. Will be released soon.
Released: https://github.com/go-test/deep/releases/tag/v1.0.9
deep.Equal does behave differently from reflect.DeepEqual when comparing functions.
The documentation of reflect.DeepEqual states for functions:
Example Code:
Output: