diff --git a/cmd/godoc/godoc_test.go b/cmd/godoc/godoc_test.go index a2552d9dd7..82ed1e87bc 100644 --- a/cmd/godoc/godoc_test.go +++ b/cmd/godoc/godoc_test.go @@ -236,7 +236,12 @@ func testWeb(t *testing.T, withIndex bool) { cmd.Stdout = os.Stderr cmd.Stderr = os.Stderr cmd.Args[0] = "godoc" - cmd.Env = godocEnv() + + // Set GOPATH variable to non-existing path. + // We cannot just unset GOPATH variable because godoc would default it to ~/go. + // (We don't want the indexer looking at the local workspace during tests.) + cmd.Env = append(os.Environ(), "GOPATH=does_not_exist") + if err := cmd.Start(); err != nil { t.Fatalf("failed to start godoc: %s", err) } @@ -390,14 +395,9 @@ func main() { print(lib.V) } defer cleanup() addr := serverAddress(t) cmd := exec.Command(bin, fmt.Sprintf("-http=%s", addr), "-analysis=type") + cmd.Env = os.Environ() cmd.Env = append(cmd.Env, fmt.Sprintf("GOROOT=%s", filepath.Join(tmpdir, "goroot"))) cmd.Env = append(cmd.Env, fmt.Sprintf("GOPATH=%s", filepath.Join(tmpdir, "gopath"))) - for _, e := range os.Environ() { - if strings.HasPrefix(e, "GOROOT=") || strings.HasPrefix(e, "GOPATH=") { - continue - } - cmd.Env = append(cmd.Env, e) - } cmd.Stdout = os.Stderr stderr, err := cmd.StderrPipe() if err != nil { @@ -475,15 +475,3 @@ tryagain: } } } - -// godocEnv returns the process environment without the GOPATH variable. -// (We don't want the indexer looking at the local workspace during tests.) -func godocEnv() (env []string) { - for _, v := range os.Environ() { - if strings.HasPrefix(v, "GOPATH=") { - continue - } - env = append(env, v) - } - return -}