forked from spacemeshos/go-spacemesh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
assert.go
68 lines (59 loc) · 1.27 KB
/
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
59
60
61
62
63
64
65
66
67
68
// Package assert provides basic assert functions for tests
package assert
import (
"errors"
"fmt"
"testing"
)
// basic assertion support
// Nil verifies that obj is nil.
func Nil(t *testing.T, obj interface{}, msgs ...string) {
t.Helper()
if obj != nil {
t.Fatal(msgs, "error:", errors.New("expected object to be nil"))
}
}
// NotNil verifies that obj is not nil.
func NotNil(t *testing.T, obj interface{}, msgs ...string) {
t.Helper()
if obj == nil {
t.Fatal(msgs, "epxected a non-nil object")
}
}
// True verifies that v is true.
func True(t *testing.T, v bool, msgs ...string) {
t.Helper()
if !v {
t.Fatal(msgs)
}
}
// Equal verifies that a is equal to b.
func Equal(t *testing.T, a interface{}, b interface{}, msg string) {
t.Helper()
if a == b {
return
}
if len(msg) == 0 {
msg = fmt.Sprintf("%v != %v", a, b)
}
t.Fatal(msg)
}
// False verifies that v is false.
func False(t *testing.T, v bool, msgs ...string) {
t.Helper()
True(t, !v, msgs...)
}
// NoErr verifies that err is nil.
func NoErr(t *testing.T, err error, msgs ...string) {
t.Helper()
if err != nil {
t.Fatal(msgs, "error:", err)
}
}
// Err verifies that err is not nil.
func Err(t *testing.T, err error, msgs ...string) {
t.Helper()
if err == nil {
t.Fatal(msgs, "error:", err)
}
}