File: README.md

package info (click to toggle)
golang-github-alecthomas-assert 0.0~git20170929.405dbfe-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 176 kB
  • sloc: makefile: 2
file content (39 lines) | stat: -rw-r--r-- 1,341 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# Go assertion library (fork of [stretchr/testify/require](https://github.com/stretchr/testify/tree/master/require))

This is a fork of stretchr's assertion library that does two things:

1. It makes spotting differences in equality much easier. It uses [repr](https://github.com/alecthomas/repr) and
    [diffmatchpatch](https://github.com/sergi/go-diff/diffmatchpatch) to display structural differences
    in colour.
2. Aborts tests on first assertion failure (the same behaviour as `stretchr/testify/require`).

## Example

Given the following test:

```go
type Person struct {
  Name string
  Age  int
}

// Use github.com/alecthomas/assert
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)
}

// Use github.com/stretchr/testify/require
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.

<img style="overflow-x: auto;" src="./_example/diff.png">