Skip to content
This repository has been archived by the owner on Jan 2, 2025. It is now read-only.

Commit

Permalink
feat: Allow overriding go test binary (#14)
Browse files Browse the repository at this point in the history
Closes #4
  • Loading branch information
aeneasr authored Feb 16, 2020
1 parent 61e64c9 commit ec156ff
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ $ go-acc --ignore pkga,pkgb .
You can pass all flags defined by "go test" after "--":
$ go-acc . -- -short -v -failfast
You can pick an alternative go test binary using:
GO_TEST_BINARY="go test"
GO_TEST_BINARY="gotest"
`,
Run: func(cmd *cobra.Command, args []string) {
mode := flagx.MustGetString(cmd, "covermode")
Expand Down Expand Up @@ -94,17 +99,28 @@ $ go-acc . -- -short -v -failfast
files := make([]string, len(packages))
for k, pkg := range packages {
files[k] = filepath.Join(os.TempDir(), uuid.New()) + ".cc.tmp"

gotest := os.Getenv("GO_TEST_BINARY")
if gotest == "" {
gotest = "go test"
}

gt := strings.Split(gotest, " ")
if len(gt) != 2 {
gt = append(gt, "")
}

var c *exec.Cmd
ca := append(append(
[]string{
"test",
gt[1],
"-covermode=" + mode,
"-coverprofile=" + files[k],
"-coverpkg=" + strings.Join(packages, ","),
},
passthrough...),
pkg)
c = exec.Command("go", ca...)
c = exec.Command(gt[0], ca...)

stderr, err := c.StderrPipe()
if err != nil {
Expand Down

0 comments on commit ec156ff

Please sign in to comment.