Skip to content

Commit

Permalink
Avoid using -i argument to go test for Golang 1.10+
Browse files Browse the repository at this point in the history
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
  • Loading branch information
joestringer authored and Andrea Nodari committed Sep 13, 2018
1 parent 3774a09 commit 46bbc26
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
7 changes: 7 additions & 0 deletions ginkgo/testrunner/build_args.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// +build go1.10

package testrunner

var (
buildArgs = []string{"test", "-c"}
)
7 changes: 7 additions & 0 deletions ginkgo/testrunner/build_args_old.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// +build !go1.10

package testrunner

var (
buildArgs = []string{"test", "-c", "-i"}
)
4 changes: 3 additions & 1 deletion ginkgo/testrunner/test_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down
5 changes: 4 additions & 1 deletion ginkgo/testrunner/test_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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[3:]...)
}
Ω(args).Should(Equal([]string{
"test",
"-c",
"-i",
"-o",
".",
"",
Expand Down

0 comments on commit 46bbc26

Please sign in to comment.