Skip to content

Commit c5094cc

Browse files
committed
internal/imports: a step towards making tests hermetic
If an import test unsets GOROOT, the code looks in the directory /src, which is usually harmless, but undesirable. That is, it should be possible for tests to prevent the code from looking anywhere but inside the constructed test environment. This CL is one step towards that goal. Change-Id: If14307f653c2b549c5b791a0fbce78c18ce348a4 Reviewed-on: https://go-review.googlesource.com/c/tools/+/579035 Reviewed-by: Robert Findley <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 5e04895 commit c5094cc

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

internal/imports/mod.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,9 @@ func newModuleResolver(e *ProcessEnv, moduleCacheCache *DirInfoCache) (*ModuleRe
166166
return count(j) < count(i) // descending order
167167
})
168168

169-
r.roots = []gopathwalk.Root{
170-
{Path: filepath.Join(goenv["GOROOT"], "/src"), Type: gopathwalk.RootGOROOT},
169+
r.roots = []gopathwalk.Root{}
170+
if goenv["GOROOT"] != "" { // "" happens in tests
171+
r.roots = append(r.roots, gopathwalk.Root{Path: filepath.Join(goenv["GOROOT"], "/src"), Type: gopathwalk.RootGOROOT})
171172
}
172173
r.mainByDir = make(map[string]*gocommand.ModuleJSON)
173174
for _, main := range r.mains {

0 commit comments

Comments
 (0)