diff --git a/deep.go b/deep.go index 254ee7d..3e6636c 100644 --- a/deep.go +++ b/deep.go @@ -27,7 +27,9 @@ var ( LogErrors = false // CompareUnexportedFields causes unexported struct fields, like s in - // T{s int}, to be compared when true. + // T{s int}, to be compared when true. This does not work for comparing + // error or Time types on unexported fields because methods on unexported + // fields cannot be called. CompareUnexportedFields = false // NilSlicesAreEmpty causes a nil slice to be equal to an empty slice. diff --git a/deep_test.go b/deep_test.go index d2ae7ce..98fba1f 100644 --- a/deep_test.go +++ b/deep_test.go @@ -1408,7 +1408,9 @@ func TestErrorUnexported(t *testing.T) { type foo struct { bar error } + defaultCompareUnexportedFields := deep.CompareUnexportedFields deep.CompareUnexportedFields = true + defer func() { deep.CompareUnexportedFields = defaultCompareUnexportedFields }() e1 := foo{bar: fmt.Errorf("error")} e2 := foo{bar: fmt.Errorf("error")} deep.Equal(e1, e2)