Skip to content

Commit

Permalink
modfile: ensure that Cleanup removes extraneous entries after SetRequire
Browse files Browse the repository at this point in the history
Updates golang/go#34822

Change-Id: If6981c8673c2843f5075d6d9a478bcf80f26e2fb
Reviewed-on: https://go-review.googlesource.com/c/mod/+/204821
Run-TryBot: Bryan C. Mills <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Jay Conrod <[email protected]>
  • Loading branch information
Bryan C. Mills committed Nov 1, 2019
1 parent 577bb39 commit a222b96
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions modfile/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,8 @@ func (f *File) SetRequire(req []*Require) {
if v, ok := need[r.Mod.Path]; ok {
r.Mod.Version = v
r.Indirect = indirect[r.Mod.Path]
} else {
*r = Require{}
}
}

Expand Down
6 changes: 6 additions & 0 deletions modfile/rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ var setRequireTests = []struct {
x.y/b v1.2.3
x.y/a v1.2.3
x.y/d v1.2.3
)
`,
[]struct {
Expand Down Expand Up @@ -158,6 +159,11 @@ func TestSetRequire(t *testing.T) {
if !bytes.Equal(out, golden) {
t.Errorf("have:\n%s\nwant:\n%s", out, golden)
}

f.Cleanup()
if len(f.Require) != len(mods) {
t.Errorf("after Cleanup, len(Require) = %v; want %v", len(f.Require), len(mods))
}
})
}
}

0 comments on commit a222b96

Please sign in to comment.