vendor: Mega update all dependencies

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4080
This commit is contained in:
Jakob Borg
2017-04-05 14:34:41 +00:00
parent 49c1527724
commit a1bcc15458
1354 changed files with 55066 additions and 797850 deletions

View File

@@ -4,6 +4,7 @@ import (
"bytes"
"flag"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
@@ -15,10 +16,15 @@ import (
)
func BuildBootstrapCommand() *Command {
var agouti, noDot bool
var (
agouti, noDot, internal bool
customBootstrapFile string
)
flagSet := flag.NewFlagSet("bootstrap", flag.ExitOnError)
flagSet.BoolVar(&agouti, "agouti", false, "If set, bootstrap will generate a bootstrap file for writing Agouti tests")
flagSet.BoolVar(&noDot, "nodot", false, "If set, bootstrap will generate a bootstrap file that does not . import ginkgo and gomega")
flagSet.BoolVar(&internal, "internal", false, "If set, generate will generate a test file that uses the regular package name")
flagSet.StringVar(&customBootstrapFile, "template", "", "If specified, generate will use the contents of the file passed as the bootstrap template")
return &Command{
Name: "bootstrap",
@@ -29,12 +35,12 @@ func BuildBootstrapCommand() *Command {
"Accepts the following flags:",
},
Command: func(args []string, additionalArgs []string) {
generateBootstrap(agouti, noDot)
generateBootstrap(agouti, noDot, internal, customBootstrapFile)
},
}
}
var bootstrapText = `package {{.Package}}_test
var bootstrapText = `package {{.Package}}
import (
{{.GinkgoImport}}
@@ -49,7 +55,7 @@ func Test{{.FormattedName}}(t *testing.T) {
}
`
var agoutiBootstrapText = `package {{.Package}}_test
var agoutiBootstrapText = `package {{.Package}}
import (
{{.GinkgoImport}}
@@ -115,6 +121,14 @@ func prettifyPackageName(name string) string {
return name
}
func determinePackageName(name string, internal bool) string {
if internal {
return name
}
return name + "_test"
}
func fileExists(path string) bool {
_, err := os.Stat(path)
if err == nil {
@@ -123,10 +137,10 @@ func fileExists(path string) bool {
return false
}
func generateBootstrap(agouti bool, noDot bool) {
func generateBootstrap(agouti, noDot, internal bool, customBootstrapFile string) {
packageName, bootstrapFilePrefix, formattedName := getPackageAndFormattedName()
data := bootstrapData{
Package: packageName,
Package: determinePackageName(packageName, internal),
FormattedName: formattedName,
GinkgoImport: `. "github.com/onsi/ginkgo"`,
GomegaImport: `. "github.com/onsi/gomega"`,
@@ -153,7 +167,13 @@ func generateBootstrap(agouti bool, noDot bool) {
defer f.Close()
var templateText string
if agouti {
if customBootstrapFile != "" {
tpl, err := ioutil.ReadFile(customBootstrapFile)
if err != nil {
panic(err.Error())
}
templateText = string(tpl)
} else if agouti {
templateText = agoutiBootstrapText
} else {
templateText = bootstrapText

View File

@@ -46,7 +46,7 @@ func (r *SpecBuilder) BuildSpecs(args []string, additionalArgs []string) {
passed := true
for _, suite := range suites {
runner := testrunner.New(suite, 1, false, r.commandFlags.Race, r.commandFlags.Cover, r.commandFlags.CoverPkg, r.commandFlags.Tags, nil)
runner := testrunner.New(suite, 1, false, r.commandFlags.GoOpts, nil)
fmt.Printf("Compiling %s...\n", suite.PackageName)
path, _ := filepath.Abs(filepath.Join(suite.Path, fmt.Sprintf("%s.test", suite.PackageName)))

View File

@@ -10,10 +10,11 @@ import (
)
func BuildGenerateCommand() *Command {
var agouti, noDot bool
var agouti, noDot, internal bool
flagSet := flag.NewFlagSet("generate", flag.ExitOnError)
flagSet.BoolVar(&agouti, "agouti", false, "If set, generate will generate a test file for writing Agouti tests")
flagSet.BoolVar(&noDot, "nodot", false, "If set, generate will generate a test file that does not . import ginkgo and gomega")
flagSet.BoolVar(&internal, "internal", false, "If set, generate will generate a test file that uses the regular package name")
return &Command{
Name: "generate",
@@ -25,15 +26,15 @@ func BuildGenerateCommand() *Command {
"Accepts the following flags:",
},
Command: func(args []string, additionalArgs []string) {
generateSpec(args, agouti, noDot)
generateSpec(args, agouti, noDot, internal)
},
}
}
var specText = `package {{.Package}}_test
var specText = `package {{.Package}}
import (
. "{{.PackageImportPath}}"
{{if .DotImportPackage}}. "{{.PackageImportPath}}"{{end}}
{{if .IncludeImports}}. "github.com/onsi/ginkgo"{{end}}
{{if .IncludeImports}}. "github.com/onsi/gomega"{{end}}
@@ -47,7 +48,7 @@ var _ = Describe("{{.Subject}}", func() {
var agoutiSpecText = `package {{.Package}}_test
import (
. "{{.PackageImportPath}}"
{{if .DotImportPackage}}. "{{.PackageImportPath}}"{{end}}
{{if .IncludeImports}}. "github.com/onsi/ginkgo"{{end}}
{{if .IncludeImports}}. "github.com/onsi/gomega"{{end}}
@@ -75,11 +76,12 @@ type specData struct {
Subject string
PackageImportPath string
IncludeImports bool
DotImportPackage bool
}
func generateSpec(args []string, agouti, noDot bool) {
func generateSpec(args []string, agouti, noDot, internal bool) {
if len(args) == 0 {
err := generateSpecForSubject("", agouti, noDot)
err := generateSpecForSubject("", agouti, noDot, internal)
if err != nil {
fmt.Println(err.Error())
fmt.Println("")
@@ -91,7 +93,7 @@ func generateSpec(args []string, agouti, noDot bool) {
var failed bool
for _, arg := range args {
err := generateSpecForSubject(arg, agouti, noDot)
err := generateSpecForSubject(arg, agouti, noDot, internal)
if err != nil {
failed = true
fmt.Println(err.Error())
@@ -103,7 +105,7 @@ func generateSpec(args []string, agouti, noDot bool) {
}
}
func generateSpecForSubject(subject string, agouti, noDot bool) error {
func generateSpecForSubject(subject string, agouti, noDot, internal bool) error {
packageName, specFilePrefix, formattedName := getPackageAndFormattedName()
if subject != "" {
subject = strings.Split(subject, ".go")[0]
@@ -113,10 +115,11 @@ func generateSpecForSubject(subject string, agouti, noDot bool) error {
}
data := specData{
Package: packageName,
Package: determinePackageName(packageName, internal),
Subject: formattedName,
PackageImportPath: getPackageImportPath(),
IncludeImports: !noDot,
DotImportPackage: !internal,
}
targetFile := fmt.Sprintf("%s_test.go", specFilePrefix)

View File

@@ -9,7 +9,7 @@ func BuildHelpCommand() *Command {
return &Command{
Name: "help",
FlagSet: flag.NewFlagSet("help", flag.ExitOnError),
UsageCommand: "ginkgo help <COMAND>",
UsageCommand: "ginkgo help <COMMAND>",
Usage: []string{
"Print usage information. If a command is passed in, print usage information just for that command.",
},

View File

@@ -1,4 +1,4 @@
// +build freebsd openbsd netbsd dragonfly darwin linux
// +build freebsd openbsd netbsd dragonfly darwin linux solaris
package interrupthandler

View File

@@ -234,7 +234,7 @@ func complainAndQuit(complaint string) {
os.Exit(1)
}
func findSuites(args []string, recurse bool, skipPackage string, allowPrecompiled bool) ([]testsuite.TestSuite, []string) {
func findSuites(args []string, recurseForAll bool, skipPackage string, allowPrecompiled bool) ([]testsuite.TestSuite, []string) {
suites := []testsuite.TestSuite{}
if len(args) > 0 {
@@ -246,10 +246,15 @@ func findSuites(args []string, recurse bool, skipPackage string, allowPrecompile
continue
}
}
suites = append(suites, testsuite.SuitesInDir(arg, recurse)...)
recurseForSuite := recurseForAll
if strings.HasSuffix(arg, "/...") && arg != "/..." {
arg = arg[:len(arg)-4]
recurseForSuite = true
}
suites = append(suites, testsuite.SuitesInDir(arg, recurseForSuite)...)
}
} else {
suites = testsuite.SuitesInDir(".", recurse)
suites = testsuite.SuitesInDir(".", recurseForAll)
}
skippedPackages := []string{}

View File

@@ -1,91 +0,0 @@
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

View File

@@ -1,81 +0,0 @@
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"))
})
})
})

View File

@@ -71,7 +71,7 @@ func (r *SpecRunner) RunSpecs(args []string, additionalArgs []string) {
runners := []*testrunner.TestRunner{}
for _, suite := range suites {
runners = append(runners, testrunner.New(suite, r.commandFlags.NumCPU, r.commandFlags.ParallelStream, r.commandFlags.Race, r.commandFlags.Cover, r.commandFlags.CoverPkg, r.commandFlags.Tags, additionalArgs))
runners = append(runners, testrunner.New(suite, r.commandFlags.NumCPU, r.commandFlags.ParallelStream, r.commandFlags.GoOpts, additionalArgs))
}
numSuites := 0

View File

@@ -9,11 +9,8 @@ import (
type RunWatchAndBuildCommandFlags struct {
Recurse bool
Race bool
Cover bool
CoverPkg string
SkipPackage string
Tags string
GoOpts map[string]interface{}
//for run and watch commands
NumCPU int
@@ -87,15 +84,57 @@ func (c *RunWatchAndBuildCommandFlags) computeNodes() {
}
}
func (c *RunWatchAndBuildCommandFlags) stringSlot(slot string) *string {
var opt string
c.GoOpts[slot] = &opt
return &opt
}
func (c *RunWatchAndBuildCommandFlags) boolSlot(slot string) *bool {
var opt bool
c.GoOpts[slot] = &opt
return &opt
}
func (c *RunWatchAndBuildCommandFlags) intSlot(slot string) *int {
var opt int
c.GoOpts[slot] = &opt
return &opt
}
func (c *RunWatchAndBuildCommandFlags) flags(mode int) {
c.GoOpts = make(map[string]interface{})
onWindows := (runtime.GOOS == "windows")
c.FlagSet.BoolVar(&(c.Recurse), "r", false, "Find and run test suites under the current directory recursively")
c.FlagSet.BoolVar(&(c.Race), "race", false, "Run tests with race detection enabled")
c.FlagSet.BoolVar(&(c.Cover), "cover", false, "Run tests with coverage analysis, will generate coverage profiles with the package name in the current directory")
c.FlagSet.StringVar(&(c.CoverPkg), "coverpkg", "", "Run tests with coverage on the given external modules")
c.FlagSet.BoolVar(&(c.Recurse), "r", false, "Find and run test suites under the current directory recursively.")
c.FlagSet.BoolVar(c.boolSlot("race"), "race", false, "Run tests with race detection enabled.")
c.FlagSet.BoolVar(c.boolSlot("cover"), "cover", false, "Run tests with coverage analysis, will generate coverage profiles with the package name in the current directory.")
c.FlagSet.StringVar(c.stringSlot("coverpkg"), "coverpkg", "", "Run tests with coverage on the given external modules.")
c.FlagSet.StringVar(&(c.SkipPackage), "skipPackage", "", "A comma-separated list of package names to be skipped. If any part of the package's path matches, that package is ignored.")
c.FlagSet.StringVar(&(c.Tags), "tags", "", "A list of build tags to consider satisfied during the build")
c.FlagSet.StringVar(c.stringSlot("tags"), "tags", "", "A list of build tags to consider satisfied during the build.")
c.FlagSet.StringVar(c.stringSlot("gcflags"), "gcflags", "", "Arguments to pass on each go tool compile invocation.")
c.FlagSet.StringVar(c.stringSlot("covermode"), "covermode", "", "Set the mode for coverage analysis.")
c.FlagSet.BoolVar(c.boolSlot("a"), "a", false, "Force rebuilding of packages that are already up-to-date.")
c.FlagSet.BoolVar(c.boolSlot("n"), "n", false, "Have `go test` print the commands but do not run them.")
c.FlagSet.BoolVar(c.boolSlot("msan"), "msan", false, "Enable interoperation with memory sanitizer.")
c.FlagSet.BoolVar(c.boolSlot("x"), "x", false, "Have `go test` print the commands.")
c.FlagSet.BoolVar(c.boolSlot("work"), "work", false, "Print the name of the temporary work directory and do not delete it when exiting.")
c.FlagSet.StringVar(c.stringSlot("asmflags"), "asmflags", "", "Arguments to pass on each go tool asm invocation.")
c.FlagSet.StringVar(c.stringSlot("buildmode"), "buildmode", "", "Build mode to use. See 'go help buildmode' for more.")
c.FlagSet.StringVar(c.stringSlot("compiler"), "compiler", "", "Name of compiler to use, as in runtime.Compiler (gccgo or gc).")
c.FlagSet.StringVar(c.stringSlot("gccgoflags"), "gccgoflags", "", "Arguments to pass on each gccgo compiler/linker invocation.")
c.FlagSet.StringVar(c.stringSlot("installsuffix"), "installsuffix", "", "A suffix to use in the name of the package installation directory.")
c.FlagSet.StringVar(c.stringSlot("ldflags"), "ldflags", "", "Arguments to pass on each go tool link invocation.")
c.FlagSet.BoolVar(c.boolSlot("linkshared"), "linkshared", false, "Link against shared libraries previously created with -buildmode=shared.")
c.FlagSet.StringVar(c.stringSlot("pkgdir"), "pkgdir", "", "install and load all packages from the given dir instead of the usual locations.")
c.FlagSet.StringVar(c.stringSlot("toolexec"), "toolexec", "", "a program to use to invoke toolchain programs like vet and asm.")
c.FlagSet.IntVar(c.intSlot("blockprofilerate"), "blockprofilerate", 1, "Control the detail provided in goroutine blocking profiles by calling runtime.SetBlockProfileRate with the given value.")
c.FlagSet.StringVar(c.stringSlot("coverprofile"), "coverprofile", "", "Write a coverage profile to the specified file after all tests have passed.")
c.FlagSet.StringVar(c.stringSlot("cpuprofile"), "cpuprofile", "", "Write a CPU profile to the specified file before exiting.")
c.FlagSet.StringVar(c.stringSlot("memprofile"), "memprofile", "", "Write a memory profile to the specified file after all tests have passed.")
c.FlagSet.IntVar(c.intSlot("memprofilerate"), "memprofilerate", 0, "Enable more precise (and expensive) memory profiles by setting runtime.MemProfileRate.")
c.FlagSet.StringVar(c.stringSlot("outputdir"), "outputdir", "", "Place output files from profiling in the specified directory.")
if mode == runMode || mode == watchMode {
config.Flags(c.FlagSet, "", false)

View File

@@ -9,6 +9,7 @@ import (
"github.com/onsi/ginkgo/ginkgo/interrupthandler"
"github.com/onsi/ginkgo/ginkgo/testrunner"
"github.com/onsi/ginkgo/ginkgo/testsuite"
colorable "github.com/onsi/ginkgo/reporters/stenographer/support/go-colorable"
)
type compilationInput struct {
@@ -166,7 +167,7 @@ func (r *SuiteRunner) listFailedSuites(suitesThatFailed []testsuite.TestSuite) {
if config.DefaultReporterConfig.NoColor {
fmt.Printf("\t"+packageNameFormatter+" %s\n", suite.PackageName, suite.Path)
} else {
fmt.Printf("\t%s"+packageNameFormatter+"%s %s%s%s\n", redColor, suite.PackageName, defaultStyle, lightGrayColor, suite.Path, defaultStyle)
fmt.Fprintf(colorable.NewColorableStdout(), "\t%s"+packageNameFormatter+"%s %s%s%s\n", redColor, suite.PackageName, defaultStyle, lightGrayColor, suite.Path, defaultStyle)
}
}
}

View File

@@ -29,29 +29,23 @@ type TestRunner struct {
numCPU int
parallelStream bool
race bool
cover bool
coverPkg string
tags string
goOpts map[string]interface{}
additionalArgs []string
}
func New(suite testsuite.TestSuite, numCPU int, parallelStream bool, race bool, cover bool, coverPkg string, tags string, additionalArgs []string) *TestRunner {
func New(suite testsuite.TestSuite, numCPU int, parallelStream bool, goOpts map[string]interface{}, additionalArgs []string) *TestRunner {
runner := &TestRunner{
Suite: suite,
numCPU: numCPU,
parallelStream: parallelStream,
race: race,
cover: cover,
coverPkg: coverPkg,
tags: tags,
goOpts: goOpts,
additionalArgs: additionalArgs,
}
if !suite.Precompiled {
dir, err := ioutil.TempDir("", "ginkgo")
if err != nil {
panic(fmt.Sprintf("coulnd't create temporary directory... might be time to rm -rf:\n%s", err.Error()))
panic(fmt.Sprintf("couldn't create temporary directory... might be time to rm -rf:\n%s", err.Error()))
}
runner.compilationTargetPath = filepath.Join(dir, suite.PackageName+".test")
}
@@ -63,6 +57,70 @@ func (t *TestRunner) Compile() error {
return t.CompileTo(t.compilationTargetPath)
}
func (t *TestRunner) BuildArgs(path string) []string {
args := []string{"test", "-c", "-i", "-o", path, t.Suite.Path}
if *t.goOpts["covermode"].(*string) != "" {
args = append(args, "-cover", fmt.Sprintf("-covermode=%s", *t.goOpts["covermode"].(*string)))
} else {
if *t.goOpts["cover"].(*bool) || *t.goOpts["coverpkg"].(*string) != "" {
args = append(args, "-cover", "-covermode=atomic")
}
}
boolOpts := []string{
"a",
"n",
"msan",
"race",
"x",
"work",
"linkshared",
}
for _, opt := range boolOpts {
if s, found := t.goOpts[opt].(*bool); found && *s {
args = append(args, fmt.Sprintf("-%s", opt))
}
}
intOpts := []string{
"memprofilerate",
"blockprofilerate",
}
for _, opt := range intOpts {
if s, found := t.goOpts[opt].(*int); found {
args = append(args, fmt.Sprintf("-%s=%d", opt, *s))
}
}
stringOpts := []string{
"asmflags",
"buildmode",
"compiler",
"gccgoflags",
"installsuffix",
"ldflags",
"pkgdir",
"toolexec",
"coverprofile",
"cpuprofile",
"memprofile",
"outputdir",
"coverpkg",
"tags",
"gcflags",
}
for _, opt := range stringOpts {
if s, found := t.goOpts[opt].(*string); found && *s != "" {
args = append(args, fmt.Sprintf("-%s=%s", opt, *s))
}
}
return args
}
func (t *TestRunner) CompileTo(path string) error {
if t.compiled {
return nil
@@ -72,20 +130,7 @@ func (t *TestRunner) CompileTo(path string) error {
return nil
}
args := []string{"test", "-c", "-i", "-o", path, t.Suite.Path}
if t.race {
args = append(args, "-race")
}
if t.cover || t.coverPkg != "" {
args = append(args, "-cover", "-covermode=atomic")
}
if t.coverPkg != "" {
args = append(args, fmt.Sprintf("-coverpkg=%s", t.coverPkg))
}
if t.tags != "" {
args = append(args, fmt.Sprintf("-tags=%s", t.tags))
}
args := t.BuildArgs(path)
cmd := exec.Command("go", args...)
output, err := cmd.CombinedOutput()
@@ -184,6 +229,7 @@ fixCompilationOutput..... rewrites the output to fix the paths.
yeah......
*/
func fixCompilationOutput(output string, relToPath string) string {
relToPath = filepath.Join(relToPath)
re := regexp.MustCompile(`^(\S.*\.go)\:\d+\:`)
lines := strings.Split(output, "\n")
for i, line := range lines {
@@ -193,8 +239,10 @@ func fixCompilationOutput(output string, relToPath string) string {
}
path := line[indices[2]:indices[3]]
path = filepath.Join(relToPath, path)
lines[i] = path + line[indices[3]:]
if filepath.Dir(path) != relToPath {
path = filepath.Join(relToPath, path)
lines[i] = path + line[indices[3]:]
}
}
return strings.Join(lines, "\n")
}
@@ -276,7 +324,7 @@ func (t *TestRunner) runAndStreamParallelGinkgoSuite() RunResult {
os.Stdout.Sync()
if t.cover || t.coverPkg != "" {
if *t.goOpts["cover"].(*bool) || *t.goOpts["coverpkg"].(*string) != "" || *t.goOpts["covermode"].(*string) != "" {
t.combineCoverprofiles()
}
@@ -289,7 +337,7 @@ func (t *TestRunner) runParallelGinkgoSuite() RunResult {
writers := make([]*logWriter, t.numCPU)
reports := make([]*bytes.Buffer, t.numCPU)
stenographer := stenographer.New(!config.DefaultReporterConfig.NoColor)
stenographer := stenographer.New(!config.DefaultReporterConfig.NoColor, config.GinkgoConfig.FlakeAttempts > 1)
aggregator := remote.NewAggregator(t.numCPU, result, config.DefaultReporterConfig, stenographer)
server, err := remote.NewServer(t.numCPU)
@@ -344,7 +392,7 @@ func (t *TestRunner) runParallelGinkgoSuite() RunResult {
| |
-------------------------------------------------------------------
`)
fmt.Println(t.Suite.PackageName, "timed out. path:", t.Suite.Path)
os.Stdout.Sync()
for _, writer := range writers {
@@ -358,7 +406,7 @@ func (t *TestRunner) runParallelGinkgoSuite() RunResult {
os.Stdout.Sync()
}
if t.cover || t.coverPkg != "" {
if *t.goOpts["cover"].(*bool) || *t.goOpts["coverpkg"].(*string) != "" || *t.goOpts["covermode"].(*string) != "" {
t.combineCoverprofiles()
}
@@ -367,7 +415,7 @@ func (t *TestRunner) runParallelGinkgoSuite() RunResult {
func (t *TestRunner) cmd(ginkgoArgs []string, stream io.Writer, node int) *exec.Cmd {
args := []string{"--test.timeout=24h"}
if t.cover || t.coverPkg != "" {
if *t.goOpts["cover"].(*bool) || *t.goOpts["coverpkg"].(*string) != "" || *t.goOpts["covermode"].(*string) != "" {
coverprofile := "--test.coverprofile=" + t.Suite.PackageName + ".coverprofile"
if t.numCPU > 1 {
coverprofile = fmt.Sprintf("%s.%d", coverprofile, node)

View File

@@ -4,7 +4,6 @@ import (
"errors"
"io/ioutil"
"os"
"path"
"path/filepath"
"regexp"
"strings"
@@ -49,11 +48,7 @@ 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" {
if vendorExperimentCheck(dir) {
return suites
}

View File

@@ -1,13 +0,0 @@
package testsuite_test
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"testing"
)
func TestTestsuite(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Testsuite Suite")
}

View File

@@ -1,200 +0,0 @@
package testsuite_test
import (
"io/ioutil"
"os"
"path/filepath"
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/ginkgo/testsuite"
. "github.com/onsi/gomega"
)
var _ = Describe("TestSuite", func() {
var tmpDir string
var relTmpDir string
writeFile := func(folder string, filename string, content string, mode os.FileMode) {
path := filepath.Join(tmpDir, folder)
err := os.MkdirAll(path, 0700)
Ω(err).ShouldNot(HaveOccurred())
path = filepath.Join(path, filename)
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")
Ω(err).ShouldNot(HaveOccurred())
cwd, err := os.Getwd()
Ω(err).ShouldNot(HaveOccurred())
relTmpDir, err = filepath.Rel(cwd, tmpDir)
relTmpDir = "./" + relTmpDir
Ω(err).ShouldNot(HaveOccurred())
//go files in the root directory (no tests)
writeFile("/", "main.go", "package main", 0666)
//non-go files in a nested directory
writeFile("/redherring", "big_test.jpg", "package ginkgo", 0666)
//non-ginkgo tests in a nested directory
writeFile("/professorplum", "professorplum_test.go", `import "testing"`, 0666)
//ginkgo tests in a nested directory
writeFile("/colonelmustard", "colonelmustard_test.go", `import "github.com/onsi/ginkgo"`, 0666)
//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)
writeFile("/precompiled-dir", "nonexecutable.test", `fake-binary-file`, 0666)
})
AfterEach(func() {
os.RemoveAll(tmpDir)
})
Describe("Finding precompiled test suites", func() {
Context("if pointed at an executable file that ends with .test", func() {
It("should return a precompiled test suite", func() {
suite, err := PrecompiledTestSuite(filepath.Join(tmpDir, "precompiled-dir", "precompiled.test"))
Ω(err).ShouldNot(HaveOccurred())
Ω(suite).Should(Equal(TestSuite{
Path: relTmpDir + "/precompiled-dir",
PackageName: "precompiled",
IsGinkgo: true,
Precompiled: true,
}))
})
})
Context("if pointed at a directory", func() {
It("should error", func() {
suite, err := PrecompiledTestSuite(filepath.Join(tmpDir, "precompiled-dir"))
Ω(suite).Should(BeZero())
Ω(err).Should(HaveOccurred())
})
})
Context("if pointed at an executable that doesn't have .test", func() {
It("should error", func() {
suite, err := PrecompiledTestSuite(filepath.Join(tmpDir, "precompiled-dir", "some-other-binary"))
Ω(suite).Should(BeZero())
Ω(err).Should(HaveOccurred())
})
})
Context("if pointed at a .test that isn't executable", func() {
It("should error", func() {
suite, err := PrecompiledTestSuite(filepath.Join(tmpDir, "precompiled-dir", "nonexecutable.test"))
Ω(suite).Should(BeZero())
Ω(err).Should(HaveOccurred())
})
})
Context("if pointed at a nonexisting file", func() {
It("should error", func() {
suite, err := PrecompiledTestSuite(filepath.Join(tmpDir, "precompiled-dir", "nope-nothing-to-see-here"))
Ω(suite).Should(BeZero())
Ω(err).Should(HaveOccurred())
})
})
})
Describe("scanning for suites in a directory", func() {
Context("when there are no tests in the specified directory", func() {
It("should come up empty", func() {
suites := SuitesInDir(tmpDir, false)
Ω(suites).Should(BeEmpty())
})
})
Context("when there are ginkgo tests in the specified directory", func() {
It("should return an appropriately configured suite", func() {
suites := SuitesInDir(filepath.Join(tmpDir, "colonelmustard"), false)
Ω(suites).Should(HaveLen(1))
Ω(suites[0].Path).Should(Equal(relTmpDir + "/colonelmustard"))
Ω(suites[0].PackageName).Should(Equal("colonelmustard"))
Ω(suites[0].IsGinkgo).Should(BeTrue())
Ω(suites[0].Precompiled).Should(BeFalse())
})
})
Context("when there are non-ginkgo tests in the specified directory", func() {
It("should return an appropriately configured suite", func() {
suites := SuitesInDir(filepath.Join(tmpDir, "professorplum"), false)
Ω(suites).Should(HaveLen(1))
Ω(suites[0].Path).Should(Equal(relTmpDir + "/professorplum"))
Ω(suites[0].PackageName).Should(Equal("professorplum"))
Ω(suites[0].IsGinkgo).Should(BeFalse())
Ω(suites[0].Precompiled).Should(BeFalse())
})
})
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(4))
Ω(suites).Should(ContainElement(TestSuite{
Path: relTmpDir + "/colonelmustard",
PackageName: "colonelmustard",
IsGinkgo: true,
Precompiled: false,
}))
Ω(suites).Should(ContainElement(TestSuite{
Path: relTmpDir + "/professorplum",
PackageName: "professorplum",
IsGinkgo: false,
Precompiled: false,
}))
Ω(suites).Should(ContainElement(TestSuite{
Path: relTmpDir + "/colonelmustard/library",
PackageName: "library",
IsGinkgo: true,
Precompiled: false,
}))
})
})
})
})

View File

@@ -0,0 +1,16 @@
// +build !go1.6
package testsuite
import (
"os"
"path"
)
// "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
func vendorExperimentCheck(dir string) bool {
vendorExperiment := os.Getenv("GO15VENDOREXPERIMENT")
return vendorExperiment == "1" && path.Base(dir) == "vendor"
}

View File

@@ -0,0 +1,15 @@
// +build go1.6
package testsuite
import (
"os"
"path"
)
// in 1.6 the vendor directory became the default go behaviour, so now
// check if its disabled.
func vendorExperimentCheck(dir string) bool {
vendorExperiment := os.Getenv("GO15VENDOREXPERIMENT")
return vendorExperiment != "0" && path.Base(dir) == "vendor"
}

View File

@@ -10,6 +10,7 @@ import (
"github.com/onsi/ginkgo/ginkgo/testrunner"
"github.com/onsi/ginkgo/ginkgo/testsuite"
"github.com/onsi/ginkgo/ginkgo/watch"
colorable "github.com/onsi/ginkgo/reporters/stenographer/support/go-colorable"
)
func BuildWatchCommand() *Command {
@@ -57,7 +58,7 @@ func (w *SpecWatcher) runnersForSuites(suites []testsuite.TestSuite, additionalA
runners := []*testrunner.TestRunner{}
for _, suite := range suites {
runners = append(runners, testrunner.New(suite, w.commandFlags.NumCPU, w.commandFlags.ParallelStream, w.commandFlags.Race, w.commandFlags.Cover, w.commandFlags.CoverPkg, w.commandFlags.Tags, additionalArgs))
runners = append(runners, testrunner.New(suite, w.commandFlags.NumCPU, w.commandFlags.ParallelStream, w.commandFlags.GoOpts, additionalArgs))
}
return runners
@@ -96,29 +97,30 @@ func (w *SpecWatcher) WatchSuites(args []string, additionalArgs []string) {
case <-ticker.C:
suites, _ := findSuites(args, w.commandFlags.Recurse, w.commandFlags.SkipPackage, false)
delta, _ := deltaTracker.Delta(suites)
coloredStream := colorable.NewColorableStdout()
suitesToRun := []testsuite.TestSuite{}
if len(delta.NewSuites) > 0 {
fmt.Printf(greenColor+"Detected %d new %s:\n"+defaultStyle, len(delta.NewSuites), pluralizedWord("suite", "suites", len(delta.NewSuites)))
fmt.Fprintf(coloredStream, greenColor+"Detected %d new %s:\n"+defaultStyle, len(delta.NewSuites), pluralizedWord("suite", "suites", len(delta.NewSuites)))
for _, suite := range delta.NewSuites {
suitesToRun = append(suitesToRun, suite.Suite)
fmt.Println(" " + suite.Description())
fmt.Fprintln(coloredStream, " "+suite.Description())
}
}
modifiedSuites := delta.ModifiedSuites()
if len(modifiedSuites) > 0 {
fmt.Println(greenColor + "\nDetected changes in:" + defaultStyle)
fmt.Fprintln(coloredStream, greenColor+"\nDetected changes in:"+defaultStyle)
for _, pkg := range delta.ModifiedPackages {
fmt.Println(" " + pkg)
fmt.Fprintln(coloredStream, " "+pkg)
}
fmt.Printf(greenColor+"Will run %d %s:\n"+defaultStyle, len(modifiedSuites), pluralizedWord("suite", "suites", len(modifiedSuites)))
fmt.Fprintf(coloredStream, greenColor+"Will run %d %s:\n"+defaultStyle, len(modifiedSuites), pluralizedWord("suite", "suites", len(modifiedSuites)))
for _, suite := range modifiedSuites {
suitesToRun = append(suitesToRun, suite.Suite)
fmt.Println(" " + suite.Description())
fmt.Fprintln(coloredStream, " "+suite.Description())
}
fmt.Println("")
fmt.Fprintln(coloredStream, "")
}
if len(suitesToRun) > 0 {
@@ -136,7 +138,7 @@ func (w *SpecWatcher) WatchSuites(args []string, additionalArgs []string) {
if result.Passed {
color = greenColor
}
fmt.Println(color + "\nDone. Resuming watch..." + defaultStyle)
fmt.Fprintln(coloredStream, color+"\nDone. Resuming watch..."+defaultStyle)
}
}