This is a fork of stretchr's assertion library that does two things:
- It makes spotting differences in equality much easier. It uses repr and
diffmatchpatch to display structural differences
in colour.
- Aborts tests on first assertion failure (the same behaviour as
stretchr/testify/require
).
Example
Given the following test:
type Person struct {
Name string
Age int
}
func TestDiff(t *testing.T) {
expected := []*Person{{"Alec", 20}, {"Bob", 21}, {"Sally", 22}}
actual := []*Person{{"Alex", 20}, {"Bob", 22}, {"Sally", 22}}
assert.Equal(t, expected, actual)
}
func TestTestifyDiff(t *testing.T) {
expected := []*Person{{"Alec", 20}, {"Bob", 21}, {"Sally", 22}}
actual := []*Person{{"Alex", 20}, {"Bob", 22}, {"Sally", 22}}
require.Equal(t, expected, actual)
}
The following output illustrates the problems this solves. Firstly, it shows
nested structures correctly, and secondly it highlights the differences between
actual and expected text.
![](https://github.com/alecthomas/assert/raw/HEAD/./_example/diff.png)