From acd792380219cfdb845dcccd1f0d64fd3fdcdc47 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Wed, 24 Jun 2020 16:39:54 -0700 Subject: [PATCH] [dev.go2go] go/go2go: add IDs for test files No test because the test harness doesn't support test packages. (But probably we'll need a better test harness.) Fixes #39839 Change-Id: I4532b1443dbdd081552ffb78477cbe5039183416 Reviewed-on: https://go-review.googlesource.com/c/go/+/239708 Reviewed-by: Ian Lance Taylor --- src/go/go2go/go2go.go | 4 +--- src/go/go2go/importer.go | 10 ++++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/go/go2go/go2go.go b/src/go/go2go/go2go.go index d1928bf14f..9766220819 100644 --- a/src/go/go2go/go2go.go +++ b/src/go/go2go/go2go.go @@ -95,9 +95,7 @@ func rewriteFilesInPath(importer *Importer, importPath, dir string, go2files []s return nil, fmt.Errorf("type checking failed for %s\n%v", pkg.Name, merr) } - if !strings.HasSuffix(pkg.Name, "_test") { - importer.record(pkgfiles, importPath, tpkg, asts) - } + importer.record(pkg.Name, pkgfiles, importPath, tpkg, asts) rpkgs = append(rpkgs, tpkg) tpkgs = append(tpkgs, pkgfiles) diff --git a/src/go/go2go/importer.go b/src/go/go2go/importer.go index 8f2a35dd2e..c1e9536520 100644 --- a/src/go/go2go/importer.go +++ b/src/go/go2go/importer.go @@ -296,11 +296,13 @@ func (imp *Importer) localImport(importPath, dir string) (*types.Package, error) // record records information for a package, for use when working // with packages that import this one. -func (imp *Importer) record(pkgfiles []namedAST, importPath string, tpkg *types.Package, asts []*ast.File) { - if importPath != "" { - imp.packages[importPath] = tpkg +func (imp *Importer) record(pkgName string, pkgfiles []namedAST, importPath string, tpkg *types.Package, asts []*ast.File) { + if !strings.HasSuffix(pkgName, "_test") { + if importPath != "" { + imp.packages[importPath] = tpkg + } + imp.imports[importPath] = imp.collectImports(asts) } - imp.imports[importPath] = imp.collectImports(asts) for _, nast := range pkgfiles { imp.addIDs(nast.ast) }