return p
}
+// goTool reports the path of the go tool to use to run the tests.
+// If possible, use the same Go used to run run.go, otherwise
+// fallback to the go version found in the PATH.
+func goTool() string {
+ var exeSuffix string
+ if runtime.GOOS == "windows" {
+ exeSuffix = ".exe"
+ }
+ path := filepath.Join(runtime.GOROOT(), "bin", "go"+exeSuffix)
+ if _, err := os.Stat(path); err == nil {
+ return path
+ }
+ // Just run "go" from PATH
+ return "go"
+}
+
func shardMatch(name string) bool {
if *shards == 0 {
return true
type runCmd func(...string) ([]byte, error)
func compileFile(runcmd runCmd, longname string, flags []string) (out []byte, err error) {
- cmd := []string{"go", "tool", "compile", "-e"}
+ cmd := []string{goTool(), "tool", "compile", "-e"}
cmd = append(cmd, flags...)
if *linkshared {
cmd = append(cmd, "-dynlink", "-installsuffix=dynlink")
}
func compileInDir(runcmd runCmd, dir string, flags []string, names ...string) (out []byte, err error) {
- cmd := []string{"go", "tool", "compile", "-e", "-D", ".", "-I", "."}
+ cmd := []string{goTool(), "tool", "compile", "-e", "-D", ".", "-I", "."}
cmd = append(cmd, flags...)
if *linkshared {
cmd = append(cmd, "-dynlink", "-installsuffix=dynlink")
func linkFile(runcmd runCmd, goname string) (err error) {
pfile := strings.Replace(goname, ".go", ".o", -1)
- cmd := []string{"go", "tool", "link", "-w", "-o", "a.exe", "-L", "."}
+ cmd := []string{goTool(), "tool", "link", "-w", "-o", "a.exe", "-L", "."}
if *linkshared {
cmd = append(cmd, "-linkshared", "-installsuffix=dynlink")
}
os.Setenv("GOOS", "linux")
os.Setenv("GOARCH", arch)
- cmdline := []string{"go", "build", "-gcflags", "-S"}
+ cmdline := []string{goTool(), "build", "-gcflags", "-S"}
cmdline = append(cmdline, flags...)
cmdline = append(cmdline, long)
out, err := runcmd(cmdline...)
case "errorcheck":
// TODO(gri) remove need for -C (disable printing of columns in error messages)
- cmdline := []string{"go", "tool", "compile", "-C", "-e", "-o", "a.o"}
+ cmdline := []string{goTool(), "tool", "compile", "-C", "-e", "-o", "a.o"}
// No need to add -dynlink even if linkshared if we're just checking for errors...
cmdline = append(cmdline, flags...)
cmdline = append(cmdline, long)
}
case "build":
- _, err := runcmd("go", "build", goGcflags(), "-o", "a.exe", long)
+ _, err := runcmd(goTool(), "build", goGcflags(), "-o", "a.exe", long)
if err != nil {
t.err = err
}
}
var objs []string
- cmd := []string{"go", "tool", "compile", "-e", "-D", ".", "-I", ".", "-o", "go.o"}
+ cmd := []string{goTool(), "tool", "compile", "-e", "-D", ".", "-I", ".", "-o", "go.o"}
if len(asms) > 0 {
cmd = append(cmd, "-asmhdr", "go_asm.h")
}
}
objs = append(objs, "go.o")
if len(asms) > 0 {
- cmd = []string{"go", "tool", "asm", "-e", "-I", ".", "-o", "asm.o"}
+ cmd = []string{goTool(), "tool", "asm", "-e", "-I", ".", "-o", "asm.o"}
for _, file := range asms {
cmd = append(cmd, filepath.Join(longdir, file.Name()))
}
}
objs = append(objs, "asm.o")
}
- cmd = []string{"go", "tool", "pack", "c", "all.a"}
+ cmd = []string{goTool(), "tool", "pack", "c", "all.a"}
cmd = append(cmd, objs...)
_, err = runcmd(cmd...)
if err != nil {
t.err = err
break
}
- cmd = []string{"go", "tool", "link", "-o", "a.exe", "all.a"}
+ cmd = []string{goTool(), "tool", "link", "-o", "a.exe", "all.a"}
_, err = runcmd(cmd...)
if err != nil {
t.err = err
case "buildrun": // build binary, then run binary, instead of go run. Useful for timeout tests where failure mode is infinite loop.
// TODO: not supported on NaCl
useTmp = true
- cmd := []string{"go", "build", goGcflags(), "-o", "a.exe"}
+ cmd := []string{goTool(), "build", goGcflags(), "-o", "a.exe"}
if *linkshared {
cmd = append(cmd, "-linkshared")
}
// Because we run lots of trivial test programs,
// the time adds up.
pkg := filepath.Join(t.tempDir, "pkg.a")
- if _, err := runcmd("go", "tool", "compile", "-o", pkg, t.goFileName()); err != nil {
+ if _, err := runcmd(goTool(), "tool", "compile", "-o", pkg, t.goFileName()); err != nil {
t.err = err
return
}
exe := filepath.Join(t.tempDir, "test.exe")
- cmd := []string{"go", "tool", "link", "-s", "-w"}
+ cmd := []string{goTool(), "tool", "link", "-s", "-w"}
cmd = append(cmd, "-o", exe, pkg)
if _, err := runcmd(cmd...); err != nil {
t.err = err
}
out, err = runcmd(append([]string{exe}, args...)...)
} else {
- cmd := []string{"go", "run", goGcflags()}
+ cmd := []string{goTool(), "run", goGcflags()}
if *linkshared {
cmd = append(cmd, "-linkshared")
}
<-rungatec
}()
useTmp = false
- cmd := []string{"go", "run", goGcflags()}
+ cmd := []string{goTool(), "run", goGcflags()}
if *linkshared {
cmd = append(cmd, "-linkshared")
}
t.err = fmt.Errorf("write tempfile:%s", err)
return
}
- cmd = []string{"go", "run", goGcflags()}
+ cmd = []string{goTool(), "run", goGcflags()}
if *linkshared {
cmd = append(cmd, "-linkshared")
}
case "errorcheckoutput":
useTmp = false
- cmd := []string{"go", "run", goGcflags()}
+ cmd := []string{goTool(), "run", goGcflags()}
if *linkshared {
cmd = append(cmd, "-linkshared")
}
t.err = fmt.Errorf("write tempfile:%s", err)
return
}
- cmdline := []string{"go", "tool", "compile", "-e", "-o", "a.o"}
+ cmdline := []string{goTool(), "tool", "compile", "-e", "-o", "a.o"}
cmdline = append(cmdline, flags...)
cmdline = append(cmdline, tfile)
out, err = runcmd(cmdline...)
return
}
// Polish.
- exec.Command("go", "fmt", file).CombinedOutput()
+ exec.Command(goTool(), "fmt", file).CombinedOutput()
}
// matchPrefix reports whether s is of the form ^(.*/)?prefix(:|[),