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

Commit

Permalink
Remove testify dependency (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
misha-ridge authored Jan 17, 2022
1 parent c2d6d6a commit 3cf8585
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 25 deletions.
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
module github.com/ridge/must

go 1.14

require github.com/stretchr/testify v1.5.1
11 changes: 0 additions & 11 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,11 +0,0 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
54 changes: 42 additions & 12 deletions must_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,63 @@ package must
import (
"errors"
"os"
"reflect"
"testing"
"time"

"github.com/stretchr/testify/assert"
)

func capturePanic(f func()) (ret interface{}) {
defer func() {
ret = recover()
}()
f()
return nil
}

func TestOK(t *testing.T) {
e := errors.New("")
assert.PanicsWithValue(t, e, func() { OK(e) })
assert.NotPanics(t, func() { OK(nil) })

if capturePanic(func() { OK(e) }) != e {
t.Errorf("OK(non-nil-error) did not panic with the passed error")
}

if capturePanic(func() { OK(nil) }) != nil {
t.Errorf("OK(nil) panicked")
}
}

func TestDo(t *testing.T) {
e := errors.New("")
assert.PanicsWithValue(t, e, func() {

ret := capturePanic(func() {
Do(func() error {
return e
})
})
assert.NotPanics(t, func() {
if ret != e {
t.Errorf("Do({return e}) did not panic with the returned error")
}

ret = capturePanic(func() {
Do(func() error {
return nil
})
})
if ret != nil {
t.Errorf("Do({return nil}) panicked")
}
}

func TestInt(t *testing.T) {
e := errors.New("")
assert.PanicsWithValue(t, e, func() { Int(10, e) })
assert.Equal(t, 10, Int(10, nil))

if capturePanic(func() { Int(10, e) }) != e {
t.Errorf("Int(10, non-nil-error) did not panic with the passed error")
}

if Int(10, nil) != 10 {
t.Errorf("Int(10, nil) did not return 10")
}
}

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

assert.PanicsWithValue(t, e, func() {
OSFileInfos(fis, e)
})
assert.Equal(t, fis, OSFileInfos(fis, nil))
if capturePanic(func() { OSFileInfos(fis, e) }) != e {
t.Errorf("OSFileInfos(fis, non-nil-error) did not panic with the passed error")
}

if !reflect.DeepEqual(OSFileInfos(fis, nil), fis) {
t.Errorf("OSFileInfos(fis, nil) did not return fis")
}
}

0 comments on commit 3cf8585

Please sign in to comment.