Skip to content

Commit 68f92b6

Browse files
committed
go/packages: remove go.mod files
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 <heschi@google.com> Reviewed-by: Ian Cottrell <iancottrell@google.com>
1 parent 9098376 commit 68f92b6

File tree

19 files changed

+23
-44
lines changed

19 files changed

+23
-44
lines changed

go/packages/packages_test.go

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,41 +1543,37 @@ func testName(t *testing.T, exporter packagestest.Exporter) {
15431543

15441544
func TestName_Modules(t *testing.T) {
15451545
// Test the top-level package case described in runNamedQueries.
1546-
// Note that overriding GOPATH below prevents Export from
1547-
// creating more than one module.
1548-
exported := packagestest.Export(t, packagestest.Modules, []packagestest.Module{{
1549-
Name: "golang.org/pkg",
1550-
Files: map[string]interface{}{
1551-
"pkg.go": `package pkg`,
1552-
}}})
1546+
exported := packagestest.Export(t, packagestest.Modules, []packagestest.Module{
1547+
{
1548+
Name: "golang.org/pkg",
1549+
Files: map[string]interface{}{
1550+
"pkg.go": `package pkg`,
1551+
},
1552+
},
1553+
{
1554+
Name: "example.com/tools-testrepo",
1555+
Files: map[string]interface{}{
1556+
"pkg/pkg.go": `package pkg`,
1557+
},
1558+
},
1559+
{
1560+
Name: "example.com/tools-testrepo/v2",
1561+
Files: map[string]interface{}{
1562+
"pkg/pkg.go": `package pkg`,
1563+
},
1564+
},
1565+
})
15531566
defer exported.Cleanup()
15541567

1555-
wd, err := os.Getwd()
1556-
if err != nil {
1557-
t.Fatal(err)
1558-
}
1559-
gopath, err := ioutil.TempDir("", "TestName_Modules")
1560-
if err != nil {
1561-
t.Fatal(err)
1562-
}
1563-
defer os.RemoveAll(gopath)
1564-
if err := copyAll(filepath.Join(wd, "testdata", "TestName_Modules"), gopath); err != nil {
1565-
t.Fatal(err)
1566-
}
1567-
// testdata/TestNamed_Modules contains:
1568-
// - pkg/mod/github.com/heschik/tools-testrepo@v1.0.0/pkg
1569-
// - pkg/mod/github.com/heschik/tools-testrepo/v2@v2.0.0/pkg
1570-
// - src/b/pkg
15711568
exported.Config.Mode = packages.LoadImports
1572-
exported.Config.Env = append(exported.Config.Env, "GOPATH="+gopath)
15731569
initial, err := packages.Load(exported.Config, "iamashamedtousethedisabledqueryname=pkg")
15741570
if err != nil {
15751571
t.Fatal(err)
15761572
}
15771573
graph, _ := importGraph(initial)
15781574
wantGraph := `
1579-
* github.com/heschik/tools-testrepo/pkg
1580-
* github.com/heschik/tools-testrepo/v2/pkg
1575+
* example.com/tools-testrepo/pkg
1576+
* example.com/tools-testrepo/v2/pkg
15811577
* golang.org/pkg
15821578
`[1:]
15831579
if graph != wantGraph {
@@ -2504,7 +2500,7 @@ func copyAll(srcPath, dstPath string) error {
25042500
if err != nil {
25052501
return err
25062502
}
2507-
dstFilePath := filepath.Join(dstPath, rel)
2503+
dstFilePath := strings.Replace(filepath.Join(dstPath, rel), "definitelynot_go.mod", "go.mod", -1)
25082504
if err := os.MkdirAll(filepath.Dir(dstFilePath), 0755); err != nil {
25092505
return err
25102506
}

go/packages/testdata/TestName_Modules/pkg/mod/cache/download/github.com/heschik/tools-testrepo/@v/list

Lines changed: 0 additions & 1 deletion
This file was deleted.

go/packages/testdata/TestName_Modules/pkg/mod/cache/download/github.com/heschik/tools-testrepo/@v/v1.0.0.info

Lines changed: 0 additions & 1 deletion
This file was deleted.

go/packages/testdata/TestName_Modules/pkg/mod/cache/download/github.com/heschik/tools-testrepo/@v/v1.0.0.mod

Lines changed: 0 additions & 1 deletion
This file was deleted.

go/packages/testdata/TestName_Modules/pkg/mod/cache/download/github.com/heschik/tools-testrepo/@v/v1.0.0.ziphash

Lines changed: 0 additions & 1 deletion
This file was deleted.

go/packages/testdata/TestName_Modules/pkg/mod/cache/download/github.com/heschik/tools-testrepo/v2/@v/list

Lines changed: 0 additions & 1 deletion
This file was deleted.

go/packages/testdata/TestName_Modules/pkg/mod/cache/download/github.com/heschik/tools-testrepo/v2/@v/v2.0.0.info

Lines changed: 0 additions & 1 deletion
This file was deleted.

go/packages/testdata/TestName_Modules/pkg/mod/cache/download/github.com/heschik/tools-testrepo/v2/@v/v2.0.0.mod

Lines changed: 0 additions & 1 deletion
This file was deleted.

go/packages/testdata/TestName_Modules/pkg/mod/cache/download/github.com/heschik/tools-testrepo/v2/@v/v2.0.0.ziphash

Lines changed: 0 additions & 1 deletion
This file was deleted.

go/packages/testdata/TestName_Modules/pkg/mod/github.com/heschik/tools-testrepo/v2@v2.0.0/pkg/pkg.go

Lines changed: 0 additions & 1 deletion
This file was deleted.

go/packages/testdata/TestName_Modules/pkg/mod/github.com/heschik/tools-testrepo@v1.0.0/pkg/pkg.go

Lines changed: 0 additions & 1 deletion
This file was deleted.

go/packages/testdata/TestName_Modules/src/b/pkg/pkg.go

Lines changed: 0 additions & 1 deletion
This file was deleted.

go/packages/testdata/TestName_ModulesDedup/pkg/mod/github.com/heschik/tools-testrepo/v2@v2.0.2/go.mod

Lines changed: 0 additions & 3 deletions
This file was deleted.

go/packages/testdata/TestName_ModulesDedup/pkg/mod/github.com/heschik/tools-testrepo@v1.0.0/go.mod

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)