initial commit
[govpp.git] / vendor / github.com / onsi / gomega / internal / testingtsupport / testing_t_support.go
1 package testingtsupport
2
3 import (
4         "regexp"
5         "runtime/debug"
6         "strings"
7
8         "github.com/onsi/gomega/types"
9 )
10
11 type gomegaTestingT interface {
12         Errorf(format string, args ...interface{})
13 }
14
15 func BuildTestingTGomegaFailHandler(t gomegaTestingT) types.GomegaFailHandler {
16         return func(message string, callerSkip ...int) {
17                 skip := 1
18                 if len(callerSkip) > 0 {
19                         skip = callerSkip[0]
20                 }
21                 stackTrace := pruneStack(string(debug.Stack()), skip)
22                 t.Errorf("\n%s\n%s", stackTrace, message)
23         }
24 }
25
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):]
30         }
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])
37                 }
38         }
39         return strings.Join(prunedStack, "\n")
40 }