mirror of
https://github.com/golang/go.git
synced 2025-05-05 23:53:05 +00: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:
parent
73e16cff9e
commit
9f6d4ad827
@ -8,7 +8,6 @@ import (
|
|||||||
"go/build"
|
"go/build"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
|
||||||
"runtime"
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -18,7 +17,7 @@ import (
|
|||||||
func TestContainingPackage(t *testing.T) {
|
func TestContainingPackage(t *testing.T) {
|
||||||
// unvirtualized:
|
// unvirtualized:
|
||||||
goroot := runtime.GOROOT()
|
goroot := runtime.GOROOT()
|
||||||
gopath := filepath.SplitList(os.Getenv("GOPATH"))[0]
|
gopath := gopathContainingTools(t)
|
||||||
|
|
||||||
type Test struct {
|
type Test struct {
|
||||||
gopath, filename, wantPkg string
|
gopath, filename, wantPkg string
|
||||||
@ -70,3 +69,13 @@ func TestContainingPackage(t *testing.T) {
|
|||||||
|
|
||||||
// TODO(adonovan): test on virtualized GOPATH too.
|
// 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
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user