forked from cornfeedhobo/pflag
-
Notifications
You must be signed in to change notification settings - Fork 1
/
util_test.go
85 lines (72 loc) · 1.84 KB
/
util_test.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package zflag_test
import (
"fmt"
"reflect"
"testing"
)
func repeatFlag(flag string, values ...string) (res []string) {
res = make([]string, 0, len(values))
for _, val := range values {
res = append(res, fmt.Sprintf("%s=%s", flag, val))
}
return
}
func assertDeepEqual(t *testing.T, expected, actual interface{}) {
t.Helper()
if !reflect.DeepEqual(expected, actual) {
t.Errorf("expected %[1]v with type %[1]T but got %[2]v with type %[2]T", expected, actual)
}
}
func assertEqual(t *testing.T, expected, actual interface{}) {
t.Helper()
assertEqualf(t, expected, actual, "expected %[1]v with type %[1]T but got %[2]v with type %[2]T", expected, actual)
}
func assertEqualf(t *testing.T, expected, actual interface{}, msg string, fmt ...interface{}) {
t.Helper()
if expected != actual {
t.Errorf(msg, fmt...)
}
}
func assertErr(t *testing.T, actual error) {
t.Helper()
if actual == nil {
t.Fatalf("expected an error, got: %s", actual)
}
}
func assertNoErr(t *testing.T, actual error) {
t.Helper()
if actual != nil {
t.Fatalf("expected no error, got: %s", actual)
}
}
func assertNoPanic(t *testing.T) func() {
return func() {
t.Helper()
if v := recover(); v != nil {
t.Fatal("expected no panic, got:", v)
}
}
}
func assertPanic(t *testing.T) func() {
return func() {
t.Helper()
if v := recover(); v == nil {
t.Fatal("expected a panic, got:", v)
}
}
}
func assertErrMsg(t *testing.T, expectedErrMsg string, err error) {
t.Helper()
assertErr(t, err)
if err.Error() != expectedErrMsg {
t.Fatalf("expected error to equal %q, but was: %s", expectedErrMsg, err)
}
}
func assertNotNilf(t *testing.T, value interface{}, msg string, fmt ...interface{}) {
t.Helper()
if value == nil {
t.Fatalf(msg, fmt...)
}
}