7 "github.com/onsi/gomega/format"
10 type PanicMatcher struct {
14 func (matcher *PanicMatcher) Match(actual interface{}) (success bool, err error) {
16 return false, fmt.Errorf("PanicMatcher expects a non-nil actual.")
19 actualType := reflect.TypeOf(actual)
20 if actualType.Kind() != reflect.Func {
21 return false, fmt.Errorf("PanicMatcher expects a function. Got:\n%s", format.Object(actual, 1))
23 if !(actualType.NumIn() == 0 && actualType.NumOut() == 0) {
24 return false, fmt.Errorf("PanicMatcher expects a function with no arguments and no return value. Got:\n%s", format.Object(actual, 1))
29 if e := recover(); e != nil {
35 reflect.ValueOf(actual).Call([]reflect.Value{})
40 func (matcher *PanicMatcher) FailureMessage(actual interface{}) (message string) {
41 return format.Message(actual, "to panic")
44 func (matcher *PanicMatcher) NegatedFailureMessage(actual interface{}) (message string) {
45 return format.Message(actual, fmt.Sprintf("not to panic, but panicked with\n%s", format.Object(matcher.object, 1)))