1
0
mirror of https://github.com/golang/go synced 2024-11-18 15:04:44 -07:00

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>
This commit is contained in:
Rebecca Stambler 2020-03-20 15:07:41 -04:00
parent 4c83a7e07a
commit cc38525d79
2 changed files with 43 additions and 1 deletions

View File

@ -85,6 +85,5 @@ func testInvalidFilesInOverlay(t *testing.T, exporter packagestest.Exporter) {
}
}
})
}
}

View File

@ -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))
}
}