diff --git a/misc/cgo/testshared/shared_test.go b/misc/cgo/testshared/shared_test.go index b9ef6dad8e24cb..c7f15b8e8916f6 100644 --- a/misc/cgo/testshared/shared_test.go +++ b/misc/cgo/testshared/shared_test.go @@ -105,6 +105,8 @@ func testMain(m *testing.M) (int, error) { fmt.Printf("+ cd %s\n", modRoot) } os.Setenv("GOPATH", gopath) + // Explicitly override GOBIN as well, in case it was set through a GOENV file. + os.Setenv("GOBIN", filepath.Join(gopath, "bin")) os.Chdir(modRoot) os.Setenv("PWD", modRoot) @@ -153,10 +155,6 @@ func TestMain(m *testing.M) { log.SetFlags(log.Lshortfile) flag.Parse() - // Some of the tests install binaries into a custom GOPATH. - // That won't work if GOBIN is set. - os.Unsetenv("GOBIN") - exitCode, err := testMain(m) if err != nil { log.Fatal(err)