From fdd819d88832bb7a12e57274b7523c1f16e2d91f Mon Sep 17 00:00:00 2001 From: Joe Stringer Date: Thu, 6 Sep 2018 11:49:57 -0700 Subject: [PATCH] Avoid using -i argument to go test for Golang 1.10+ Since Golang 1.10, this option should no longer be required: https://golang.org/doc/go1.10#build > The old advice to add the -i flag for speed, as in go build -i or go test -i, is no longer necessary: builds run just as fast without -i. For more details, see go help cache. Furthermore, it creates issues like the below when running ginkgo against a snap-installed version of Golang 1.10 on Ubuntu 18.04: $ ginkgo build Compiling test... Failed to compile test: go test runtime/cgo: open /snap/go/2130/pkg/linux_amd64/runtime/cgo.a: read-only file system --- ginkgo/testrunner/build_args.go | 7 +++++++ ginkgo/testrunner/build_args_old.go | 7 +++++++ ginkgo/testrunner/test_runner.go | 4 +++- ginkgo/testrunner/test_runner_test.go | 5 ++++- 4 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 ginkgo/testrunner/build_args.go create mode 100644 ginkgo/testrunner/build_args_old.go diff --git a/ginkgo/testrunner/build_args.go b/ginkgo/testrunner/build_args.go new file mode 100644 index 0000000000..3b1a238c2c --- /dev/null +++ b/ginkgo/testrunner/build_args.go @@ -0,0 +1,7 @@ +// +build go1.10 + +package testrunner + +var ( + buildArgs = []string{"test", "-c"} +) diff --git a/ginkgo/testrunner/build_args_old.go b/ginkgo/testrunner/build_args_old.go new file mode 100644 index 0000000000..14d70dbcc5 --- /dev/null +++ b/ginkgo/testrunner/build_args_old.go @@ -0,0 +1,7 @@ +// +build !go1.10 + +package testrunner + +var ( + buildArgs = []string{"test", "-c", "-i"} +) diff --git a/ginkgo/testrunner/test_runner.go b/ginkgo/testrunner/test_runner.go index 97a83145fa..a0113e1367 100644 --- a/ginkgo/testrunner/test_runner.go +++ b/ginkgo/testrunner/test_runner.go @@ -64,7 +64,9 @@ func (t *TestRunner) Compile() error { } func (t *TestRunner) BuildArgs(path string) []string { - args := []string{"test", "-c", "-i", "-o", path, t.Suite.Path} + args := make([]string, len(buildArgs), len(buildArgs)+3) + copy(args, buildArgs) + args = append(args, "-o", path, t.Suite.Path) if t.getCoverMode() != "" { args = append(args, "-cover", fmt.Sprintf("-covermode=%s", t.getCoverMode())) diff --git a/ginkgo/testrunner/test_runner_test.go b/ginkgo/testrunner/test_runner_test.go index b6f5567700..58d1fb094b 100644 --- a/ginkgo/testrunner/test_runner_test.go +++ b/ginkgo/testrunner/test_runner_test.go @@ -36,10 +36,13 @@ var _ = Describe("TestRunner", func() { tr := testrunner.New(testsuite.TestSuite{}, 1, false, 0, opts, []string{}) args := tr.BuildArgs(".") + // Remove the "-i" argument; This is discarded in Golang 1.10+. + if args[2] == "-i" { + args = append(args[0:2], args[4:]...) + } Ω(args).Should(Equal([]string{ "test", "-c", - "-i", "-o", ".", "",