mirror of https://github.com/golang/go.git
cmd/go: set GOPATH in list's Context
Fixes #14547. Change-Id: Ic175ee8f7e65b9b99f1f47fbf267a2aba7c8fec7 Reviewed-on: https://go-review.googlesource.com/20010 Run-TryBot: Caleb Spare <cespare@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
033e3e106e
commit
596df2424d
|
|
@ -26,6 +26,7 @@ func newContext(c *build.Context) *Context {
|
|||
GOARCH: c.GOARCH,
|
||||
GOOS: c.GOOS,
|
||||
GOROOT: c.GOROOT,
|
||||
GOPATH: c.GOPATH,
|
||||
CgoEnabled: c.CgoEnabled,
|
||||
UseAllFiles: c.UseAllFiles,
|
||||
Compiler: c.Compiler,
|
||||
|
|
|
|||
|
|
@ -2105,10 +2105,33 @@ func main() { C.f() }`)
|
|||
tg.grepStderr(`gccgo.*\-L alibpath \-lalib`, `no Go-inline "#cgo LDFLAGS:" ("-L alibpath -lalib") passed to gccgo linking stage`)
|
||||
}
|
||||
|
||||
func TestListTemplateCanUseContextFunction(t *testing.T) {
|
||||
func TestListTemplateContextFunction(t *testing.T) {
|
||||
tg := testgo(t)
|
||||
defer tg.cleanup()
|
||||
tg.run("list", "-f", "GOARCH: {{context.GOARCH}}")
|
||||
for _, tt := range []struct {
|
||||
v string
|
||||
want string
|
||||
}{
|
||||
{"GOARCH", runtime.GOARCH},
|
||||
{"GOOS", runtime.GOOS},
|
||||
{"GOROOT", filepath.Clean(runtime.GOROOT())},
|
||||
{"GOPATH", os.Getenv("GOPATH")},
|
||||
{"CgoEnabled", ""},
|
||||
{"UseAllFiles", ""},
|
||||
{"Compiler", ""},
|
||||
{"BuildTags", ""},
|
||||
{"ReleaseTags", ""},
|
||||
{"InstallSuffix", ""},
|
||||
} {
|
||||
tmpl := "{{context." + tt.v + "}}"
|
||||
tg.run("list", "-f", tmpl)
|
||||
if tt.want == "" {
|
||||
continue
|
||||
}
|
||||
if got := strings.TrimSpace(tg.getStdout()); got != tt.want {
|
||||
t.Errorf("go list -f %q: got %q; want %q", tmpl, got, tt.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// cmd/go: "go test" should fail if package does not build
|
||||
|
|
|
|||
Loading…
Reference in New Issue