forked from cerc-io/ipld-eth-server
Update dependencies
- uses newer version of go-ethereum required for go1.11
This commit is contained in:
+13
-6
@@ -9,37 +9,42 @@ import (
|
||||
|
||||
type Assertion struct {
|
||||
actualInput interface{}
|
||||
fail types.GomegaFailHandler
|
||||
failWrapper *types.GomegaFailWrapper
|
||||
offset int
|
||||
extra []interface{}
|
||||
}
|
||||
|
||||
func New(actualInput interface{}, fail types.GomegaFailHandler, offset int, extra ...interface{}) *Assertion {
|
||||
func New(actualInput interface{}, failWrapper *types.GomegaFailWrapper, offset int, extra ...interface{}) *Assertion {
|
||||
return &Assertion{
|
||||
actualInput: actualInput,
|
||||
fail: fail,
|
||||
failWrapper: failWrapper,
|
||||
offset: offset,
|
||||
extra: extra,
|
||||
}
|
||||
}
|
||||
|
||||
func (assertion *Assertion) Should(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool {
|
||||
assertion.failWrapper.TWithHelper.Helper()
|
||||
return assertion.vetExtras(optionalDescription...) && assertion.match(matcher, true, optionalDescription...)
|
||||
}
|
||||
|
||||
func (assertion *Assertion) ShouldNot(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool {
|
||||
assertion.failWrapper.TWithHelper.Helper()
|
||||
return assertion.vetExtras(optionalDescription...) && assertion.match(matcher, false, optionalDescription...)
|
||||
}
|
||||
|
||||
func (assertion *Assertion) To(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool {
|
||||
assertion.failWrapper.TWithHelper.Helper()
|
||||
return assertion.vetExtras(optionalDescription...) && assertion.match(matcher, true, optionalDescription...)
|
||||
}
|
||||
|
||||
func (assertion *Assertion) ToNot(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool {
|
||||
assertion.failWrapper.TWithHelper.Helper()
|
||||
return assertion.vetExtras(optionalDescription...) && assertion.match(matcher, false, optionalDescription...)
|
||||
}
|
||||
|
||||
func (assertion *Assertion) NotTo(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool {
|
||||
assertion.failWrapper.TWithHelper.Helper()
|
||||
return assertion.vetExtras(optionalDescription...) && assertion.match(matcher, false, optionalDescription...)
|
||||
}
|
||||
|
||||
@@ -55,8 +60,9 @@ func (assertion *Assertion) buildDescription(optionalDescription ...interface{})
|
||||
func (assertion *Assertion) match(matcher types.GomegaMatcher, desiredMatch bool, optionalDescription ...interface{}) bool {
|
||||
matches, err := matcher.Match(assertion.actualInput)
|
||||
description := assertion.buildDescription(optionalDescription...)
|
||||
assertion.failWrapper.TWithHelper.Helper()
|
||||
if err != nil {
|
||||
assertion.fail(description+err.Error(), 2+assertion.offset)
|
||||
assertion.failWrapper.Fail(description+err.Error(), 2+assertion.offset)
|
||||
return false
|
||||
}
|
||||
if matches != desiredMatch {
|
||||
@@ -66,7 +72,7 @@ func (assertion *Assertion) match(matcher types.GomegaMatcher, desiredMatch bool
|
||||
} else {
|
||||
message = matcher.NegatedFailureMessage(assertion.actualInput)
|
||||
}
|
||||
assertion.fail(description+message, 2+assertion.offset)
|
||||
assertion.failWrapper.Fail(description+message, 2+assertion.offset)
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -80,7 +86,8 @@ func (assertion *Assertion) vetExtras(optionalDescription ...interface{}) bool {
|
||||
}
|
||||
|
||||
description := assertion.buildDescription(optionalDescription...)
|
||||
assertion.fail(description+message, 2+assertion.offset)
|
||||
assertion.failWrapper.TWithHelper.Helper()
|
||||
assertion.failWrapper.Fail(description+message, 2+assertion.offset)
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
+60
-54
@@ -3,10 +3,13 @@ package assertion_test
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/onsi/gomega/internal/testingtsupport"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
. "github.com/onsi/gomega/internal/assertion"
|
||||
"github.com/onsi/gomega/internal/fakematcher"
|
||||
"github.com/onsi/gomega/types"
|
||||
)
|
||||
|
||||
var _ = Describe("Assertion", func() {
|
||||
@@ -19,45 +22,48 @@ var _ = Describe("Assertion", func() {
|
||||
|
||||
input := "The thing I'm testing"
|
||||
|
||||
var fakeFailHandler = func(message string, callerSkip ...int) {
|
||||
failureMessage = message
|
||||
if len(callerSkip) == 1 {
|
||||
failureCallerSkip = callerSkip[0]
|
||||
}
|
||||
var fakeFailWrapper = &types.GomegaFailWrapper{
|
||||
Fail: func(message string, callerSkip ...int) {
|
||||
failureMessage = message
|
||||
if len(callerSkip) == 1 {
|
||||
failureCallerSkip = callerSkip[0]
|
||||
}
|
||||
},
|
||||
TWithHelper: testingtsupport.EmptyTWithHelper{},
|
||||
}
|
||||
|
||||
BeforeEach(func() {
|
||||
matcher = &fakematcher.FakeMatcher{}
|
||||
failureMessage = ""
|
||||
failureCallerSkip = 0
|
||||
a = New(input, fakeFailHandler, 1)
|
||||
a = New(input, fakeFailWrapper, 1)
|
||||
})
|
||||
|
||||
Context("when called", func() {
|
||||
It("should pass the provided input value to the matcher", func() {
|
||||
a.Should(matcher)
|
||||
|
||||
Ω(matcher.ReceivedActual).Should(Equal(input))
|
||||
Expect(matcher.ReceivedActual).Should(Equal(input))
|
||||
matcher.ReceivedActual = ""
|
||||
|
||||
a.ShouldNot(matcher)
|
||||
|
||||
Ω(matcher.ReceivedActual).Should(Equal(input))
|
||||
Expect(matcher.ReceivedActual).Should(Equal(input))
|
||||
matcher.ReceivedActual = ""
|
||||
|
||||
a.To(matcher)
|
||||
|
||||
Ω(matcher.ReceivedActual).Should(Equal(input))
|
||||
Expect(matcher.ReceivedActual).Should(Equal(input))
|
||||
matcher.ReceivedActual = ""
|
||||
|
||||
a.ToNot(matcher)
|
||||
|
||||
Ω(matcher.ReceivedActual).Should(Equal(input))
|
||||
Expect(matcher.ReceivedActual).Should(Equal(input))
|
||||
matcher.ReceivedActual = ""
|
||||
|
||||
a.NotTo(matcher)
|
||||
|
||||
Ω(matcher.ReceivedActual).Should(Equal(input))
|
||||
Expect(matcher.ReceivedActual).Should(Equal(input))
|
||||
})
|
||||
})
|
||||
|
||||
@@ -70,23 +76,23 @@ var _ = Describe("Assertion", func() {
|
||||
Context("and a positive assertion is being made", func() {
|
||||
It("should not call the failure callback", func() {
|
||||
a.Should(matcher)
|
||||
Ω(failureMessage).Should(Equal(""))
|
||||
Expect(failureMessage).Should(Equal(""))
|
||||
})
|
||||
|
||||
It("should be true", func() {
|
||||
Ω(a.Should(matcher)).Should(BeTrue())
|
||||
Expect(a.Should(matcher)).Should(BeTrue())
|
||||
})
|
||||
})
|
||||
|
||||
Context("and a negative assertion is being made", func() {
|
||||
It("should call the failure callback", func() {
|
||||
a.ShouldNot(matcher)
|
||||
Ω(failureMessage).Should(Equal("negative: The thing I'm testing"))
|
||||
Ω(failureCallerSkip).Should(Equal(3))
|
||||
Expect(failureMessage).Should(Equal("negative: The thing I'm testing"))
|
||||
Expect(failureCallerSkip).Should(Equal(3))
|
||||
})
|
||||
|
||||
It("should be false", func() {
|
||||
Ω(a.ShouldNot(matcher)).Should(BeFalse())
|
||||
Expect(a.ShouldNot(matcher)).Should(BeFalse())
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -100,23 +106,23 @@ var _ = Describe("Assertion", func() {
|
||||
Context("and a positive assertion is being made", func() {
|
||||
It("should call the failure callback", func() {
|
||||
a.Should(matcher)
|
||||
Ω(failureMessage).Should(Equal("positive: The thing I'm testing"))
|
||||
Ω(failureCallerSkip).Should(Equal(3))
|
||||
Expect(failureMessage).Should(Equal("positive: The thing I'm testing"))
|
||||
Expect(failureCallerSkip).Should(Equal(3))
|
||||
})
|
||||
|
||||
It("should be false", func() {
|
||||
Ω(a.Should(matcher)).Should(BeFalse())
|
||||
Expect(a.Should(matcher)).Should(BeFalse())
|
||||
})
|
||||
})
|
||||
|
||||
Context("and a negative assertion is being made", func() {
|
||||
It("should not call the failure callback", func() {
|
||||
a.ShouldNot(matcher)
|
||||
Ω(failureMessage).Should(Equal(""))
|
||||
Expect(failureMessage).Should(Equal(""))
|
||||
})
|
||||
|
||||
It("should be true", func() {
|
||||
Ω(a.ShouldNot(matcher)).Should(BeTrue())
|
||||
Expect(a.ShouldNot(matcher)).Should(BeTrue())
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -130,16 +136,16 @@ var _ = Describe("Assertion", func() {
|
||||
Context("and there is an optional description", func() {
|
||||
It("should append the description to the failure message", func() {
|
||||
a.Should(matcher, "A description")
|
||||
Ω(failureMessage).Should(Equal("A description\npositive: The thing I'm testing"))
|
||||
Ω(failureCallerSkip).Should(Equal(3))
|
||||
Expect(failureMessage).Should(Equal("A description\npositive: The thing I'm testing"))
|
||||
Expect(failureCallerSkip).Should(Equal(3))
|
||||
})
|
||||
})
|
||||
|
||||
Context("and there are multiple arguments to the optional description", func() {
|
||||
It("should append the formatted description to the failure message", func() {
|
||||
a.Should(matcher, "A description of [%d]", 3)
|
||||
Ω(failureMessage).Should(Equal("A description of [3]\npositive: The thing I'm testing"))
|
||||
Ω(failureCallerSkip).Should(Equal(3))
|
||||
Expect(failureMessage).Should(Equal("A description of [3]\npositive: The thing I'm testing"))
|
||||
Expect(failureCallerSkip).Should(Equal(3))
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -153,8 +159,8 @@ var _ = Describe("Assertion", func() {
|
||||
It("should call the failure callback", func() {
|
||||
matcher.MatchesToReturn = true
|
||||
a.Should(matcher)
|
||||
Ω(failureMessage).Should(Equal("Kaboom!"))
|
||||
Ω(failureCallerSkip).Should(Equal(3))
|
||||
Expect(failureMessage).Should(Equal("Kaboom!"))
|
||||
Expect(failureCallerSkip).Should(Equal(3))
|
||||
})
|
||||
})
|
||||
|
||||
@@ -162,20 +168,20 @@ var _ = Describe("Assertion", func() {
|
||||
It("should call the failure callback", func() {
|
||||
matcher.MatchesToReturn = false
|
||||
a.ShouldNot(matcher)
|
||||
Ω(failureMessage).Should(Equal("Kaboom!"))
|
||||
Ω(failureCallerSkip).Should(Equal(3))
|
||||
Expect(failureMessage).Should(Equal("Kaboom!"))
|
||||
Expect(failureCallerSkip).Should(Equal(3))
|
||||
})
|
||||
})
|
||||
|
||||
It("should always be false", func() {
|
||||
Ω(a.Should(matcher)).Should(BeFalse())
|
||||
Ω(a.ShouldNot(matcher)).Should(BeFalse())
|
||||
Expect(a.Should(matcher)).Should(BeFalse())
|
||||
Expect(a.ShouldNot(matcher)).Should(BeFalse())
|
||||
})
|
||||
})
|
||||
|
||||
Context("when there are extra parameters", func() {
|
||||
It("(a simple example)", func() {
|
||||
Ω(func() (string, int, error) {
|
||||
Expect(func() (string, int, error) {
|
||||
return "foo", 0, nil
|
||||
}()).Should(Equal("foo"))
|
||||
})
|
||||
@@ -186,13 +192,13 @@ var _ = Describe("Assertion", func() {
|
||||
matcher.ErrToReturn = nil
|
||||
|
||||
var typedNil []string
|
||||
a = New(input, fakeFailHandler, 1, 0, nil, typedNil)
|
||||
a = New(input, fakeFailWrapper, 1, 0, nil, typedNil)
|
||||
|
||||
result := a.Should(matcher)
|
||||
Ω(result).Should(BeTrue())
|
||||
Ω(matcher.ReceivedActual).Should(Equal(input))
|
||||
Expect(result).Should(BeTrue())
|
||||
Expect(matcher.ReceivedActual).Should(Equal(input))
|
||||
|
||||
Ω(failureMessage).Should(BeZero())
|
||||
Expect(failureMessage).Should(BeZero())
|
||||
})
|
||||
})
|
||||
|
||||
@@ -201,36 +207,36 @@ var _ = Describe("Assertion", func() {
|
||||
matcher.MatchesToReturn = false
|
||||
matcher.ErrToReturn = nil
|
||||
|
||||
a = New(input, fakeFailHandler, 1, errors.New("foo"))
|
||||
a = New(input, fakeFailWrapper, 1, errors.New("foo"))
|
||||
result := a.Should(matcher)
|
||||
Ω(result).Should(BeFalse())
|
||||
Ω(matcher.ReceivedActual).Should(BeZero(), "The matcher doesn't even get called")
|
||||
Ω(failureMessage).Should(ContainSubstring("foo"))
|
||||
Expect(result).Should(BeFalse())
|
||||
Expect(matcher.ReceivedActual).Should(BeZero(), "The matcher doesn't even get called")
|
||||
Expect(failureMessage).Should(ContainSubstring("foo"))
|
||||
failureMessage = ""
|
||||
|
||||
a = New(input, fakeFailHandler, 1, nil, 1)
|
||||
a = New(input, fakeFailWrapper, 1, nil, 1)
|
||||
result = a.ShouldNot(matcher)
|
||||
Ω(result).Should(BeFalse())
|
||||
Ω(failureMessage).Should(ContainSubstring("1"))
|
||||
Expect(result).Should(BeFalse())
|
||||
Expect(failureMessage).Should(ContainSubstring("1"))
|
||||
failureMessage = ""
|
||||
|
||||
a = New(input, fakeFailHandler, 1, nil, 0, []string{"foo"})
|
||||
a = New(input, fakeFailWrapper, 1, nil, 0, []string{"foo"})
|
||||
result = a.To(matcher)
|
||||
Ω(result).Should(BeFalse())
|
||||
Ω(failureMessage).Should(ContainSubstring("foo"))
|
||||
Expect(result).Should(BeFalse())
|
||||
Expect(failureMessage).Should(ContainSubstring("foo"))
|
||||
failureMessage = ""
|
||||
|
||||
a = New(input, fakeFailHandler, 1, nil, 0, []string{"foo"})
|
||||
a = New(input, fakeFailWrapper, 1, nil, 0, []string{"foo"})
|
||||
result = a.ToNot(matcher)
|
||||
Ω(result).Should(BeFalse())
|
||||
Ω(failureMessage).Should(ContainSubstring("foo"))
|
||||
Expect(result).Should(BeFalse())
|
||||
Expect(failureMessage).Should(ContainSubstring("foo"))
|
||||
failureMessage = ""
|
||||
|
||||
a = New(input, fakeFailHandler, 1, nil, 0, []string{"foo"})
|
||||
a = New(input, fakeFailWrapper, 1, nil, 0, []string{"foo"})
|
||||
result = a.NotTo(matcher)
|
||||
Ω(result).Should(BeFalse())
|
||||
Ω(failureMessage).Should(ContainSubstring("foo"))
|
||||
Ω(failureCallerSkip).Should(Equal(3))
|
||||
Expect(result).Should(BeFalse())
|
||||
Expect(failureMessage).Should(ContainSubstring("foo"))
|
||||
Expect(failureCallerSkip).Should(Equal(3))
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -246,7 +252,7 @@ var _ = Describe("Assertion", func() {
|
||||
}()
|
||||
|
||||
RegisterFailHandler(nil)
|
||||
Ω(true).Should(BeTrue())
|
||||
Expect(true).Should(BeTrue())
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user