Skip to content
This repository has been archived by the owner on May 2, 2020. It is now read-only.

Commit

Permalink
Added ShouldPanic
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerb committed May 21, 2016
1 parent 6c1a467 commit 0e2cbac
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
12 changes: 12 additions & 0 deletions is.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,18 @@ func (is *Is) Len(o interface{}, l int) {
}
}

// ShouldPanic expects the provided function to panic. If the function does
// not panic, this assertion fails.
func (is *Is) ShouldPanic(f func()) {
defer func() {
r := recover()
if r == nil {
fail(is, "expected function to panic")
}
}()
f()
}

// SetOutput changes the message output Writer from the default (os.Stdout).
// This may be useful if the application under test takes over the console, or
// if logging to a file is desired.
Expand Down
8 changes: 8 additions & 0 deletions is_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ func TestIs(t *testing.T) {
is.Equal((*testStruct)(nil), &testStruct{})
is.Equal(&testStruct{}, (*testStruct)(nil))
is.Equal((*testStruct)(nil), (*testStruct)(nil))

fail = func(is *Is, format string, args ...interface{}) {
fmt.Print(decorate(fmt.Sprintf(format, args...)))
t.FailNow()
}
is.ShouldPanic(func() {
panic("The sky is falling!")
})
}

func TestIsMsg(t *testing.T) {
Expand Down

0 comments on commit 0e2cbac

Please sign in to comment.