Skip to content

Commit

Permalink
Better comments/naming in ExpectPanic()
Browse files Browse the repository at this point in the history
This changes the variable name from err to iface and updates the comment
to better address the use cases for this function.
  • Loading branch information
liquidgecka committed Jan 24, 2018
1 parent 561e6b2 commit 9b7d3b5
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions expect.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,10 @@ func (t *T) ExpectErrorMessagef(err error, msg string, spec string, args ...inte
}

// Expects the function passed in to panic. This will call f() and expect
// that an error matching err will be raised as a panic.
func (t *T) ExpectPanic(f func(), err interface{}, desc ...string) {
// that an interface{} instance will be raised matching iface. This will
// typically be a string, or an error interface and will be compared using
// the Equal() method.
func (t *T) ExpectPanic(f func(), iface interface{}, desc ...string) {
prefix := ""
if len(desc) > 0 {
prefix = strings.Join(desc, " ") + ": "
Expand All @@ -107,7 +109,7 @@ func (t *T) ExpectPanic(f func(), err interface{}, desc ...string) {
if i == nil {
t.Fatalf("%sFunction call did not panic as expected.", prefix)
}
t.Equal(i, err, "Raised value is not correct")
t.Equal(i, iface, "Raised value is not correct")
}()
f()
}

0 comments on commit 9b7d3b5

Please sign in to comment.