Use Go 1.5 vendoring instead of Godeps
Change made by: - running "gvt fetch" on each of the packages mentioned in Godeps/Godeps.json - `rm -rf Godeps` - tweaking the build scripts to not mention Godeps - tweaking the build scripts to test `./lib/...`, `./cmd/...` explicitly (to avoid testing vendor) - tweaking the build scripts to not juggle GOPATH for Godeps and instead set GO15VENDOREXPERIMENT. This also results in some updated packages at the same time I bet. Building with Go 1.3 and 1.4 still *works* but won't use our vendored dependencies - the user needs to have the actual packages in their GOPATH then, which they'll get with a normal "go get". Building with Go 1.6+ will get our vendored dependencies by default even when not using our build script, which is nice. By doing this we gain some freedom in that we can pick and choose manually what to include in vendor, as it's not based on just dependency analysis of our own code. This is also a risk as we might pick up dependencies we are unaware of, as the build may work locally with those packages present in GOPATH. On the other hand the build server will detect this as it has no packages in it's GOPATH beyond what is included in the repo. Recommended tool to manage dependencies is github.com/FiloSottile/gvt.
This commit is contained in:
+194
@@ -0,0 +1,194 @@
|
||||
package nodot
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go/ast"
|
||||
"go/build"
|
||||
"go/parser"
|
||||
"go/token"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func ApplyNoDot(data []byte) ([]byte, error) {
|
||||
sections, err := generateNodotSections()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, section := range sections {
|
||||
data = section.createOrUpdateIn(data)
|
||||
}
|
||||
|
||||
return data, nil
|
||||
}
|
||||
|
||||
type nodotSection struct {
|
||||
name string
|
||||
pkg string
|
||||
declarations []string
|
||||
types []string
|
||||
}
|
||||
|
||||
func (s nodotSection) createOrUpdateIn(data []byte) []byte {
|
||||
renames := map[string]string{}
|
||||
|
||||
contents := string(data)
|
||||
|
||||
lines := strings.Split(contents, "\n")
|
||||
|
||||
comment := "// Declarations for " + s.name
|
||||
|
||||
newLines := []string{}
|
||||
for _, line := range lines {
|
||||
if line == comment {
|
||||
continue
|
||||
}
|
||||
|
||||
words := strings.Split(line, " ")
|
||||
lastWord := words[len(words)-1]
|
||||
|
||||
if s.containsDeclarationOrType(lastWord) {
|
||||
renames[lastWord] = words[1]
|
||||
continue
|
||||
}
|
||||
|
||||
newLines = append(newLines, line)
|
||||
}
|
||||
|
||||
if len(newLines[len(newLines)-1]) > 0 {
|
||||
newLines = append(newLines, "")
|
||||
}
|
||||
|
||||
newLines = append(newLines, comment)
|
||||
|
||||
for _, typ := range s.types {
|
||||
name, ok := renames[s.prefix(typ)]
|
||||
if !ok {
|
||||
name = typ
|
||||
}
|
||||
newLines = append(newLines, fmt.Sprintf("type %s %s", name, s.prefix(typ)))
|
||||
}
|
||||
|
||||
for _, decl := range s.declarations {
|
||||
name, ok := renames[s.prefix(decl)]
|
||||
if !ok {
|
||||
name = decl
|
||||
}
|
||||
newLines = append(newLines, fmt.Sprintf("var %s = %s", name, s.prefix(decl)))
|
||||
}
|
||||
|
||||
newLines = append(newLines, "")
|
||||
|
||||
newContents := strings.Join(newLines, "\n")
|
||||
|
||||
return []byte(newContents)
|
||||
}
|
||||
|
||||
func (s nodotSection) prefix(declOrType string) string {
|
||||
return s.pkg + "." + declOrType
|
||||
}
|
||||
|
||||
func (s nodotSection) containsDeclarationOrType(word string) bool {
|
||||
for _, declaration := range s.declarations {
|
||||
if s.prefix(declaration) == word {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
for _, typ := range s.types {
|
||||
if s.prefix(typ) == word {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func generateNodotSections() ([]nodotSection, error) {
|
||||
sections := []nodotSection{}
|
||||
|
||||
declarations, err := getExportedDeclerationsForPackage("github.com/onsi/ginkgo", "ginkgo_dsl.go", "GINKGO_VERSION", "GINKGO_PANIC")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
sections = append(sections, nodotSection{
|
||||
name: "Ginkgo DSL",
|
||||
pkg: "ginkgo",
|
||||
declarations: declarations,
|
||||
types: []string{"Done", "Benchmarker"},
|
||||
})
|
||||
|
||||
declarations, err = getExportedDeclerationsForPackage("github.com/onsi/gomega", "gomega_dsl.go", "GOMEGA_VERSION")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
sections = append(sections, nodotSection{
|
||||
name: "Gomega DSL",
|
||||
pkg: "gomega",
|
||||
declarations: declarations,
|
||||
})
|
||||
|
||||
declarations, err = getExportedDeclerationsForPackage("github.com/onsi/gomega", "matchers.go")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
sections = append(sections, nodotSection{
|
||||
name: "Gomega Matchers",
|
||||
pkg: "gomega",
|
||||
declarations: declarations,
|
||||
})
|
||||
|
||||
return sections, nil
|
||||
}
|
||||
|
||||
func getExportedDeclerationsForPackage(pkgPath string, filename string, blacklist ...string) ([]string, error) {
|
||||
pkg, err := build.Import(pkgPath, ".", 0)
|
||||
if err != nil {
|
||||
return []string{}, err
|
||||
}
|
||||
|
||||
declarations, err := getExportedDeclarationsForFile(filepath.Join(pkg.Dir, filename))
|
||||
if err != nil {
|
||||
return []string{}, err
|
||||
}
|
||||
|
||||
blacklistLookup := map[string]bool{}
|
||||
for _, declaration := range blacklist {
|
||||
blacklistLookup[declaration] = true
|
||||
}
|
||||
|
||||
filteredDeclarations := []string{}
|
||||
for _, declaration := range declarations {
|
||||
if blacklistLookup[declaration] {
|
||||
continue
|
||||
}
|
||||
filteredDeclarations = append(filteredDeclarations, declaration)
|
||||
}
|
||||
|
||||
return filteredDeclarations, nil
|
||||
}
|
||||
|
||||
func getExportedDeclarationsForFile(path string) ([]string, error) {
|
||||
fset := token.NewFileSet()
|
||||
tree, err := parser.ParseFile(fset, path, nil, 0)
|
||||
if err != nil {
|
||||
return []string{}, err
|
||||
}
|
||||
|
||||
declarations := []string{}
|
||||
ast.FileExports(tree)
|
||||
for _, decl := range tree.Decls {
|
||||
switch x := decl.(type) {
|
||||
case *ast.GenDecl:
|
||||
switch s := x.Specs[0].(type) {
|
||||
case *ast.ValueSpec:
|
||||
declarations = append(declarations, s.Names[0].Name)
|
||||
}
|
||||
case *ast.FuncDecl:
|
||||
declarations = append(declarations, x.Name.Name)
|
||||
}
|
||||
}
|
||||
|
||||
return declarations, nil
|
||||
}
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
package nodot_test
|
||||
|
||||
import (
|
||||
"github.com/onsi/ginkgo"
|
||||
"github.com/onsi/gomega"
|
||||
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNodot(t *testing.T) {
|
||||
RegisterFailHandler(Fail)
|
||||
RunSpecs(t, "Nodot Suite")
|
||||
}
|
||||
|
||||
// Declarations for Ginkgo DSL
|
||||
type Done ginkgo.Done
|
||||
type Benchmarker ginkgo.Benchmarker
|
||||
|
||||
var GinkgoWriter = ginkgo.GinkgoWriter
|
||||
var GinkgoParallelNode = ginkgo.GinkgoParallelNode
|
||||
var GinkgoT = ginkgo.GinkgoT
|
||||
var CurrentGinkgoTestDescription = ginkgo.CurrentGinkgoTestDescription
|
||||
var RunSpecs = ginkgo.RunSpecs
|
||||
var RunSpecsWithDefaultAndCustomReporters = ginkgo.RunSpecsWithDefaultAndCustomReporters
|
||||
var RunSpecsWithCustomReporters = ginkgo.RunSpecsWithCustomReporters
|
||||
var Fail = ginkgo.Fail
|
||||
var GinkgoRecover = ginkgo.GinkgoRecover
|
||||
var Describe = ginkgo.Describe
|
||||
var FDescribe = ginkgo.FDescribe
|
||||
var PDescribe = ginkgo.PDescribe
|
||||
var XDescribe = ginkgo.XDescribe
|
||||
var Context = ginkgo.Context
|
||||
var FContext = ginkgo.FContext
|
||||
var PContext = ginkgo.PContext
|
||||
var XContext = ginkgo.XContext
|
||||
var It = ginkgo.It
|
||||
var FIt = ginkgo.FIt
|
||||
var PIt = ginkgo.PIt
|
||||
var XIt = ginkgo.XIt
|
||||
var Measure = ginkgo.Measure
|
||||
var FMeasure = ginkgo.FMeasure
|
||||
var PMeasure = ginkgo.PMeasure
|
||||
var XMeasure = ginkgo.XMeasure
|
||||
var BeforeSuite = ginkgo.BeforeSuite
|
||||
var AfterSuite = ginkgo.AfterSuite
|
||||
var SynchronizedBeforeSuite = ginkgo.SynchronizedBeforeSuite
|
||||
var SynchronizedAfterSuite = ginkgo.SynchronizedAfterSuite
|
||||
var BeforeEach = ginkgo.BeforeEach
|
||||
var JustBeforeEach = ginkgo.JustBeforeEach
|
||||
var AfterEach = ginkgo.AfterEach
|
||||
|
||||
// Declarations for Gomega DSL
|
||||
var RegisterFailHandler = gomega.RegisterFailHandler
|
||||
var RegisterTestingT = gomega.RegisterTestingT
|
||||
var InterceptGomegaFailures = gomega.InterceptGomegaFailures
|
||||
var Ω = gomega.Ω
|
||||
var Expect = gomega.Expect
|
||||
var ExpectWithOffset = gomega.ExpectWithOffset
|
||||
var Eventually = gomega.Eventually
|
||||
var EventuallyWithOffset = gomega.EventuallyWithOffset
|
||||
var Consistently = gomega.Consistently
|
||||
var ConsistentlyWithOffset = gomega.ConsistentlyWithOffset
|
||||
var SetDefaultEventuallyTimeout = gomega.SetDefaultEventuallyTimeout
|
||||
var SetDefaultEventuallyPollingInterval = gomega.SetDefaultEventuallyPollingInterval
|
||||
var SetDefaultConsistentlyDuration = gomega.SetDefaultConsistentlyDuration
|
||||
var SetDefaultConsistentlyPollingInterval = gomega.SetDefaultConsistentlyPollingInterval
|
||||
|
||||
// Declarations for Gomega Matchers
|
||||
var Equal = gomega.Equal
|
||||
var BeEquivalentTo = gomega.BeEquivalentTo
|
||||
var BeNil = gomega.BeNil
|
||||
var BeTrue = gomega.BeTrue
|
||||
var BeFalse = gomega.BeFalse
|
||||
var HaveOccurred = gomega.HaveOccurred
|
||||
var MatchError = gomega.MatchError
|
||||
var BeClosed = gomega.BeClosed
|
||||
var Receive = gomega.Receive
|
||||
var MatchRegexp = gomega.MatchRegexp
|
||||
var ContainSubstring = gomega.ContainSubstring
|
||||
var MatchJSON = gomega.MatchJSON
|
||||
var BeEmpty = gomega.BeEmpty
|
||||
var HaveLen = gomega.HaveLen
|
||||
var BeZero = gomega.BeZero
|
||||
var ContainElement = gomega.ContainElement
|
||||
var ConsistOf = gomega.ConsistOf
|
||||
var HaveKey = gomega.HaveKey
|
||||
var HaveKeyWithValue = gomega.HaveKeyWithValue
|
||||
var BeNumerically = gomega.BeNumerically
|
||||
var BeTemporally = gomega.BeTemporally
|
||||
var BeAssignableToTypeOf = gomega.BeAssignableToTypeOf
|
||||
var Panic = gomega.Panic
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
package nodot_test
|
||||
|
||||
import (
|
||||
. "github.com/onsi/ginkgo/ginkgo/nodot"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var _ = Describe("ApplyNoDot", func() {
|
||||
var result string
|
||||
|
||||
apply := func(input string) string {
|
||||
output, err := ApplyNoDot([]byte(input))
|
||||
Ω(err).ShouldNot(HaveOccurred())
|
||||
return string(output)
|
||||
}
|
||||
|
||||
Context("when no declarations have been imported yet", func() {
|
||||
BeforeEach(func() {
|
||||
result = apply("")
|
||||
})
|
||||
|
||||
It("should add headings for the various declarations", func() {
|
||||
Ω(result).Should(ContainSubstring("// Declarations for Ginkgo DSL"))
|
||||
Ω(result).Should(ContainSubstring("// Declarations for Gomega DSL"))
|
||||
Ω(result).Should(ContainSubstring("// Declarations for Gomega Matchers"))
|
||||
})
|
||||
|
||||
It("should import Ginkgo's declarations", func() {
|
||||
Ω(result).Should(ContainSubstring("var It = ginkgo.It"))
|
||||
Ω(result).Should(ContainSubstring("var XDescribe = ginkgo.XDescribe"))
|
||||
})
|
||||
|
||||
It("should import Ginkgo's types", func() {
|
||||
Ω(result).Should(ContainSubstring("type Done ginkgo.Done"))
|
||||
Ω(result).Should(ContainSubstring("type Benchmarker ginkgo.Benchmarker"))
|
||||
Ω(strings.Count(result, "type ")).Should(Equal(2))
|
||||
})
|
||||
|
||||
It("should import Gomega's DSL and matchers", func() {
|
||||
Ω(result).Should(ContainSubstring("var Ω = gomega.Ω"))
|
||||
Ω(result).Should(ContainSubstring("var ContainSubstring = gomega.ContainSubstring"))
|
||||
Ω(result).Should(ContainSubstring("var Equal = gomega.Equal"))
|
||||
})
|
||||
|
||||
It("should not import blacklisted things", func() {
|
||||
Ω(result).ShouldNot(ContainSubstring("GINKGO_VERSION"))
|
||||
Ω(result).ShouldNot(ContainSubstring("GINKGO_PANIC"))
|
||||
Ω(result).ShouldNot(ContainSubstring("GOMEGA_VERSION"))
|
||||
})
|
||||
})
|
||||
|
||||
It("should be idempotent (module empty lines - go fmt can fix those for us)", func() {
|
||||
first := apply("")
|
||||
second := apply(first)
|
||||
first = strings.Trim(first, "\n")
|
||||
second = strings.Trim(second, "\n")
|
||||
Ω(first).Should(Equal(second))
|
||||
})
|
||||
|
||||
It("should not mess with other things in the input", func() {
|
||||
result = apply("var MyThing = SomethingThatsMine")
|
||||
Ω(result).Should(ContainSubstring("var MyThing = SomethingThatsMine"))
|
||||
})
|
||||
|
||||
Context("when the user has redefined a name", func() {
|
||||
It("should honor the redefinition", func() {
|
||||
result = apply(`
|
||||
var _ = gomega.Ω
|
||||
var When = ginkgo.It
|
||||
`)
|
||||
|
||||
Ω(result).Should(ContainSubstring("var _ = gomega.Ω"))
|
||||
Ω(result).ShouldNot(ContainSubstring("var Ω = gomega.Ω"))
|
||||
|
||||
Ω(result).Should(ContainSubstring("var When = ginkgo.It"))
|
||||
Ω(result).ShouldNot(ContainSubstring("var It = ginkgo.It"))
|
||||
|
||||
Ω(result).Should(ContainSubstring("var Context = ginkgo.Context"))
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user