@@ -32,7 +32,7 @@ Alternatively, you may have forgotten to register a fail handler with RegisterFa
3232Depending on your vendoring solution you may be inadvertently importing gomega and subpackages (e.g. ghhtp, gexec,...) from different locations.
3333`
3434
35- var globalFailHandler types.GomegaFailHandler
35+ var globalFailWrapper * types.GomegaFailWrapper
3636
3737var defaultEventuallyTimeout = time .Second
3838var defaultEventuallyPollingInterval = 10 * time .Millisecond
@@ -42,7 +42,14 @@ var defaultConsistentlyPollingInterval = 10 * time.Millisecond
4242//RegisterFailHandler connects Ginkgo to Gomega. When a matcher fails
4343//the fail handler passed into RegisterFailHandler is called.
4444func RegisterFailHandler (handler types.GomegaFailHandler ) {
45- globalFailHandler = handler
45+ if handler == nil {
46+ globalFailWrapper = nil
47+ return
48+ }
49+ globalFailWrapper = & types.GomegaFailWrapper {
50+ Fail : handler ,
51+ TWithHelper : testingtsupport.EmptyTWithHelper {},
52+ }
4653}
4754
4855//RegisterTestingT connects Gomega to Golang's XUnit style
@@ -67,7 +74,7 @@ func RegisterFailHandler(handler types.GomegaFailHandler) {
6774//
6875// (As an aside: Ginkgo gets around this limitation by running parallel tests in different *processes*).
6976func RegisterTestingT (t types.GomegaTestingT ) {
70- RegisterFailHandler (testingtsupport .BuildTestingTGomegaFailHandler (t ))
77+ RegisterFailHandler (testingtsupport .BuildTestingTGomegaFailWrapper (t ). Fail )
7178}
7279
7380//InterceptGomegaHandlers runs a given callback and returns an array of
@@ -80,7 +87,7 @@ func RegisterTestingT(t types.GomegaTestingT) {
8087//This is most useful when testing custom matchers, but can also be used to check
8188//on a value using a Gomega assertion without causing a test failure.
8289func InterceptGomegaFailures (f func ()) []string {
83- originalHandler := globalFailHandler
90+ originalHandler := globalFailWrapper . Fail
8491 failures := []string {}
8592 RegisterFailHandler (func (message string , callerSkip ... int ) {
8693 failures = append (failures , message )
@@ -142,10 +149,10 @@ func Expect(actual interface{}, extra ...interface{}) GomegaAssertion {
142149//error message to refer to the calling line in the test (as opposed to the line in the helper function)
143150//set the first argument of `ExpectWithOffset` appropriately.
144151func ExpectWithOffset (offset int , actual interface {}, extra ... interface {}) GomegaAssertion {
145- if globalFailHandler == nil {
152+ if globalFailWrapper == nil {
146153 panic (nilFailHandlerPanic )
147154 }
148- return assertion .New (actual , globalFailHandler , offset , extra ... )
155+ return assertion .New (actual , globalFailWrapper , offset , extra ... )
149156}
150157
151158//Eventually wraps an actual value allowing assertions to be made on it.
@@ -192,7 +199,7 @@ func Eventually(actual interface{}, intervals ...interface{}) GomegaAsyncAsserti
192199//initial argument to indicate an offset in the call stack. This is useful when building helper
193200//functions that contain matchers. To learn more, read about `ExpectWithOffset`.
194201func EventuallyWithOffset (offset int , actual interface {}, intervals ... interface {}) GomegaAsyncAssertion {
195- if globalFailHandler == nil {
202+ if globalFailWrapper == nil {
196203 panic (nilFailHandlerPanic )
197204 }
198205 timeoutInterval := defaultEventuallyTimeout
@@ -203,7 +210,7 @@ func EventuallyWithOffset(offset int, actual interface{}, intervals ...interface
203210 if len (intervals ) > 1 {
204211 pollingInterval = toDuration (intervals [1 ])
205212 }
206- return asyncassertion .New (asyncassertion .AsyncAssertionTypeEventually , actual , globalFailHandler , timeoutInterval , pollingInterval , offset )
213+ return asyncassertion .New (asyncassertion .AsyncAssertionTypeEventually , actual , globalFailWrapper , timeoutInterval , pollingInterval , offset )
207214}
208215
209216//Consistently wraps an actual value allowing assertions to be made on it.
@@ -237,7 +244,7 @@ func Consistently(actual interface{}, intervals ...interface{}) GomegaAsyncAsser
237244//initial argument to indicate an offset in the call stack. This is useful when building helper
238245//functions that contain matchers. To learn more, read about `ExpectWithOffset`.
239246func ConsistentlyWithOffset (offset int , actual interface {}, intervals ... interface {}) GomegaAsyncAssertion {
240- if globalFailHandler == nil {
247+ if globalFailWrapper == nil {
241248 panic (nilFailHandlerPanic )
242249 }
243250 timeoutInterval := defaultConsistentlyDuration
@@ -248,7 +255,7 @@ func ConsistentlyWithOffset(offset int, actual interface{}, intervals ...interfa
248255 if len (intervals ) > 1 {
249256 pollingInterval = toDuration (intervals [1 ])
250257 }
251- return asyncassertion .New (asyncassertion .AsyncAssertionTypeConsistently , actual , globalFailHandler , timeoutInterval , pollingInterval , offset )
258+ return asyncassertion .New (asyncassertion .AsyncAssertionTypeConsistently , actual , globalFailWrapper , timeoutInterval , pollingInterval , offset )
252259}
253260
254261//Set the default timeout duration for Eventually. Eventually will repeatedly poll your condition until it succeeds, or until this timeout elapses.
@@ -340,7 +347,7 @@ func NewGomegaWithT(t types.GomegaTestingT) *GomegaWithT {
340347
341348//See documentation for Expect
342349func (g * GomegaWithT ) Expect (actual interface {}, extra ... interface {}) GomegaAssertion {
343- return assertion .New (actual , testingtsupport .BuildTestingTGomegaFailHandler (g .t ), 0 , extra ... )
350+ return assertion .New (actual , testingtsupport .BuildTestingTGomegaFailWrapper (g .t ), 0 , extra ... )
344351}
345352
346353//See documentation for Eventually
@@ -353,7 +360,7 @@ func (g *GomegaWithT) Eventually(actual interface{}, intervals ...interface{}) G
353360 if len (intervals ) > 1 {
354361 pollingInterval = toDuration (intervals [1 ])
355362 }
356- return asyncassertion .New (asyncassertion .AsyncAssertionTypeEventually , actual , testingtsupport .BuildTestingTGomegaFailHandler (g .t ), timeoutInterval , pollingInterval , 0 )
363+ return asyncassertion .New (asyncassertion .AsyncAssertionTypeEventually , actual , testingtsupport .BuildTestingTGomegaFailWrapper (g .t ), timeoutInterval , pollingInterval , 0 )
357364}
358365
359366//See documentation for Consistently
@@ -366,7 +373,7 @@ func (g *GomegaWithT) Consistently(actual interface{}, intervals ...interface{})
366373 if len (intervals ) > 1 {
367374 pollingInterval = toDuration (intervals [1 ])
368375 }
369- return asyncassertion .New (asyncassertion .AsyncAssertionTypeConsistently , actual , testingtsupport .BuildTestingTGomegaFailHandler (g .t ), timeoutInterval , pollingInterval , 0 )
376+ return asyncassertion .New (asyncassertion .AsyncAssertionTypeConsistently , actual , testingtsupport .BuildTestingTGomegaFailWrapper (g .t ), timeoutInterval , pollingInterval , 0 )
370377}
371378
372379func toDuration (input interface {}) time.Duration {
0 commit comments