go/packages: add test for golang/go#37971

Since the fix is only available at master, make the test 1.15-specific.

Change-Id: Ie17c8806479d3d53076c2351da8bcfcfbfc8257f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/224517
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
diff --git a/go/packages/packages114_test.go b/go/packages/packages114_test.go
index 8786219..c85fcd7 100644
--- a/go/packages/packages114_test.go
+++ b/go/packages/packages114_test.go
@@ -85,6 +85,5 @@
 				}
 			}
 		})
-
 	}
 }
diff --git a/go/packages/packages115_test.go b/go/packages/packages115_test.go
new file mode 100644
index 0000000..004de7c
--- /dev/null
+++ b/go/packages/packages115_test.go
@@ -0,0 +1,43 @@
+// Copyright 2020 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build go1.15
+
+package packages_test
+
+import (
+	"testing"
+
+	"golang.org/x/tools/go/packages"
+	"golang.org/x/tools/go/packages/packagestest"
+)
+
+// TestInvalidFilesInXTest checks the fix for golang/go#37971.
+func TestInvalidFilesInXTest(t *testing.T) {
+	packagestest.TestAll(t, testInvalidFilesInXTest)
+}
+func testInvalidFilesInXTest(t *testing.T, exporter packagestest.Exporter) {
+	exported := packagestest.Export(t, exporter, []packagestest.Module{
+		{
+			Name: "golang.org/fake",
+			Files: map[string]interface{}{
+				"d/d.go":      `package d; import "net/http"; const d = http.MethodGet; func Get() string { return d; }`,
+				"d/d2.go":     ``, // invalid file
+				"d/d_test.go": `package d_test; import "testing"; import "golang.org/fake/d"; func TestD(t *testing.T) { d.Get(); }`,
+			},
+		},
+	})
+	defer exported.Cleanup()
+
+	exported.Config.Mode = packages.NeedName | packages.NeedFiles
+	exported.Config.Tests = true
+
+	initial, err := packages.Load(exported.Config, "golang.org/fake/d")
+	if err != nil {
+		t.Fatal(err)
+	}
+	if len(initial) != 3 {
+		t.Errorf("expected 3 packages, got %d", len(initial))
+	}
+}