From 77106db15f689a60e7d4e085d967ac557b918fb2 Mon Sep 17 00:00:00 2001 From: Yury Smolsky Date: Fri, 23 Mar 2018 13:59:17 +0200 Subject: [PATCH] cmd/godoc: fix TestWebIndex test The godoc in the test was indexing sources in the default GOPATH. If the default GOPATH pointed to local workspace, test would timeout. The fix is to supply GOPATH set to non-existing path. Fixes golang/go#24504 Change-Id: Iedf044cdec78d5c5642105650ad8ec17aa10a5ba Reviewed-on: https://go-review.googlesource.com/102295 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- cmd/godoc/godoc_test.go | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) 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 -}