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 <rsc@golang.org>
This commit is contained in:
Michael Matloob 2018-07-17 14:58:34 -04:00
parent 32950ab3be
commit 54f9f5980a
5 changed files with 9 additions and 21 deletions

View File

@ -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 caching, all the underlying build systems can guarantee to produce
export data in a reasonable (amortized) time. export data in a reasonable (amortized) time.
Packages that are part of a test are marked IsTest=true. Test "main" packages synthesized by the build system are now reported as
Such packages include in-package tests, external tests, first-class packages, avoiding the need for clients (such as go/ssa) to
and the test "main" packages synthesized by the build system. reinvent this generation logic.
The latter packages are 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 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 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. - 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.
*/ */

View File

@ -107,10 +107,6 @@ func golistPackages(ctx context.Context, dir string, env []string, cgo, export,
pkgpath = id[:i] 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" { if pkgpath == "unsafe" {
p.GoFiles = nil // ignore fake unsafe.go file 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, ID: id,
Name: p.Name, Name: p.Name,
PkgPath: pkgpath, PkgPath: pkgpath,
IsTest: isTest,
Srcs: absJoin(p.Dir, p.GoFiles, p.CgoFiles), Srcs: absJoin(p.Dir, p.GoFiles, p.CgoFiles),
OtherSrcs: absJoin(p.Dir, p.SFiles, p.CFiles), OtherSrcs: absJoin(p.Dir, p.SFiles, p.CFiles),
imports: imports, imports: imports,

View File

@ -165,9 +165,8 @@ func main() {
func print(lpkg *packages.Package) { func print(lpkg *packages.Package) {
// title // title
var kind string var kind string
if lpkg.IsTest { // TODO(matloob): If IsTest is added back print "test command" or
kind = "test " // "test package" for packages with IsTest == true.
}
if lpkg.Name == "main" { if lpkg.Name == "main" {
kind += "command" kind += "command"
} else { } else {

View File

@ -211,9 +211,6 @@ type Package struct {
// The name of an executable is "main". // The name of an executable is "main".
Name string Name string
// IsTest indicates whether this package is a test.
IsTest bool
// Srcs is the list of names of this package's Go // Srcs is the list of names of this package's Go
// source files as presented to the compiler. // source files as presented to the compiler.
// Names are guaranteed to be absolute. // Names are guaranteed to be absolute.

View File

@ -145,7 +145,7 @@ func TestMetadataImportGraph(t *testing.T) {
{"e", "main", "command", "e.go e2.go"}, {"e", "main", "command", "e.go e2.go"},
{"errors", "errors", "package", "errors.go"}, {"errors", "errors", "package", "errors.go"},
{"subdir/d", "d", "package", "d.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", ""}, {"unsafe", "unsafe", "package", ""},
} { } {
p, ok := all[test.id] p, ok := all[test.id]
@ -159,9 +159,6 @@ func TestMetadataImportGraph(t *testing.T) {
// kind // kind
var kind string var kind string
if p.IsTest {
kind = "test "
}
if p.Name == "main" { if p.Name == "main" {
kind += "command" kind += "command"
} else { } else {