1 package testingtsupport
8 "github.com/onsi/gomega/types"
11 type gomegaTestingT interface {
12 Errorf(format string, args ...interface{})
15 func BuildTestingTGomegaFailHandler(t gomegaTestingT) types.GomegaFailHandler {
16 return func(message string, callerSkip ...int) {
18 if len(callerSkip) > 0 {
21 stackTrace := pruneStack(string(debug.Stack()), skip)
22 t.Errorf("\n%s\n%s", stackTrace, message)
26 func pruneStack(fullStackTrace string, skip int) string {
27 stack := strings.Split(fullStackTrace, "\n")
28 if len(stack) > 2*(skip+1) {
29 stack = stack[2*(skip+1):]
31 prunedStack := []string{}
32 re := regexp.MustCompile(`\/ginkgo\/|\/pkg\/testing\/|\/pkg\/runtime\/`)
33 for i := 0; i < len(stack)/2; i++ {
34 if !re.Match([]byte(stack[i*2])) {
35 prunedStack = append(prunedStack, stack[i*2])
36 prunedStack = append(prunedStack, stack[i*2+1])
39 return strings.Join(prunedStack, "\n")