tools/go/packages
Daniel Martí c3e1567727 go/packages: make tests pass with custom GOCACHE
This commit was merged earlier with some failing trybots, so it was
reverted. This is a re-submission.

Before this change, a test would fail:

	$ GOCACHE=$HOME/go/cache go test
	--- FAIL: TestLoadImportsGraph (0.36s)
	    --- FAIL: TestLoadImportsGraph/GOPATH (0.19s)
		packages_test.go:191: golang.org/fake/subdir/d.test.Srcs = [4302876da86a8aae0c1669924daa223cafca60ef49ccaa060ae37e778d18f218-d], want [0.go]
	    --- FAIL: TestLoadImportsGraph/Modules (0.17s)
		packages_test.go:191: golang.org/fake/subdir/d.test.Srcs = [4302876da86a8aae0c1669924daa223cafca60ef49ccaa060ae37e778d18f218-d], want [0.go]
	FAIL

This is because it assumed that the user hadn't set their own GOCACHE,
and thus that all source files in the cache would be under the default
"go-build" cache directory.

We could fix this via os.Getenv("GOCACHE"), but a simpler mechanism is
to see if the source file has an extension. Source files don't have an
extension in GOCACHE, so that's much simpler to detect.

After this change:

	$ GOCACHE=$HOME/go/cache go test
	PASS

golist_fallback.go also had a bit of code to add "/go-build/" to the
added testmain.go path, to trick the tests on Go 1.10 to think the file
was in GOCACHE. Update that code too, to now not add ".go" to the path
instead.

While at it, gofmt.

Fixes golang/go#29445.

Change-Id: I21fc59f13f00bea1f9a8a80e0438825f1a36ac3e
Reviewed-on: https://go-review.googlesource.com/c/156977
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2019-01-16 20:24:37 +00:00
..
gopackages go/package/gopackages: update gopackages to use the new tool library for its main function 2019-01-08 19:17:02 +00:00
packagestest go/packages/packagestest: make temp directory writeable 2019-01-04 18:20:27 +00:00
testdata go/packages: add name= query 2018-10-16 20:20:09 +00:00
doc.go Remove warning stability warning 2019-01-08 19:38:35 +00:00
example_test.go go/packages: remove the Config.Error hook 2018-09-04 20:52:37 +00:00
external.go go/packages: use packagesdriver to fetch sizes for "go list" 2018-12-19 20:36:29 +00:00
golist.go go/packages: Load with no patterns should load "." 2019-01-10 21:10:28 +00:00
golist_fallback.go go/packages: make tests pass with custom GOCACHE 2019-01-16 20:24:37 +00:00
golist_fallback_testmain.go go/packages: add missing test variants to fallback loader 2018-09-25 16:56:39 +00:00
golist_overlay.go go/packages: check for containing files after overlay is processed 2018-12-06 19:48:17 +00:00
packages.go go/packages: rename Illtyped to IllTyped in docs 2019-01-14 16:46:48 +00:00
packages110_test.go go/packages: generate test main files from the golist fallback 2018-09-17 22:19:12 +00:00
packages_test.go go/packages: make tests pass with custom GOCACHE 2019-01-16 20:24:37 +00:00
packagescgo_test.go go/...: use recommended issue tracker URLs 2018-12-05 01:41:16 +00:00
stdlib_test.go go/...: use recommended issue tracker URLs 2018-12-05 01:41:16 +00:00
visit.go go/packages: make visit order stable 2018-11-02 02:37:01 +00:00