Commit 596df242 authored by Caleb Spare's avatar Caleb Spare Committed by Michael Hudson-Doyle

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: 's avatarIan Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
parent 033e3e10
......@@ -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) {
tg := testgo(t)
defer tg.cleanup()
tg.run("list", "-f", "GOARCH: {{context.GOARCH}}")
func TestListTemplateContextFunction(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment