Skip to content

Commit

Permalink
go/packages: in overlay_test, allow test variant in second_file case
Browse files Browse the repository at this point in the history
When CL 241577 lands, 'go list -e' will include unparseable files
(like a file without a package declaration) in GoFiles in addition to
InvalidGoFiles.

This makes go/packages more tolerant of empty test files. With
CL 241577, if a file=src.go query is given when an empty _test.go is
present, packages.Load will return two matching packages: the library
under test, and the internal test package.

This CL broadens overlay_test.go so the new behavior doesn't break the
test.

For golang/go#39986

Change-Id: I14d019129465e928a3f60a2230edd2e2d1d74687
Reviewed-on: https://go-review.googlesource.com/c/tools/+/317409
Trust: Jay Conrod <[email protected]>
Run-TryBot: Jay Conrod <[email protected]>
TryBot-Result: Go Bot <[email protected]>
gopls-CI: kokoro <[email protected]>
Reviewed-by: Bryan C. Mills <[email protected]>
  • Loading branch information
Jay Conrod committed May 10, 2021
1 parent f05e912 commit ecb7392
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions go/packages/overlay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -818,8 +818,9 @@ func testInvalidFilesBeforeOverlayContains(t *testing.T, exporter packagestest.E
if err != nil {
t.Fatal(err)
}
if len(initial) != 1 {
t.Fatalf("expected 1 packages, got %v", len(initial))
if len(initial) != 1 &&
(len(initial) != 2 || !isTestVariant(initial[0].ID, initial[1].ID)) {
t.Fatalf("expected 1 package (perhaps with test variant), got %v", len(initial))
}
pkg := initial[0]
if pkg.ID != tt.wantID {
Expand Down Expand Up @@ -849,6 +850,11 @@ func testInvalidFilesBeforeOverlayContains(t *testing.T, exporter packagestest.E
}
}

func isTestVariant(libID, testID string) bool {
variantID := fmt.Sprintf("%[1]s [%[1]s.test]", libID)
return variantID == testID
}

func TestInvalidXTestInGOPATH(t *testing.T) {
packagestest.TestAll(t, testInvalidXTestInGOPATH)
}
Expand Down

0 comments on commit ecb7392

Please sign in to comment.