summaryrefslogtreecommitdiff
path: root/vendor/github.com/onsi/gomega/internal/testingtsupport
diff options
context:
space:
mode:
authorValentin Rothberg <rothberg@redhat.com>2019-02-05 11:51:41 +0100
committerValentin Rothberg <rothberg@redhat.com>2019-02-06 11:14:06 +0100
commit9ac0ebb0791851aea81ecc847802db5a39bfb6e7 (patch)
tree30ad98bcc2c2dd1136f46a48cbc44d422adfa184 /vendor/github.com/onsi/gomega/internal/testingtsupport
parent51714d5da7aaa19014fd67b48b79dfbd5f69c1f0 (diff)
downloadpodman-9ac0ebb0791851aea81ecc847802db5a39bfb6e7.tar.gz
podman-9ac0ebb0791851aea81ecc847802db5a39bfb6e7.tar.bz2
podman-9ac0ebb0791851aea81ecc847802db5a39bfb6e7.zip
Cirrus: add vendor_check_task
* Make sure that all vendored dependencies are in sync with the code and the vendor.conf by running `make vendor` with a follow-up status check of the git tree. * Vendor ginkgo and gomega to include the test dependencies. Signed-off-by: Chris Evic <cevich@redhat.com> Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
Diffstat (limited to 'vendor/github.com/onsi/gomega/internal/testingtsupport')
-rw-r--r--vendor/github.com/onsi/gomega/internal/testingtsupport/testing_t_support.go60
-rw-r--r--vendor/github.com/onsi/gomega/internal/testingtsupport/testing_t_support_test.go92
2 files changed, 152 insertions, 0 deletions
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
new file mode 100644
index 000000000..bb27032f6
--- /dev/null
+++ b/vendor/github.com/onsi/gomega/internal/testingtsupport/testing_t_support.go
@@ -0,0 +1,60 @@
+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")
+}
diff --git a/vendor/github.com/onsi/gomega/internal/testingtsupport/testing_t_support_test.go b/vendor/github.com/onsi/gomega/internal/testingtsupport/testing_t_support_test.go
new file mode 100644
index 000000000..8fd8f0a6c
--- /dev/null
+++ b/vendor/github.com/onsi/gomega/internal/testingtsupport/testing_t_support_test.go
@@ -0,0 +1,92 @@
+package testingtsupport_test
+
+import (
+ "regexp"
+ "time"
+
+ "github.com/onsi/gomega/internal/testingtsupport"
+
+ . "github.com/onsi/gomega"
+
+ "fmt"
+ "testing"
+)
+
+func TestTestingT(t *testing.T) {
+ RegisterTestingT(t)
+ Ω(true).Should(BeTrue())
+}
+
+type FakeTWithHelper struct {
+ LastFatal string
+}
+
+func (f *FakeTWithHelper) Fatalf(format string, args ...interface{}) {
+ f.LastFatal = fmt.Sprintf(format, args...)
+}
+
+func TestGomegaWithTWithoutHelper(t *testing.T) {
+ g := NewGomegaWithT(t)
+
+ testingtsupport.StackTracePruneRE = regexp.MustCompile(`\/ginkgo\/`)
+
+ f := &FakeTWithHelper{}
+ testG := NewGomegaWithT(f)
+
+ testG.Expect("foo").To(Equal("foo"))
+ g.Expect(f.LastFatal).To(BeZero())
+
+ testG.Expect("foo").To(Equal("bar"))
+ g.Expect(f.LastFatal).To(ContainSubstring("<string>: foo"))
+ g.Expect(f.LastFatal).To(ContainSubstring("testingtsupport_test"), "It should include a stacktrace")
+
+ testG.Eventually("foo2", time.Millisecond).Should(Equal("bar"))
+ g.Expect(f.LastFatal).To(ContainSubstring("<string>: foo2"))
+
+ testG.Consistently("foo3", time.Millisecond).Should(Equal("bar"))
+ g.Expect(f.LastFatal).To(ContainSubstring("<string>: foo3"))
+}
+
+type FakeTWithoutHelper struct {
+ LastFatal string
+ HelperCount int
+}
+
+func (f *FakeTWithoutHelper) Fatalf(format string, args ...interface{}) {
+ f.LastFatal = fmt.Sprintf(format, args...)
+}
+
+func (f *FakeTWithoutHelper) Helper() {
+ f.HelperCount += 1
+}
+
+func (f *FakeTWithoutHelper) ResetHelper() {
+ f.HelperCount = 0
+}
+
+func TestGomegaWithTWithHelper(t *testing.T) {
+ g := NewGomegaWithT(t)
+
+ f := &FakeTWithoutHelper{}
+ testG := NewGomegaWithT(f)
+
+ testG.Expect("foo").To(Equal("foo"))
+ g.Expect(f.LastFatal).To(BeZero())
+ g.Expect(f.HelperCount).To(BeNumerically(">", 0))
+ f.ResetHelper()
+
+ testG.Expect("foo").To(Equal("bar"))
+ g.Expect(f.LastFatal).To(ContainSubstring("<string>: foo"))
+ g.Expect(f.LastFatal).NotTo(ContainSubstring("testingtsupport_test"), "It should _not_ include a stacktrace")
+ g.Expect(f.HelperCount).To(BeNumerically(">", 0))
+ f.ResetHelper()
+
+ testG.Eventually("foo2", time.Millisecond).Should(Equal("bar"))
+ g.Expect(f.LastFatal).To(ContainSubstring("<string>: foo2"))
+ g.Expect(f.HelperCount).To(BeNumerically(">", 0))
+ f.ResetHelper()
+
+ testG.Consistently("foo3", time.Millisecond).Should(Equal("bar"))
+ g.Expect(f.LastFatal).To(ContainSubstring("<string>: foo3"))
+ g.Expect(f.HelperCount).To(BeNumerically(">", 0))
+}