return err2
}
+// TestExecutableGOROOT verifies that the cmd/go binary itself uses
+// os.Executable (when available) to locate GOROOT.
func TestExecutableGOROOT(t *testing.T) {
skipIfGccgo(t, "gccgo has no GOROOT")
- if runtime.GOOS == "openbsd" {
- t.Skipf("test case does not work on %s, missing os.Executable", runtime.GOOS)
- }
- // Env with no GOROOT.
- var env []string
- for _, e := range os.Environ() {
- if !strings.HasPrefix(e, "GOROOT=") {
- env = append(env, e)
- }
- }
+ // Note: Must not call tg methods inside subtests: tg is attached to outer t.
+ tg := testgo(t)
+ tg.unsetenv("GOROOT")
+ defer tg.cleanup()
check := func(t *testing.T, exe, want string) {
cmd := exec.Command(exe, "env", "GOROOT")
- cmd.Env = env
+ cmd.Env = tg.env
out, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("%s env GOROOT: %v, %s", exe, err, out)
}
}
- // Note: Must not call tg methods inside subtests: tg is attached to outer t.
- tg := testgo(t)
- defer tg.cleanup()
-
tg.makeTempdir()
tg.tempDir("new/bin")
newGoTool := tg.path("new/bin/go" + exeSuffix)
}
cmd := exec.Command(newGoTool, "run", "testdata/print_goroot.go")
- cmd.Env = env
- out, err := cmd.CombinedOutput()
+ cmd.Env = tg.env
+ cmd.Stderr = os.Stderr
+ out, err := cmd.Output()
if err != nil {
t.Fatalf("%s run testdata/print_goroot.go: %v, %s", newGoTool, err, out)
}