Skip to content

Commit

Permalink
Merge pull request #204 from xeger/go15vendorexperiment
Browse files Browse the repository at this point in the history
Support GO15VENDOREXPERIMENT by ignoring vendored test suites.
  • Loading branch information
onsi committed Dec 19, 2015
2 parents d8b05bb + cdad21d commit e43390e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
10 changes: 10 additions & 0 deletions ginkgo/testsuite/test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"io/ioutil"
"os"
"path"
"path/filepath"
"regexp"
"strings"
Expand Down Expand Up @@ -47,6 +48,15 @@ func PrecompiledTestSuite(path string) (TestSuite, error) {

func SuitesInDir(dir string, recurse bool) []TestSuite {
suites := []TestSuite{}

// "This change will only be enabled if the go command is run with
// GO15VENDOREXPERIMENT=1 in its environment."
// c.f. the vendor-experiment proposal https://goo.gl/2ucMeC
vendorExperiment := os.Getenv("GO15VENDOREXPERIMENT")
if (vendorExperiment == "1") && path.Base(dir) == "vendor" {
return suites
}

files, _ := ioutil.ReadDir(dir)
re := regexp.MustCompile(`_test\.go$`)
for _, file := range files {
Expand Down
35 changes: 34 additions & 1 deletion ginkgo/testsuite/testsuite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ var _ = Describe("TestSuite", func() {
ioutil.WriteFile(path, []byte(content), mode)
}

var origVendor string

BeforeSuite(func() {
origVendor = os.Getenv("GO15VENDOREXPERIMENT")
})

AfterSuite(func() {
os.Setenv("GO15VENDOREXPERIMENT", origVendor)
})

BeforeEach(func() {
var err error
tmpDir, err = ioutil.TempDir("/tmp", "ginkgo")
Expand All @@ -49,6 +59,9 @@ var _ = Describe("TestSuite", func() {
//ginkgo tests in a deeply nested directory
writeFile("/colonelmustard/library", "library_test.go", `import "github.com/onsi/ginkgo"`, 0666)

//ginkgo tests deeply nested in a vendored dependency
writeFile("/vendor/mrspeacock/lounge", "lounge_test.go", `import "github.com/onsi/ginkgo"`, 0666)

//a precompiled ginkgo test
writeFile("/precompiled-dir", "precompiled.test", `fake-binary-file`, 0777)
writeFile("/precompiled-dir", "some-other-binary", `fake-binary-file`, 0777)
Expand Down Expand Up @@ -138,10 +151,30 @@ var _ = Describe("TestSuite", func() {
})
})

Context("given GO15VENDOREXPERIMENT", func() {
BeforeEach(func() {
os.Setenv("GO15VENDOREXPERIMENT", "1")
})

AfterEach(func() {
os.Setenv("GO15VENDOREXPERIMENT", "")
})

It("should skip vendor dirs", func() {
suites := SuitesInDir(filepath.Join(tmpDir+"/vendor"), false)
Ω(suites).Should(HaveLen(0))
})

It("should not recurse into vendor dirs", func() {
suites := SuitesInDir(filepath.Join(tmpDir), true)
Ω(suites).Should(HaveLen(3))
})
})

Context("when recursively scanning", func() {
It("should return suites for corresponding test suites, only", func() {
suites := SuitesInDir(tmpDir, true)
Ω(suites).Should(HaveLen(3))
Ω(suites).Should(HaveLen(4))

Ω(suites).Should(ContainElement(TestSuite{
Path: relTmpDir + "/colonelmustard",
Expand Down

0 comments on commit e43390e

Please sign in to comment.