1
0
mirror of https://github.com/golang/go synced 2024-09-30 16:18:35 -06:00

go/buildutil: use build.Import to find GOPATH containing x/tools

Previously, the test assumed that golang.org/x/tools was always in the
first GOPATH workspace. It may not be. Find it dynamically instead.

Fixes golang/go#19400.

Change-Id: I9c75d5ff1409aebd403d7ad4314b496fe1a04140
Reviewed-on: https://go-review.googlesource.com/94900
Run-TryBot: Dmitri Shuralyov <dmitri@shuralyov.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
This commit is contained in:
Dmitri Shuralyov 2018-02-17 02:00:07 -05:00 committed by Alan Donovan
parent 73e16cff9e
commit 9f6d4ad827

View File

@ -8,7 +8,6 @@ import (
"go/build"
"io/ioutil"
"os"
"path/filepath"
"runtime"
"testing"
@ -18,7 +17,7 @@ import (
func TestContainingPackage(t *testing.T) {
// unvirtualized:
goroot := runtime.GOROOT()
gopath := filepath.SplitList(os.Getenv("GOPATH"))[0]
gopath := gopathContainingTools(t)
type Test struct {
gopath, filename, wantPkg string
@ -70,3 +69,13 @@ func TestContainingPackage(t *testing.T) {
// TODO(adonovan): test on virtualized GOPATH too.
}
// gopathContainingTools returns the path of the GOPATH workspace
// with golang.org/x/tools, or fails the test if it can't locate it.
func gopathContainingTools(t *testing.T) string {
p, err := build.Import("golang.org/x/tools", "", build.FindOnly)
if err != nil {
t.Fatal(err)
}
return p.Root
}