summaryrefslogtreecommitdiff
path: root/vendor/github.com/onsi/gomega/internal
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/onsi/gomega/internal')
-rw-r--r--vendor/github.com/onsi/gomega/internal/assertion.go (renamed from vendor/github.com/onsi/gomega/internal/assertion/assertion.go)28
-rw-r--r--vendor/github.com/onsi/gomega/internal/async_assertion.go (renamed from vendor/github.com/onsi/gomega/internal/asyncassertion/async_assertion.go)171
-rw-r--r--vendor/github.com/onsi/gomega/internal/defaults/env.go22
-rw-r--r--vendor/github.com/onsi/gomega/internal/duration_bundle.go71
-rw-r--r--vendor/github.com/onsi/gomega/internal/gomega.go102
-rw-r--r--vendor/github.com/onsi/gomega/internal/oraclematcher/oracle_matcher.go25
-rw-r--r--vendor/github.com/onsi/gomega/internal/testingtsupport/testing_t_support.go60
7 files changed, 265 insertions, 214 deletions
diff --git a/vendor/github.com/onsi/gomega/internal/assertion/assertion.go b/vendor/github.com/onsi/gomega/internal/assertion.go
index a248298f4..36b0e8345 100644
--- a/vendor/github.com/onsi/gomega/internal/assertion/assertion.go
+++ b/vendor/github.com/onsi/gomega/internal/assertion.go
@@ -1,4 +1,4 @@
-package assertion
+package internal
import (
"fmt"
@@ -9,42 +9,42 @@ import (
type Assertion struct {
actualInput interface{}
- failWrapper *types.GomegaFailWrapper
offset int
extra []interface{}
+ g *Gomega
}
-func New(actualInput interface{}, failWrapper *types.GomegaFailWrapper, offset int, extra ...interface{}) *Assertion {
+func NewAssertion(actualInput interface{}, g *Gomega, offset int, extra ...interface{}) *Assertion {
return &Assertion{
actualInput: actualInput,
- failWrapper: failWrapper,
offset: offset,
extra: extra,
+ g: g,
}
}
func (assertion *Assertion) Should(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool {
- assertion.failWrapper.TWithHelper.Helper()
+ assertion.g.THelper()
return assertion.vetExtras(optionalDescription...) && assertion.match(matcher, true, optionalDescription...)
}
func (assertion *Assertion) ShouldNot(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool {
- assertion.failWrapper.TWithHelper.Helper()
+ assertion.g.THelper()
return assertion.vetExtras(optionalDescription...) && assertion.match(matcher, false, optionalDescription...)
}
func (assertion *Assertion) To(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool {
- assertion.failWrapper.TWithHelper.Helper()
+ assertion.g.THelper()
return assertion.vetExtras(optionalDescription...) && assertion.match(matcher, true, optionalDescription...)
}
func (assertion *Assertion) ToNot(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool {
- assertion.failWrapper.TWithHelper.Helper()
+ assertion.g.THelper()
return assertion.vetExtras(optionalDescription...) && assertion.match(matcher, false, optionalDescription...)
}
func (assertion *Assertion) NotTo(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool {
- assertion.failWrapper.TWithHelper.Helper()
+ assertion.g.THelper()
return assertion.vetExtras(optionalDescription...) && assertion.match(matcher, false, optionalDescription...)
}
@@ -62,10 +62,10 @@ func (assertion *Assertion) buildDescription(optionalDescription ...interface{})
func (assertion *Assertion) match(matcher types.GomegaMatcher, desiredMatch bool, optionalDescription ...interface{}) bool {
matches, err := matcher.Match(assertion.actualInput)
- assertion.failWrapper.TWithHelper.Helper()
+ assertion.g.THelper()
if err != nil {
description := assertion.buildDescription(optionalDescription...)
- assertion.failWrapper.Fail(description+err.Error(), 2+assertion.offset)
+ assertion.g.Fail(description+err.Error(), 2+assertion.offset)
return false
}
if matches != desiredMatch {
@@ -76,7 +76,7 @@ func (assertion *Assertion) match(matcher types.GomegaMatcher, desiredMatch bool
message = matcher.NegatedFailureMessage(assertion.actualInput)
}
description := assertion.buildDescription(optionalDescription...)
- assertion.failWrapper.Fail(description+message, 2+assertion.offset)
+ assertion.g.Fail(description+message, 2+assertion.offset)
return false
}
@@ -90,8 +90,8 @@ func (assertion *Assertion) vetExtras(optionalDescription ...interface{}) bool {
}
description := assertion.buildDescription(optionalDescription...)
- assertion.failWrapper.TWithHelper.Helper()
- assertion.failWrapper.Fail(description+message, 2+assertion.offset)
+ assertion.g.THelper()
+ assertion.g.Fail(description+message, 2+assertion.offset)
return false
}
diff --git a/vendor/github.com/onsi/gomega/internal/asyncassertion/async_assertion.go b/vendor/github.com/onsi/gomega/internal/async_assertion.go
index 6aa02bc5d..ae20c14b8 100644
--- a/vendor/github.com/onsi/gomega/internal/asyncassertion/async_assertion.go
+++ b/vendor/github.com/onsi/gomega/internal/async_assertion.go
@@ -1,6 +1,4 @@
-// untested sections: 2
-
-package asyncassertion
+package internal
import (
"errors"
@@ -9,7 +7,6 @@ import (
"runtime"
"time"
- "github.com/onsi/gomega/internal/oraclematcher"
"github.com/onsi/gomega/types"
)
@@ -21,39 +18,82 @@ const (
)
type AsyncAssertion struct {
- asyncType AsyncAssertionType
- actualInput interface{}
+ asyncType AsyncAssertionType
+
+ actualIsFunc bool
+ actualValue interface{}
+ actualFunc func() ([]reflect.Value, error)
+
timeoutInterval time.Duration
pollingInterval time.Duration
- failWrapper *types.GomegaFailWrapper
offset int
+ g *Gomega
}
-func New(asyncType AsyncAssertionType, actualInput interface{}, failWrapper *types.GomegaFailWrapper, timeoutInterval time.Duration, pollingInterval time.Duration, offset int) *AsyncAssertion {
- actualType := reflect.TypeOf(actualInput)
- if actualType.Kind() == reflect.Func {
- if actualType.NumIn() != 0 {
- panic("Expected a function with no arguments and zero or more return values.")
- }
- }
-
- return &AsyncAssertion{
+func NewAsyncAssertion(asyncType AsyncAssertionType, actualInput interface{}, g *Gomega, timeoutInterval time.Duration, pollingInterval time.Duration, offset int) *AsyncAssertion {
+ out := &AsyncAssertion{
asyncType: asyncType,
- actualInput: actualInput,
- failWrapper: failWrapper,
timeoutInterval: timeoutInterval,
pollingInterval: pollingInterval,
offset: offset,
+ g: g,
+ }
+
+ switch actualType := reflect.TypeOf(actualInput); {
+ case actualType.Kind() != reflect.Func:
+ out.actualValue = actualInput
+ case actualType.NumIn() == 0 && actualType.NumOut() > 0:
+ out.actualIsFunc = true
+ out.actualFunc = func() ([]reflect.Value, error) {
+ return reflect.ValueOf(actualInput).Call([]reflect.Value{}), nil
+ }
+ case actualType.NumIn() == 1 && actualType.In(0).Implements(reflect.TypeOf((*types.Gomega)(nil)).Elem()):
+ out.actualIsFunc = true
+ out.actualFunc = func() (values []reflect.Value, err error) {
+ var assertionFailure error
+ assertionCapturingGomega := NewGomega(g.DurationBundle).ConfigureWithFailHandler(func(message string, callerSkip ...int) {
+ skip := 0
+ if len(callerSkip) > 0 {
+ skip = callerSkip[0]
+ }
+ _, file, line, _ := runtime.Caller(skip + 1)
+ assertionFailure = fmt.Errorf("Assertion in callback at %s:%d failed:\n%s", file, line, message)
+ panic("stop execution")
+ })
+
+ defer func() {
+ if actualType.NumOut() == 0 {
+ if assertionFailure == nil {
+ values = []reflect.Value{reflect.Zero(reflect.TypeOf((*error)(nil)).Elem())}
+ } else {
+ values = []reflect.Value{reflect.ValueOf(assertionFailure)}
+ }
+ } else {
+ err = assertionFailure
+ }
+ if e := recover(); e != nil && assertionFailure == nil {
+ panic(e)
+ }
+ }()
+
+ values = reflect.ValueOf(actualInput).Call([]reflect.Value{reflect.ValueOf(assertionCapturingGomega)})
+ return
+ }
+ default:
+ msg := fmt.Sprintf("The function passed to Gomega's async assertions should either take no arguments and return values, or take a single Gomega interface that it can use to make assertions within the body of the function. When taking a Gomega interface the function can optionally return values or return nothing. The function you passed takes %d arguments and returns %d values.", actualType.NumIn(), actualType.NumOut())
+ g.Fail(msg, offset+4)
}
+
+ return out
}
func (assertion *AsyncAssertion) Should(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool {
- assertion.failWrapper.TWithHelper.Helper()
+ assertion.g.THelper()
return assertion.match(matcher, true, optionalDescription...)
}
func (assertion *AsyncAssertion) ShouldNot(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool {
- assertion.failWrapper.TWithHelper.Helper()
+ assertion.g.THelper()
return assertion.match(matcher, false, optionalDescription...)
}
@@ -69,74 +109,32 @@ func (assertion *AsyncAssertion) buildDescription(optionalDescription ...interfa
return fmt.Sprintf(optionalDescription[0].(string), optionalDescription[1:]...) + "\n"
}
-func (assertion *AsyncAssertion) actualInputIsAFunction() bool {
- actualType := reflect.TypeOf(assertion.actualInput)
- return actualType.Kind() == reflect.Func && actualType.NumIn() == 0
-}
-
func (assertion *AsyncAssertion) pollActual() (interface{}, error) {
- if !assertion.actualInputIsAFunction() {
- return assertion.actualInput, nil
+ if !assertion.actualIsFunc {
+ return assertion.actualValue, nil
}
- var capturedAssertionFailure string
- var values []reflect.Value
-
- numOut := reflect.TypeOf(assertion.actualInput).NumOut()
- func() {
- originalHandler := assertion.failWrapper.Fail
- assertion.failWrapper.Fail = func(message string, callerSkip ...int) {
- skip := 0
- if len(callerSkip) > 0 {
- skip = callerSkip[0]
- }
- _, file, line, _ := runtime.Caller(skip + 1)
- capturedAssertionFailure = fmt.Sprintf("Assertion in callback at %s:%d failed:\n%s", file, line, message)
- panic("stop execution")
- }
-
- defer func() {
- assertion.failWrapper.Fail = originalHandler
- if e := recover(); e != nil && capturedAssertionFailure == "" {
- panic(e)
- }
- }()
-
- values = reflect.ValueOf(assertion.actualInput).Call([]reflect.Value{})
- }()
-
- if capturedAssertionFailure != "" {
- if numOut == 0 {
- return errors.New(capturedAssertionFailure), nil
- } else {
- return nil, errors.New(capturedAssertionFailure)
- }
+ values, err := assertion.actualFunc()
+ if err != nil {
+ return nil, err
}
-
- if numOut > 0 {
- extras := []interface{}{}
- for _, value := range values[1:] {
- extras = append(extras, value.Interface())
- }
-
- success, message := vetExtras(extras)
-
- if !success {
- return nil, errors.New(message)
- }
-
- return values[0].Interface(), nil
+ extras := []interface{}{}
+ for _, value := range values[1:] {
+ extras = append(extras, value.Interface())
+ }
+ success, message := vetExtras(extras)
+ if !success {
+ return nil, errors.New(message)
}
- return nil, nil
+ return values[0].Interface(), nil
}
func (assertion *AsyncAssertion) matcherMayChange(matcher types.GomegaMatcher, value interface{}) bool {
- if assertion.actualInputIsAFunction() {
+ if assertion.actualIsFunc {
return true
}
-
- return oraclematcher.MatchMayChangeInTheFuture(matcher, value)
+ return types.MatchMayChangeInTheFuture(matcher, value)
}
func (assertion *AsyncAssertion) match(matcher types.GomegaMatcher, desiredMatch bool, optionalDescription ...interface{}) bool {
@@ -152,7 +150,7 @@ func (assertion *AsyncAssertion) match(matcher types.GomegaMatcher, desiredMatch
matches, err = matcher.Match(value)
}
- assertion.failWrapper.TWithHelper.Helper()
+ assertion.g.THelper()
fail := func(preamble string) {
errMsg := ""
@@ -166,9 +164,9 @@ func (assertion *AsyncAssertion) match(matcher types.GomegaMatcher, desiredMatch
message = matcher.NegatedFailureMessage(value)
}
}
- assertion.failWrapper.TWithHelper.Helper()
+ assertion.g.THelper()
description := assertion.buildDescription(optionalDescription...)
- assertion.failWrapper.Fail(fmt.Sprintf("%s after %.3fs.\n%s%s%s", preamble, time.Since(timer).Seconds(), description, message, errMsg), 3+assertion.offset)
+ assertion.g.Fail(fmt.Sprintf("%s after %.3fs.\n%s%s%s", preamble, time.Since(timer).Seconds(), description, message, errMsg), 3+assertion.offset)
}
if assertion.asyncType == AsyncAssertionTypeEventually {
@@ -220,16 +218,3 @@ func (assertion *AsyncAssertion) match(matcher types.GomegaMatcher, desiredMatch
return false
}
-
-func vetExtras(extras []interface{}) (bool, string) {
- for i, extra := range extras {
- if extra != nil {
- zeroValue := reflect.Zero(reflect.TypeOf(extra)).Interface()
- if !reflect.DeepEqual(zeroValue, extra) {
- message := fmt.Sprintf("Unexpected non-nil/non-zero extra argument at index %d:\n\t<%T>: %#v", i+1, extra, extra)
- return false, message
- }
- }
- }
- return true, ""
-}
diff --git a/vendor/github.com/onsi/gomega/internal/defaults/env.go b/vendor/github.com/onsi/gomega/internal/defaults/env.go
deleted file mode 100644
index bc29c63d5..000000000
--- a/vendor/github.com/onsi/gomega/internal/defaults/env.go
+++ /dev/null
@@ -1,22 +0,0 @@
-package defaults
-
-import (
- "fmt"
- "time"
-)
-
-func SetDurationFromEnv(getDurationFromEnv func(string) string, varSetter func(time.Duration), name string) {
- durationFromEnv := getDurationFromEnv(name)
-
- if len(durationFromEnv) == 0 {
- return
- }
-
- duration, err := time.ParseDuration(durationFromEnv)
-
- if err != nil {
- panic(fmt.Sprintf("Expected a duration when using %s! Parse error %v", name, err))
- }
-
- varSetter(duration)
-}
diff --git a/vendor/github.com/onsi/gomega/internal/duration_bundle.go b/vendor/github.com/onsi/gomega/internal/duration_bundle.go
new file mode 100644
index 000000000..af8d989fa
--- /dev/null
+++ b/vendor/github.com/onsi/gomega/internal/duration_bundle.go
@@ -0,0 +1,71 @@
+package internal
+
+import (
+ "fmt"
+ "os"
+ "reflect"
+ "time"
+)
+
+type DurationBundle struct {
+ EventuallyTimeout time.Duration
+ EventuallyPollingInterval time.Duration
+ ConsistentlyDuration time.Duration
+ ConsistentlyPollingInterval time.Duration
+}
+
+const (
+ EventuallyTimeoutEnvVarName = "GOMEGA_DEFAULT_EVENTUALLY_TIMEOUT"
+ EventuallyPollingIntervalEnvVarName = "GOMEGA_DEFAULT_EVENTUALLY_POLLING_INTERVAL"
+
+ ConsistentlyDurationEnvVarName = "GOMEGA_DEFAULT_CONSISTENTLY_DURATION"
+ ConsistentlyPollingIntervalEnvVarName = "GOMEGA_DEFAULT_CONSISTENTLY_POLLING_INTERVAL"
+)
+
+func FetchDefaultDurationBundle() DurationBundle {
+ return DurationBundle{
+ EventuallyTimeout: durationFromEnv(EventuallyTimeoutEnvVarName, time.Second),
+ EventuallyPollingInterval: durationFromEnv(EventuallyPollingIntervalEnvVarName, 10*time.Millisecond),
+
+ ConsistentlyDuration: durationFromEnv(ConsistentlyDurationEnvVarName, 100*time.Millisecond),
+ ConsistentlyPollingInterval: durationFromEnv(ConsistentlyPollingIntervalEnvVarName, 10*time.Millisecond),
+ }
+}
+
+func durationFromEnv(key string, defaultDuration time.Duration) time.Duration {
+ value := os.Getenv(key)
+ if value == "" {
+ return defaultDuration
+ }
+ duration, err := time.ParseDuration(value)
+ if err != nil {
+ panic(fmt.Sprintf("Expected a duration when using %s! Parse error %v", key, err))
+ }
+ return duration
+}
+
+func toDuration(input interface{}) time.Duration {
+ duration, ok := input.(time.Duration)
+ if ok {
+ return duration
+ }
+
+ value := reflect.ValueOf(input)
+ kind := reflect.TypeOf(input).Kind()
+
+ if reflect.Int <= kind && kind <= reflect.Int64 {
+ return time.Duration(value.Int()) * time.Second
+ } else if reflect.Uint <= kind && kind <= reflect.Uint64 {
+ return time.Duration(value.Uint()) * time.Second
+ } else if reflect.Float32 <= kind && kind <= reflect.Float64 {
+ return time.Duration(value.Float() * float64(time.Second))
+ } else if reflect.String == kind {
+ duration, err := time.ParseDuration(value.String())
+ if err != nil {
+ panic(fmt.Sprintf("%#v is not a valid parsable duration string.", input))
+ }
+ return duration
+ }
+
+ panic(fmt.Sprintf("%v is not a valid interval. Must be time.Duration, parsable duration string or a number.", input))
+}
diff --git a/vendor/github.com/onsi/gomega/internal/gomega.go b/vendor/github.com/onsi/gomega/internal/gomega.go
new file mode 100644
index 000000000..f5b5c6b7a
--- /dev/null
+++ b/vendor/github.com/onsi/gomega/internal/gomega.go
@@ -0,0 +1,102 @@
+package internal
+
+import (
+ "time"
+
+ "github.com/onsi/gomega/types"
+)
+
+type Gomega struct {
+ Fail types.GomegaFailHandler
+ THelper func()
+ DurationBundle DurationBundle
+}
+
+func NewGomega(bundle DurationBundle) *Gomega {
+ return &Gomega{
+ Fail: nil,
+ THelper: nil,
+ DurationBundle: bundle,
+ }
+}
+
+func (g *Gomega) IsConfigured() bool {
+ return g.Fail != nil && g.THelper != nil
+}
+
+func (g *Gomega) ConfigureWithFailHandler(fail types.GomegaFailHandler) *Gomega {
+ g.Fail = fail
+ g.THelper = func() {}
+ return g
+}
+
+func (g *Gomega) ConfigureWithT(t types.GomegaTestingT) *Gomega {
+ g.Fail = func(message string, _ ...int) {
+ t.Helper()
+ t.Fatalf("\n%s", message)
+ }
+ g.THelper = t.Helper
+ return g
+}
+
+func (g *Gomega) Ω(atual interface{}, extra ...interface{}) types.Assertion {
+ return g.ExpectWithOffset(0, atual, extra...)
+}
+
+func (g *Gomega) Expect(atual interface{}, extra ...interface{}) types.Assertion {
+ return g.ExpectWithOffset(0, atual, extra...)
+}
+
+func (g *Gomega) ExpectWithOffset(offset int, actual interface{}, extra ...interface{}) types.Assertion {
+ return NewAssertion(actual, g, offset, extra...)
+}
+
+func (g *Gomega) Eventually(actual interface{}, intervals ...interface{}) types.AsyncAssertion {
+ return g.EventuallyWithOffset(0, actual, intervals...)
+}
+
+func (g *Gomega) EventuallyWithOffset(offset int, actual interface{}, intervals ...interface{}) types.AsyncAssertion {
+ timeoutInterval := g.DurationBundle.EventuallyTimeout
+ pollingInterval := g.DurationBundle.EventuallyPollingInterval
+ if len(intervals) > 0 {
+ timeoutInterval = toDuration(intervals[0])
+ }
+ if len(intervals) > 1 {
+ pollingInterval = toDuration(intervals[1])
+ }
+
+ return NewAsyncAssertion(AsyncAssertionTypeEventually, actual, g, timeoutInterval, pollingInterval, offset)
+}
+
+func (g *Gomega) Consistently(actual interface{}, intervals ...interface{}) types.AsyncAssertion {
+ return g.ConsistentlyWithOffset(0, actual, intervals...)
+}
+
+func (g *Gomega) ConsistentlyWithOffset(offset int, actual interface{}, intervals ...interface{}) types.AsyncAssertion {
+ timeoutInterval := g.DurationBundle.ConsistentlyDuration
+ pollingInterval := g.DurationBundle.ConsistentlyPollingInterval
+ if len(intervals) > 0 {
+ timeoutInterval = toDuration(intervals[0])
+ }
+ if len(intervals) > 1 {
+ pollingInterval = toDuration(intervals[1])
+ }
+
+ return NewAsyncAssertion(AsyncAssertionTypeConsistently, actual, g, timeoutInterval, pollingInterval, offset)
+}
+
+func (g *Gomega) SetDefaultEventuallyTimeout(t time.Duration) {
+ g.DurationBundle.EventuallyTimeout = t
+}
+
+func (g *Gomega) SetDefaultEventuallyPollingInterval(t time.Duration) {
+ g.DurationBundle.EventuallyPollingInterval = t
+}
+
+func (g *Gomega) SetDefaultConsistentlyDuration(t time.Duration) {
+ g.DurationBundle.ConsistentlyDuration = t
+}
+
+func (g *Gomega) SetDefaultConsistentlyPollingInterval(t time.Duration) {
+ g.DurationBundle.ConsistentlyPollingInterval = t
+}
diff --git a/vendor/github.com/onsi/gomega/internal/oraclematcher/oracle_matcher.go b/vendor/github.com/onsi/gomega/internal/oraclematcher/oracle_matcher.go
deleted file mode 100644
index 66cad88a1..000000000
--- a/vendor/github.com/onsi/gomega/internal/oraclematcher/oracle_matcher.go
+++ /dev/null
@@ -1,25 +0,0 @@
-package oraclematcher
-
-import "github.com/onsi/gomega/types"
-
-/*
-GomegaMatchers that also match the OracleMatcher interface can convey information about
-whether or not their result will change upon future attempts.
-
-This allows `Eventually` and `Consistently` to short circuit if success becomes impossible.
-
-For example, a process' exit code can never change. So, gexec's Exit matcher returns `true`
-for `MatchMayChangeInTheFuture` until the process exits, at which point it returns `false` forevermore.
-*/
-type OracleMatcher interface {
- MatchMayChangeInTheFuture(actual interface{}) bool
-}
-
-func MatchMayChangeInTheFuture(matcher types.GomegaMatcher, value interface{}) bool {
- oracleMatcher, ok := matcher.(OracleMatcher)
- if !ok {
- return true
- }
-
- return oracleMatcher.MatchMayChangeInTheFuture(value)
-}
diff --git a/vendor/github.com/onsi/gomega/internal/testingtsupport/testing_t_support.go b/vendor/github.com/onsi/gomega/internal/testingtsupport/testing_t_support.go
deleted file mode 100644
index bb27032f6..000000000
--- a/vendor/github.com/onsi/gomega/internal/testingtsupport/testing_t_support.go
+++ /dev/null
@@ -1,60 +0,0 @@
-package testingtsupport
-
-import (
- "regexp"
- "runtime/debug"
- "strings"
-
- "github.com/onsi/gomega/types"
-)
-
-var StackTracePruneRE = regexp.MustCompile(`\/gomega\/|\/ginkgo\/|\/pkg\/testing\/|\/pkg\/runtime\/`)
-
-type EmptyTWithHelper struct{}
-
-func (e EmptyTWithHelper) Helper() {}
-
-type gomegaTestingT interface {
- Fatalf(format string, args ...interface{})
-}
-
-func BuildTestingTGomegaFailWrapper(t gomegaTestingT) *types.GomegaFailWrapper {
- tWithHelper, hasHelper := t.(types.TWithHelper)
- if !hasHelper {
- tWithHelper = EmptyTWithHelper{}
- }
-
- fail := func(message string, callerSkip ...int) {
- if hasHelper {
- tWithHelper.Helper()
- t.Fatalf("\n%s", message)
- } else {
- skip := 2
- if len(callerSkip) > 0 {
- skip += callerSkip[0]
- }
- stackTrace := pruneStack(string(debug.Stack()), skip)
- t.Fatalf("\n%s\n%s\n", stackTrace, message)
- }
- }
-
- return &types.GomegaFailWrapper{
- Fail: fail,
- TWithHelper: tWithHelper,
- }
-}
-
-func pruneStack(fullStackTrace string, skip int) string {
- stack := strings.Split(fullStackTrace, "\n")[1:]
- if len(stack) > 2*skip {
- stack = stack[2*skip:]
- }
- prunedStack := []string{}
- for i := 0; i < len(stack)/2; i++ {
- if !StackTracePruneRE.Match([]byte(stack[i*2])) {
- prunedStack = append(prunedStack, stack[i*2])
- prunedStack = append(prunedStack, stack[i*2+1])
- }
- }
- return strings.Join(prunedStack, "\n")
-}