Skip to content
This repository was archived by the owner on Sep 25, 2023. It is now read-only.

Commit 3cf8585

Browse files
authored
Remove testify dependency (#13)
1 parent c2d6d6a commit 3cf8585

File tree

3 files changed

+42
-25
lines changed

3 files changed

+42
-25
lines changed

go.mod

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
module github.com/ridge/must
22

33
go 1.14
4-
5-
require github.com/stretchr/testify v1.5.1

go.sum

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +0,0 @@
1-
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
2-
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3-
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
4-
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
5-
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
6-
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
7-
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
8-
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
9-
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
10-
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
11-
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

must_test.go

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,63 @@ package must
33
import (
44
"errors"
55
"os"
6+
"reflect"
67
"testing"
78
"time"
8-
9-
"github.com/stretchr/testify/assert"
109
)
1110

11+
func capturePanic(f func()) (ret interface{}) {
12+
defer func() {
13+
ret = recover()
14+
}()
15+
f()
16+
return nil
17+
}
18+
1219
func TestOK(t *testing.T) {
1320
e := errors.New("")
14-
assert.PanicsWithValue(t, e, func() { OK(e) })
15-
assert.NotPanics(t, func() { OK(nil) })
21+
22+
if capturePanic(func() { OK(e) }) != e {
23+
t.Errorf("OK(non-nil-error) did not panic with the passed error")
24+
}
25+
26+
if capturePanic(func() { OK(nil) }) != nil {
27+
t.Errorf("OK(nil) panicked")
28+
}
1629
}
1730

1831
func TestDo(t *testing.T) {
1932
e := errors.New("")
20-
assert.PanicsWithValue(t, e, func() {
33+
34+
ret := capturePanic(func() {
2135
Do(func() error {
2236
return e
2337
})
2438
})
25-
assert.NotPanics(t, func() {
39+
if ret != e {
40+
t.Errorf("Do({return e}) did not panic with the returned error")
41+
}
42+
43+
ret = capturePanic(func() {
2644
Do(func() error {
2745
return nil
2846
})
2947
})
48+
if ret != nil {
49+
t.Errorf("Do({return nil}) panicked")
50+
}
3051
}
3152

3253
func TestInt(t *testing.T) {
3354
e := errors.New("")
34-
assert.PanicsWithValue(t, e, func() { Int(10, e) })
35-
assert.Equal(t, 10, Int(10, nil))
55+
56+
if capturePanic(func() { Int(10, e) }) != e {
57+
t.Errorf("Int(10, non-nil-error) did not panic with the passed error")
58+
}
59+
60+
if Int(10, nil) != 10 {
61+
t.Errorf("Int(10, nil) did not return 10")
62+
}
3663
}
3764

3865
type fakeFileInfo struct {
@@ -66,8 +93,11 @@ func TestOSFileInfos(t *testing.T) {
6693
e := errors.New("")
6794
fis := []os.FileInfo{fakeFileInfo{}}
6895

69-
assert.PanicsWithValue(t, e, func() {
70-
OSFileInfos(fis, e)
71-
})
72-
assert.Equal(t, fis, OSFileInfos(fis, nil))
96+
if capturePanic(func() { OSFileInfos(fis, e) }) != e {
97+
t.Errorf("OSFileInfos(fis, non-nil-error) did not panic with the passed error")
98+
}
99+
100+
if !reflect.DeepEqual(OSFileInfos(fis, nil), fis) {
101+
t.Errorf("OSFileInfos(fis, nil) did not return fis")
102+
}
73103
}

0 commit comments

Comments
 (0)