6 . "github.com/onsi/ginkgo"
7 . "github.com/onsi/gomega"
8 . "github.com/onsi/gomega/matchers"
11 func Erroring() error {
12 return errors.New("bam")
15 func NotErroring() error {
21 func Invalid() *AnyType {
25 var _ = Describe("Succeed", func() {
26 It("should succeed if the function succeeds", func() {
27 Ω(NotErroring()).Should(Succeed())
30 It("should succeed (in the negated) if the function errored", func() {
31 Ω(Erroring()).ShouldNot(Succeed())
34 It("should not if passed a non-error", func() {
35 success, err := (&SucceedMatcher{}).Match(Invalid())
36 Ω(success).Should(BeFalse())
37 Ω(err).Should(MatchError("Expected an error-type. Got:\n <*matchers_test.AnyType | 0x0>: nil"))
40 It("doesn't support non-error type", func() {
41 success, err := (&SucceedMatcher{}).Match(AnyType{})
42 Ω(success).Should(BeFalse())
43 Ω(err).Should(MatchError("Expected an error-type. Got:\n <matchers_test.AnyType>: {}"))
46 It("doesn't support non-error pointer type", func() {
47 success, err := (&SucceedMatcher{}).Match(&AnyType{})
48 Ω(success).Should(BeFalse())
49 Ω(err).Should(MatchError(MatchRegexp(`Expected an error-type. Got:\n <*matchers_test.AnyType | 0x[[:xdigit:]]+>: {}`)))
52 It("should not succeed with pointer types that conform to error interface", func() {
53 err := &CustomErr{"ohai"}
54 Ω(err).ShouldNot(Succeed())
57 It("should succeed with nil pointers to types that conform to error interface", func() {
58 var err *CustomErr = nil
59 Ω(err).Should(Succeed())