Skip to content

Commit

Permalink
go/importer,os/exec: use testenv.GoToolPath
Browse files Browse the repository at this point in the history
These were the last two occurences of exec.Command("go", ...) in all of
std cmd. Checked with:

	gogrep '$(f is(func))("go", $*_)' std cmd

Also changed lp_windows_test to use a test package name to avoid a
circular dependency, since internal/testenv imports os/exec.

Change-Id: I9a18948600dfecc8507ad76172e219e78b791ffd
Reviewed-on: https://go-review.googlesource.com/87200
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
  • Loading branch information
mvdan committed Jan 10, 2018
1 parent c5d744a commit c203696
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/go/importer/importer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestFor(t *testing.T) {
testenv.MustHaveGoBuild(t)

const thePackage = "math/big"
out, err := exec.Command("go", "list", "-f={{context.Compiler}}:{{.Target}}", thePackage).CombinedOutput()
out, err := exec.Command(testenv.GoToolPath(t), "list", "-f={{context.Compiler}}:{{.Target}}", thePackage).CombinedOutput()
if err != nil {
t.Fatalf("go list %s: %v\n%s", thePackage, err, out)
}
Expand Down
13 changes: 9 additions & 4 deletions src/os/exec/lp_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package exec
// Use an external test to avoid os/exec -> internal/testenv -> os/exec
// circular dependency.

package exec_test

import (
"fmt"
"internal/testenv"
"io"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"strconv"
"strings"
Expand Down Expand Up @@ -63,7 +68,7 @@ type lookPathTest struct {
}

func (test lookPathTest) runProg(t *testing.T, env []string, args ...string) (string, error) {
cmd := Command(args[0], args[1:]...)
cmd := exec.Command(args[0], args[1:]...)
cmd.Env = env
cmd.Dir = test.rootDir
args[0] = filepath.Base(args[0])
Expand Down Expand Up @@ -346,7 +351,7 @@ func (test commandTest) isSuccess(rootDir, output string, err error) error {
}

func (test commandTest) runOne(rootDir string, env []string, dir, arg0 string) error {
cmd := Command(os.Args[0], "-test.run=TestHelperProcess", "--", "exec", dir, arg0)
cmd := exec.Command(os.Args[0], "-test.run=TestHelperProcess", "--", "exec", dir, arg0)
cmd.Dir = rootDir
cmd.Env = env
output, err := cmd.CombinedOutput()
Expand Down Expand Up @@ -532,7 +537,7 @@ func buildPrintPathExe(t *testing.T, dir string) string {
t.Fatalf("failed to execute template: %v", err)
}
outname := name + ".exe"
cmd := Command("go", "build", "-o", outname, srcname)
cmd := exec.Command(testenv.GoToolPath(t), "build", "-o", outname, srcname)
cmd.Dir = dir
out, err := cmd.CombinedOutput()
if err != nil {
Expand Down

0 comments on commit c203696

Please sign in to comment.