]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: set GOPATH in list's Context
authorCaleb Spare <cespare@gmail.com>
Sun, 28 Feb 2016 09:11:23 +0000 (01:11 -0800)
committerMichael Hudson-Doyle <michael.hudson@canonical.com>
Thu, 3 Mar 2016 09:09:16 +0000 (09:09 +0000)
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>

src/cmd/go/context.go
src/cmd/go/go_test.go

index 0a0169eb9c0d97c341146aa843f52ee1cba65aca..94cd54d00d8a474057ab1e6d974533b858e1c739 100644 (file)
@@ -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,
index aa0016ad1e54e658f13d759be24c3699741f7fcd..2af715a3a46397060a44b556d8d0a5201054ce47 100644 (file)
@@ -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