From 54f9f5980a5e15f94c4019cd35f5fa0f4fd7ef45 Mon Sep 17 00:00:00 2001 From: Michael Matloob Date: Tue, 17 Jul 2018 14:58:34 -0400 Subject: [PATCH] go/packages: remove Package.IsTest field We have not yet settled on the meaning of Package.IsTest, and more deeply which packages are test and which are non test packages. This change will remove Package.IsTest in the meantime to avoid confusion. We may later add a boolean or some other way to distinguish test and non-test packages. Change-Id: If6b128f7914009fdd42b8bc3de3bff73c8f006cd Reviewed-on: https://go-review.googlesource.com/124388 Reviewed-by: Russ Cox --- go/packages/doc.go | 12 ++++++------ go/packages/golist.go | 5 ----- go/packages/gopackages/main.go | 5 ++--- go/packages/packages.go | 3 --- go/packages/packages_test.go | 5 +---- 5 files changed, 9 insertions(+), 21 deletions(-) diff --git a/go/packages/doc.go b/go/packages/doc.go index 952bb48d..59de33d1 100644 --- a/go/packages/doc.go +++ b/go/packages/doc.go @@ -172,12 +172,9 @@ files were nearly always missing or stale. Now that 'go build' supports caching, all the underlying build systems can guarantee to produce export data in a reasonable (amortized) time. -Packages that are part of a test are marked IsTest=true. -Such packages include in-package tests, external tests, -and the test "main" packages synthesized by the build system. -The latter packages are reported as first-class packages, -avoiding the need for clients (such as go/ssa) to reinvent this -generation logic. +Test "main" packages synthesized by the build system are now reported as +first-class packages, avoiding the need for clients (such as go/ssa) to +reinvent this generation logic. One way in which go/packages is simpler than the old loader is in its treatment of in-package tests. In-package tests are packages that @@ -307,4 +304,7 @@ Questions & Tasks - Bug: "gopackages fmt a.go" doesn't produce an error. +- If necessary, add back an IsTest boolean or expose ForTests on the Package struct. + IsTest was removed because we couldn't agree on a useful definition. + */ diff --git a/go/packages/golist.go b/go/packages/golist.go index ff19910b..86dab8f0 100644 --- a/go/packages/golist.go +++ b/go/packages/golist.go @@ -107,10 +107,6 @@ func golistPackages(ctx context.Context, dir string, env []string, cgo, export, pkgpath = id[:i] } - // Is this a test? - // ("foo [foo.test]" package or "foo.test" command) - isTest := p.ForTest != "" || strings.HasSuffix(pkgpath, ".test") - if pkgpath == "unsafe" { p.GoFiles = nil // ignore fake unsafe.go file } @@ -156,7 +152,6 @@ func golistPackages(ctx context.Context, dir string, env []string, cgo, export, ID: id, Name: p.Name, PkgPath: pkgpath, - IsTest: isTest, Srcs: absJoin(p.Dir, p.GoFiles, p.CgoFiles), OtherSrcs: absJoin(p.Dir, p.SFiles, p.CFiles), imports: imports, diff --git a/go/packages/gopackages/main.go b/go/packages/gopackages/main.go index 6be503df..10c2b210 100644 --- a/go/packages/gopackages/main.go +++ b/go/packages/gopackages/main.go @@ -165,9 +165,8 @@ func main() { func print(lpkg *packages.Package) { // title var kind string - if lpkg.IsTest { - kind = "test " - } + // TODO(matloob): If IsTest is added back print "test command" or + // "test package" for packages with IsTest == true. if lpkg.Name == "main" { kind += "command" } else { diff --git a/go/packages/packages.go b/go/packages/packages.go index 54267c85..97f7ab95 100644 --- a/go/packages/packages.go +++ b/go/packages/packages.go @@ -211,9 +211,6 @@ type Package struct { // The name of an executable is "main". Name string - // IsTest indicates whether this package is a test. - IsTest bool - // Srcs is the list of names of this package's Go // source files as presented to the compiler. // Names are guaranteed to be absolute. diff --git a/go/packages/packages_test.go b/go/packages/packages_test.go index 2ce0bc2c..342dc3e0 100644 --- a/go/packages/packages_test.go +++ b/go/packages/packages_test.go @@ -145,7 +145,7 @@ func TestMetadataImportGraph(t *testing.T) { {"e", "main", "command", "e.go e2.go"}, {"errors", "errors", "package", "errors.go"}, {"subdir/d", "d", "package", "d.go"}, - {"subdir/d.test", "main", "test command", "0.go"}, + {"subdir/d.test", "main", "command", "0.go"}, {"unsafe", "unsafe", "package", ""}, } { p, ok := all[test.id] @@ -159,9 +159,6 @@ func TestMetadataImportGraph(t *testing.T) { // kind var kind string - if p.IsTest { - kind = "test " - } if p.Name == "main" { kind += "command" } else {