Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: onsi/ginkgo
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.14.1
Choose a base ref
...
head repository: onsi/ginkgo
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.14.2
Choose a head ref
  • 3 commits
  • 7 files changed
  • 3 contributors

Commits on Sep 9, 2020

  1. Add additional methods to GinkgoT() to improve compatibility with the…

    … testing.TB interface
    onsi committed Sep 9, 2020
    Copy the full SHA
    b5fe44d View commit details

Commits on Sep 24, 2020

  1. Copy the full SHA
    97f3d51 View commit details

Commits on Oct 12, 2020

  1. v1.14.2

    blgm committed Oct 12, 2020
    Copy the full SHA
    55c8587 View commit details
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 1.14.2

### Fixes
- correct handling windows backslash in import path (#721) [97f3d51]
- Add additional methods to GinkgoT() to improve compatibility with the testing.TB interface [b5fe44d]

## 1.14.1

### Fixes
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ import (
"fmt"
)

const VERSION = "1.14.1"
const VERSION = "1.14.2"

type GinkgoConfigType struct {
RandomSeed int64
4 changes: 3 additions & 1 deletion ginkgo/generate_command.go
Original file line number Diff line number Diff line change
@@ -233,18 +233,20 @@ func getPackageImportPath() string {
panic(err.Error())
}

sep := string(filepath.Separator)

// Try go.mod file first
modRoot := findModuleRoot(workingDir)
if modRoot != "" {
modName := moduleName(modRoot)
if modName != "" {
cd := strings.Replace(workingDir, modRoot, "", -1)
cd = strings.ReplaceAll(cd, sep, "/")
return modName + cd
}
}

// Fallback to GOPATH structure
sep := string(filepath.Separator)
paths := strings.Split(workingDir, sep+"src"+sep)
if len(paths) == 1 {
fmt.Printf("\nCouldn't identify package import path.\n\n\tginkgo generate\n\nMust be run within a package directory under $GOPATH/src/...\nYou're going to have to change UNKNOWN_PACKAGE_PATH in the generated file...\n\n")
18 changes: 14 additions & 4 deletions ginkgo_dsl.go
Original file line number Diff line number Diff line change
@@ -93,26 +93,36 @@ func GinkgoT(optionalOffset ...int) GinkgoTInterface {
if len(optionalOffset) > 0 {
offset = optionalOffset[0]
}
return testingtproxy.New(GinkgoWriter, Fail, offset)
failedFunc := func() bool {
return CurrentGinkgoTestDescription().Failed
}
nameFunc := func() string {
return CurrentGinkgoTestDescription().FullTestText
}
return testingtproxy.New(GinkgoWriter, Fail, Skip, failedFunc, nameFunc, offset)
}

//The interface returned by GinkgoT(). This covers most of the methods
//in the testing package's T.
type GinkgoTInterface interface {
Fail()
Cleanup(func())
Error(args ...interface{})
Errorf(format string, args ...interface{})
Fail()
FailNow()
Failed() bool
Fatal(args ...interface{})
Fatalf(format string, args ...interface{})
Helper()
Log(args ...interface{})
Logf(format string, args ...interface{})
Failed() bool
Name() string
Parallel()
Skip(args ...interface{})
Skipf(format string, args ...interface{})
SkipNow()
Skipf(format string, args ...interface{})
Skipped() bool
TempDir() string
}

//Custom Ginkgo test reporters must implement the Reporter interface.
42 changes: 35 additions & 7 deletions internal/testingtproxy/testing_t_proxy.go
Original file line number Diff line number Diff line change
@@ -6,21 +6,34 @@ import (
)

type failFunc func(message string, callerSkip ...int)
type skipFunc func(message string, callerSkip ...int)
type failedFunc func() bool
type nameFunc func() string

func New(writer io.Writer, fail failFunc, offset int) *ginkgoTestingTProxy {
func New(writer io.Writer, fail failFunc, skip skipFunc, failed failedFunc, name nameFunc, offset int) *ginkgoTestingTProxy {
return &ginkgoTestingTProxy{
fail: fail,
offset: offset,
writer: writer,
skip: skip,
failed: failed,
name: name,
}
}

type ginkgoTestingTProxy struct {
fail failFunc
skip skipFunc
failed failedFunc
name nameFunc
offset int
writer io.Writer
}

func (t *ginkgoTestingTProxy) Cleanup(func()) {
// No-op
}

func (t *ginkgoTestingTProxy) Error(args ...interface{}) {
t.fail(fmt.Sprintln(args...), t.offset)
}
@@ -37,6 +50,10 @@ func (t *ginkgoTestingTProxy) FailNow() {
t.fail("failed", t.offset)
}

func (t *ginkgoTestingTProxy) Failed() bool {
return t.failed()
}

func (t *ginkgoTestingTProxy) Fatal(args ...interface{}) {
t.fail(fmt.Sprintln(args...), t.offset)
}
@@ -45,6 +62,10 @@ func (t *ginkgoTestingTProxy) Fatalf(format string, args ...interface{}) {
t.fail(fmt.Sprintf(format, args...), t.offset)
}

func (t *ginkgoTestingTProxy) Helper() {
// No-op
}

func (t *ginkgoTestingTProxy) Log(args ...interface{}) {
fmt.Fprintln(t.writer, args...)
}
@@ -53,24 +74,31 @@ func (t *ginkgoTestingTProxy) Logf(format string, args ...interface{}) {
t.Log(fmt.Sprintf(format, args...))
}

func (t *ginkgoTestingTProxy) Failed() bool {
return false
func (t *ginkgoTestingTProxy) Name() string {
return t.name()
}

func (t *ginkgoTestingTProxy) Parallel() {
// No-op
}

func (t *ginkgoTestingTProxy) Skip(args ...interface{}) {
fmt.Println(args...)
t.skip(fmt.Sprintln(args...), t.offset)
}

func (t *ginkgoTestingTProxy) Skipf(format string, args ...interface{}) {
t.Skip(fmt.Sprintf(format, args...))
func (t *ginkgoTestingTProxy) SkipNow() {
t.skip("skip", t.offset)
}

func (t *ginkgoTestingTProxy) SkipNow() {
func (t *ginkgoTestingTProxy) Skipf(format string, args ...interface{}) {
t.skip(fmt.Sprintf(format, args...), t.offset)
}

func (t *ginkgoTestingTProxy) Skipped() bool {
return false
}

func (t *ginkgoTestingTProxy) TempDir() string {
// No-op
return ""
}
13 changes: 13 additions & 0 deletions internal/testingtproxy/testingtproxy_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package testingtproxy_test

import (
"testing"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

func TestTestingtproxy(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Testingtproxy Suite")
}
154 changes: 154 additions & 0 deletions internal/testingtproxy/testingtproxy_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
package testingtproxy_test

import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

"github.com/onsi/gomega/gbytes"

"github.com/onsi/ginkgo/internal/testingtproxy"
)

type messagedCall struct {
message string
callerSkip []int
}

var _ = Describe("Testingtproxy", func() {
var t GinkgoTInterface

var failFunc func(message string, callerSkip ...int)
var skipFunc func(message string, callerSkip ...int)
var failedFunc func() bool
var nameFunc func() string

var nameToReturn string
var failedToReturn bool
var failFuncCall messagedCall
var skipFuncCall messagedCall
var offset int
var buf *gbytes.Buffer

BeforeEach(func() {
failFuncCall = messagedCall{}
skipFuncCall = messagedCall{}
nameToReturn = ""
failedToReturn = false
offset = 3

failFunc = func(message string, callerSkip ...int) {
failFuncCall.message = message
failFuncCall.callerSkip = callerSkip
}

skipFunc = func(message string, callerSkip ...int) {
skipFuncCall.message = message
skipFuncCall.callerSkip = callerSkip
}

failedFunc = func() bool {
return failedToReturn
}

nameFunc = func() string {
return nameToReturn
}

buf = gbytes.NewBuffer()

t = testingtproxy.New(buf, failFunc, skipFunc, failedFunc, nameFunc, offset)
})

It("ignores Cleanup", func() {
GinkgoT().Cleanup(func() {
panic("bam!")
}) //is a no-op
})

It("supports Error", func() {
t.Error("a", 17)
Ω(failFuncCall.message).Should(Equal("a 17\n"))
Ω(failFuncCall.callerSkip).Should(Equal([]int{offset}))
})

It("supports Errorf", func() {
t.Errorf("%s %d!", "a", 17)
Ω(failFuncCall.message).Should(Equal("a 17!"))
Ω(failFuncCall.callerSkip).Should(Equal([]int{offset}))
})

It("supports Fail", func() {
t.Fail()
Ω(failFuncCall.message).Should(Equal("failed"))
Ω(failFuncCall.callerSkip).Should(Equal([]int{offset}))
})

It("supports FailNow", func() {
t.Fail()
Ω(failFuncCall.message).Should(Equal("failed"))
Ω(failFuncCall.callerSkip).Should(Equal([]int{offset}))
})

It("supports Fatal", func() {
t.Fatal("a", 17)
Ω(failFuncCall.message).Should(Equal("a 17\n"))
Ω(failFuncCall.callerSkip).Should(Equal([]int{offset}))
})

It("supports Fatalf", func() {
t.Fatalf("%s %d!", "a", 17)
Ω(failFuncCall.message).Should(Equal("a 17!"))
Ω(failFuncCall.callerSkip).Should(Equal([]int{offset}))
})

It("ignores Helper", func() {
GinkgoT().Helper() //is a no-op
})

It("supports Log", func() {
t.Log("a", 17)
Ω(string(buf.Contents())).Should(Equal("a 17\n"))
})

It("supports Logf", func() {
t.Logf("%s %d!", "a", 17)
Ω(string(buf.Contents())).Should(Equal("a 17!\n"))
})

It("supports Name", func() {
nameToReturn = "C.S. Lewis"
Ω(t.Name()).Should(Equal("C.S. Lewis"))

Ω(GinkgoT().Name()).Should(ContainSubstring("supports Name"))
})

It("ignores Parallel", func() {
GinkgoT().Parallel() //is a no-op
})

It("supports Skip", func() {
t.Skip("a", 17)
Ω(skipFuncCall.message).Should(Equal("a 17\n"))
Ω(skipFuncCall.callerSkip).Should(Equal([]int{offset}))
})

It("supports SkipNow", func() {
t.SkipNow()
Ω(skipFuncCall.message).Should(Equal("skip"))
Ω(skipFuncCall.callerSkip).Should(Equal([]int{offset}))
})

It("supports Skipf", func() {
t.Skipf("%s %d!", "a", 17)
Ω(skipFuncCall.message).Should(Equal("a 17!"))
Ω(skipFuncCall.callerSkip).Should(Equal([]int{offset}))
})

It("always returns false for Skipped", func() {
Ω(GinkgoT().Skipped()).Should(BeFalse())
})

It("returns empty string for TempDir", func() {
Ω(GinkgoT().TempDir()).Should(Equal(""))
})
})