summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Randall <khr@golang.org>2022-07-19 15:35:51 -0700
committerKeith Randall <khr@google.com>2022-07-20 23:29:03 +0000
commitdf38614bd7f233f36a3f5ac07f0ec9029043243f (patch)
tree1cc96a0fed929bfd415e08a7d4a08559d0c513a9
parentbb1749ba3bfaa6912d79904dad5e29e6ea624d29 (diff)
downloadgo-git-df38614bd7f233f36a3f5ac07f0ec9029043243f.tar.gz
test: use go tool from tree, not path
Some of our tests do exec.Command("go", "tool", "compile", ...) or similar. That "go" is selected from PATH. When run.go is started from the command line (but not from all.bash), the first "go" is whatever happens to be first in the user's path (some random older version than tip). We really want all these tests to use the "go" tool from the source tree under test. Add GOROOT/bin to the front of the path to ensure that the tools we use come from the source tree under test. Change-Id: I609261a4add8cd5cb228316752d52b5499aec963 Reviewed-on: https://go-review.googlesource.com/c/go/+/418474 Run-TryBot: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
-rw-r--r--test/run.go18
1 files changed, 17 insertions, 1 deletions
diff --git a/test/run.go b/test/run.go
index cb1622ccc9..b2902f190c 100644
--- a/test/run.go
+++ b/test/run.go
@@ -58,7 +58,7 @@ type envVars struct {
}
var env = func() (res envVars) {
- cmd := exec.Command("go", "env", "-json")
+ cmd := exec.Command(goTool(), "env", "-json")
stdout, err := cmd.StdoutPipe()
if err != nil {
log.Fatal("StdoutPipe:", err)
@@ -710,6 +710,22 @@ func (t *test) run() {
if tempDirIsGOPATH {
cmd.Env = append(cmd.Env, "GOPATH="+t.tempDir)
}
+ // Put the bin directory of the GOROOT that built this program
+ // first in the path. This ensures that tests that use the "go"
+ // tool use the same one that built this program. This ensures
+ // that if you do "../bin/go run run.go" in this directory, all
+ // the tests that start subprocesses that "go tool compile" or
+ // whatever, use ../bin/go as their go tool, not whatever happens
+ // to be first in the user's path.
+ path := os.Getenv("PATH")
+ newdir := filepath.Join(runtime.GOROOT(), "bin")
+ if path != "" {
+ path = newdir + string(filepath.ListSeparator) + path
+ } else {
+ path = newdir
+ }
+ cmd.Env = append(cmd.Env, "PATH="+path)
+
cmd.Env = append(cmd.Env, runenv...)
var err error