https://github.com/go-test/deep
Golang deep variable equality test that returns human-readable differences
https://github.com/go-test/deep
deep-equals golang golang-testing variable-equality
Last synced: 8 months ago
JSON representation
Golang deep variable equality test that returns human-readable differences
- Host: GitHub
- URL: https://github.com/go-test/deep
- Owner: go-test
- License: mit
- Created: 2017-02-26T18:00:00.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2025-05-02T18:30:25.000Z (8 months ago)
- Last Synced: 2025-05-14T05:04:37.086Z (8 months ago)
- Topics: deep-equals, golang, golang-testing, variable-equality
- Language: Go
- Homepage:
- Size: 84 KB
- Stars: 770
- Watchers: 7
- Forks: 56
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- License: LICENSE
- Security: SECURITY.md
Awesome Lists containing this project
README
# Deep Variable Equality for Humans
[](https://goreportcard.com/report/github.com/go-test/deep)
[](https://coveralls.io/github/go-test/deep?branch=master)
[](https://pkg.go.dev/github.com/go-test/deep)
This package provides a single function: `deep.Equal`. It's like [reflect.DeepEqual](http://golang.org/pkg/reflect/#DeepEqual) but much friendlier to humans (or any sentient being) for two reason:
* `deep.Equal` returns a list of differences
* `deep.Equal` does not compare unexported fields (by default)
`reflect.DeepEqual` is good (like all things Golang!), but it's a game of [Hunt the Wumpus](https://en.wikipedia.org/wiki/Hunt_the_Wumpus). For large maps, slices, and structs, finding the difference is difficult.
`deep.Equal` doesn't play games with you, it lists the differences:
```go
package main_test
import (
"testing"
"github.com/go-test/deep"
)
type T struct {
Name string
Numbers []float64
}
func TestDeepEqual(t *testing.T) {
// Can you spot the difference?
t1 := T{
Name: "Isabella",
Numbers: []float64{1.13459, 2.29343, 3.010100010},
}
t2 := T{
Name: "Isabella",
Numbers: []float64{1.13459, 2.29843, 3.010100010},
}
if diff := deep.Equal(t1, t2); diff != nil {
t.Error(diff)
}
}
```
```
$ go test
--- FAIL: TestDeepEqual (0.00s)
main_test.go:25: [Numbers.slice[1]: 2.29343 != 2.29843]
```
The difference is in `Numbers.slice[1]`: the two values aren't equal using Go `==`.