func checkStringType(actual, expected interface{}, skip int) (string, string, error) { a, ok := actual.(string) if !ok { return "", "", ge.Expect("actual value is a string.", skip+1) } e, ok := expected.(string) if !ok { return "", "", ge.Expect("expected value is a string.", skip+1) } return a, e, nil }
// Panic checks if a function panics. func Panic(actual, expected interface{}, name string, skip int) (ret error) { f, ok := actual.(func()) if !ok { ret = errors.Expect("the argument of Panic has to be a function of type func().", skip) } defer func() { if err := recover(); err == nil { ret = errors.Expect("panicking", skip+1) } }() f() return nil }
func TestExpectTo(t *testing.T) { m, expect := mockExpect() expect(nil).To(func(actual, expected interface{}, name string, skip int) error { return errors.Expect("x", skip+1) }, nil) if m.err == nil { t.Error("Expect error but got nil.") } if m.err.Error() != "expect_test.go:17: expect x." { t.Errorf("Got error message %v.", m.err.Error()) } }