@@ -3,36 +3,63 @@ package must
33import (
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+
1219func 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
1831func 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
3253func 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
3865type 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