go-test / deep

Golang deep variable equality test that returns human-readable differences
MIT License
751 stars 54 forks source link

Embedded struct values not inspected #37

Closed tcoupland closed 5 years ago

tcoupland commented 5 years ago

Deep equals doesn't appear to check embedded values:

package main

import (
    "fmt"
    "github.com/go-test/deep"
)

type sub struct{
 subvar string
}

type top struct{
sub
}

func main() {

val1 := top{sub: sub{subvar: "x"}}
val2 := top{sub: sub{subvar: "y"}}

fmt.Println(deep.Equal(val1, val1)) // no diffs, fine
fmt.Println(deep.Equal(val1, val2)) // no diffs, not so fine
}
daniel-nichter commented 5 years ago

You need to enable CompareUnexportedFields: https://godoc.org/github.com/go-test/deep