forked from progrium/darwinkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassert.go
58 lines (47 loc) · 839 Bytes
/
assert.go
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package assert
import (
"fmt"
"reflect"
"testing"
"github.com/go-test/deep"
)
func Equal(t *testing.T, expected, actual any) {
t.Helper()
if !reflect.DeepEqual(expected, actual) {
t.Fatal(fmt.Sprintf("should be equal but got: %s", deep.Equal(expected, actual)))
}
}
func NotNil(t *testing.T, v any) {
t.Helper()
if v == nil {
t.Fatal("should not be nil")
}
}
func False(t *testing.T, v bool) {
t.Helper()
if v {
t.Fatal("should be false")
}
}
func True(t *testing.T, v bool) {
t.Helper()
if !v {
t.Fatal("should be true")
}
}
func Panics(t *testing.T, f func()) {
t.Helper()
if !didPanic(f) {
t.Fatal(fmt.Sprintf("func %p should panic", f))
}
}
func didPanic(f func()) (didPanic bool) {
didPanic = true
defer func() {
recover()
}()
// call the target function
f()
didPanic = false
return
}