imports: allow dirPackageInfo to be overridden
Change-Id: Ie90d2681e364e2a3f905675db266cb8960e08277
Reviewed-on: https://go-review.googlesource.com/39995
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
diff --git a/imports/fix.go b/imports/fix.go
index 1387c99..61a5f06 100644
--- a/imports/fix.go
+++ b/imports/fix.go
@@ -73,8 +73,11 @@
Globals map[string]bool // symbol => true
}
-// dirPackageInfo gets information from other files in the package.
-func dirPackageInfo(srcDir, filename string) (*packageInfo, error) {
+// dirPackageInfo exposes the dirPackageInfoFile function so that it can be overridden.
+var dirPackageInfo = dirPackageInfoFile
+
+// dirPackageInfoFile gets information from other files in the package.
+func dirPackageInfoFile(pkgName, srcDir, filename string) (*packageInfo, error) {
considerTests := strings.HasSuffix(filename, "_test.go")
// Handle file from stdin
@@ -178,7 +181,7 @@
}
if !loadedPackageInfo {
loadedPackageInfo = true
- packageInfo, _ = dirPackageInfo(srcDir, filename)
+ packageInfo, _ = dirPackageInfo(f.Name.Name, srcDir, filename)
}
if decls[pkgName] == nil && (packageInfo == nil || !packageInfo.Globals[pkgName]) {
refs[pkgName][v.Sel.Name] = true