Skip to content

Commit

Permalink
go/packages: remove go.mod files
Browse files Browse the repository at this point in the history
Files named go.mod define a module boundary and punch a hole in the
repository when the module is fetched with go get. We had a couple in
testdata. Get rid of them.

In one case the changes I made to produce a module cache in packagestest
were enough. In the other, the test needs multiple minor/patch versions
of the same module, which we have no provision for. Rename them to
"definitelynot_go.mod" in the repo and fix it up in the test.

Updates golang/go#34352

Change-Id: I284578b3aebb0f1fec3ddb4bef0df24f050d0636
Reviewed-on: https://go-review.googlesource.com/c/tools/+/196258
Run-TryBot: Heschi Kreinick <[email protected]>
Reviewed-by: Ian Cottrell <[email protected]>
  • Loading branch information
heschi committed Sep 18, 2019
1 parent 9098376 commit 68f92b6
Show file tree
Hide file tree
Showing 19 changed files with 23 additions and 44 deletions.
50 changes: 23 additions & 27 deletions go/packages/packages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1543,41 +1543,37 @@ func testName(t *testing.T, exporter packagestest.Exporter) {

func TestName_Modules(t *testing.T) {
// Test the top-level package case described in runNamedQueries.
// Note that overriding GOPATH below prevents Export from
// creating more than one module.
exported := packagestest.Export(t, packagestest.Modules, []packagestest.Module{{
Name: "golang.org/pkg",
Files: map[string]interface{}{
"pkg.go": `package pkg`,
}}})
exported := packagestest.Export(t, packagestest.Modules, []packagestest.Module{
{
Name: "golang.org/pkg",
Files: map[string]interface{}{
"pkg.go": `package pkg`,
},
},
{
Name: "example.com/tools-testrepo",
Files: map[string]interface{}{
"pkg/pkg.go": `package pkg`,
},
},
{
Name: "example.com/tools-testrepo/v2",
Files: map[string]interface{}{
"pkg/pkg.go": `package pkg`,
},
},
})
defer exported.Cleanup()

wd, err := os.Getwd()
if err != nil {
t.Fatal(err)
}
gopath, err := ioutil.TempDir("", "TestName_Modules")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(gopath)
if err := copyAll(filepath.Join(wd, "testdata", "TestName_Modules"), gopath); err != nil {
t.Fatal(err)
}
// testdata/TestNamed_Modules contains:
// - pkg/mod/github.com/heschik/[email protected]/pkg
// - pkg/mod/github.com/heschik/tools-testrepo/[email protected]/pkg
// - src/b/pkg
exported.Config.Mode = packages.LoadImports
exported.Config.Env = append(exported.Config.Env, "GOPATH="+gopath)
initial, err := packages.Load(exported.Config, "iamashamedtousethedisabledqueryname=pkg")
if err != nil {
t.Fatal(err)
}
graph, _ := importGraph(initial)
wantGraph := `
* github.com/heschik/tools-testrepo/pkg
* github.com/heschik/tools-testrepo/v2/pkg
* example.com/tools-testrepo/pkg
* example.com/tools-testrepo/v2/pkg
* golang.org/pkg
`[1:]
if graph != wantGraph {
Expand Down Expand Up @@ -2504,7 +2500,7 @@ func copyAll(srcPath, dstPath string) error {
if err != nil {
return err
}
dstFilePath := filepath.Join(dstPath, rel)
dstFilePath := strings.Replace(filepath.Join(dstPath, rel), "definitelynot_go.mod", "go.mod", -1)
if err := os.MkdirAll(filepath.Dir(dstFilePath), 0755); err != nil {
return err
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion go/packages/testdata/TestName_Modules/src/b/pkg/pkg.go

This file was deleted.

This file was deleted.

File renamed without changes.

This file was deleted.

0 comments on commit 68f92b6

Please sign in to comment.