Skip to content

Commit

Permalink
gopls: remove go.sum files from integration tests
Browse files Browse the repository at this point in the history
Explicit go.sum files in the txtar data for tests makes it
harder to modify the tests. This CL replaces the ones in the
gopls integration tests with calls to WriteGoSum in test setup.

And as part of modernization, a few 'interface{}'s have been
replaced with 'any's.

Change-Id: I951fa6d7b2ed780df68f4bc0d043f0738612da28
Reviewed-on: https://go-review.googlesource.com/c/tools/+/644335
Reviewed-by: Alan Donovan <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
  • Loading branch information
pjweinbgo committed Jan 27, 2025
1 parent edafbe5 commit bb0a9cd
Show file tree
Hide file tree
Showing 16 changed files with 28 additions and 83 deletions.
14 changes: 5 additions & 9 deletions gopls/internal/test/integration/codelens/codelens_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,6 @@ module mod.com/a
go 1.22
require golang.org/x/hello v1.2.3
-- go.sum --
golang.org/x/hello v1.2.3 h1:7Wesfkx/uBd+eFgPrq0irYj/1XfmbvLV8jZ/W7C2Dwg=
golang.org/x/hello v1.2.3/go.mod h1:OgtlzsxVMUUdsdQCIDYgaauCTH47B8T8vofouNJfzgY=
-- main.go --
package main
Expand All @@ -282,6 +279,7 @@ require golang.org/x/hello v1.3.3
`

WithOptions(
WriteGoSum("."),
ProxyFiles(proxyWithLatest),
).Run(t, shouldUpdateDep, func(t *testing.T, env *Env) {
env.RunGoCommand("mod", "vendor")
Expand Down Expand Up @@ -335,11 +333,6 @@ require golang.org/x/hello v1.0.0
require golang.org/x/unused v1.0.0
// EOF
-- go.sum --
golang.org/x/hello v1.0.0 h1:qbzE1/qT0/zojAMd/JcPsO2Vb9K4Bkeyq0vB2JGMmsw=
golang.org/x/hello v1.0.0/go.mod h1:WW7ER2MRNXWA6c8/4bDIek4Hc/+DofTrMaQQitGXcco=
golang.org/x/unused v1.0.0 h1:LecSbCn5P3vTcxubungSt1Pn4D/WocCaiWOPDC0y0rw=
golang.org/x/unused v1.0.0/go.mod h1:ihoW8SgWzugwwj0N2SfLfPZCxTB1QOVfhMfB5PWTQ8U=
-- main.go --
package main
Expand All @@ -349,7 +342,10 @@ func main() {
_ = hi.Goodbye
}
`
WithOptions(ProxyFiles(proxy)).Run(t, shouldRemoveDep, func(t *testing.T, env *Env) {
WithOptions(
WriteGoSum("."),
ProxyFiles(proxy),
).Run(t, shouldRemoveDep, func(t *testing.T, env *Env) {
env.OpenFile("go.mod")
env.RegexpReplace("go.mod", "// EOF", "// EOF unsaved edit") // unsaved edits ok
env.ExecuteCodeLensCommand("go.mod", command.Tidy, nil)
Expand Down
11 changes: 4 additions & 7 deletions gopls/internal/test/integration/completion/completion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,6 @@ module mod.com
go 1.14
require example.com v1.2.3
-- go.sum --
example.com v1.2.3 h1:ihBTGWGjTU3V4ZJ9OmHITkU9WQ4lGdQkMjgyLFk0FaY=
example.com v1.2.3/go.mod h1:Y2Rc5rVWjWur0h3pd9aEvK5Pof8YKDANh9gHA2Maujo=
-- main.go --
package main
Expand All @@ -295,6 +292,7 @@ func _() {
}
`
WithOptions(
WriteGoSum("."),
ProxyFiles(proxy),
).Run(t, mod, func(t *testing.T, env *Env) {
// Make sure the dependency is in the module cache and accessible for
Expand Down Expand Up @@ -347,9 +345,6 @@ module mod.com
go 1.14
require example.com v1.2.3
-- go.sum --
example.com v1.2.3 h1:ihBTGWGjTU3V4ZJ9OmHITkU9WQ4lGdQkMjgyLFk0FaY=
example.com v1.2.3/go.mod h1:Y2Rc5rVWjWur0h3pd9aEvK5Pof8YKDANh9gHA2Maujo=
-- useblah.go --
// +build hidden
Expand All @@ -361,7 +356,9 @@ package mainmod
const Name = "mainmod"
`
WithOptions(ProxyFiles(proxy)).Run(t, files, func(t *testing.T, env *Env) {
WithOptions(
WriteGoSum("."),
ProxyFiles(proxy)).Run(t, files, func(t *testing.T, env *Env) {
env.CreateBuffer("import.go", "package pkg\nvar _ = mainmod.Name\n")
env.SaveBuffer("import.go")
content := env.ReadWorkspaceFile("import.go")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,6 @@ module mod.com
go 1.12
require foo.test v1.2.3
-- go.sum --
foo.test v1.2.3 h1:TMA+lyd1ck0TqjSFpNe4T6cf/K6TYkoHwOOcMBMjaEw=
foo.test v1.2.3/go.mod h1:Ij3kyLIe5lzjycjh13NL8I2gX0quZuTdW0MnmlwGBL4=
-- print.go --
package lib
Expand Down Expand Up @@ -451,6 +448,7 @@ const Answer = 42

func TestResolveDiagnosticWithDownload(t *testing.T) {
WithOptions(
WriteGoSum("."),
ProxyFiles(testPackageWithRequireProxy),
).Run(t, testPackageWithRequire, func(t *testing.T, env *Env) {
env.OpenFile("print.go")
Expand Down Expand Up @@ -1753,9 +1751,6 @@ module mod.com
go 1.12
require nested.com v1.0.0
-- go.sum --
nested.com v1.0.0 h1:I6spLE4CgFqMdBPc+wTV2asDO2QJ3tU0YAT+jkLeN1I=
nested.com v1.0.0/go.mod h1:ly53UzXQgVjSlV7wicdBB4p8BxfytuGT1Xcyv0ReJfI=
-- main.go --
package main
Expand All @@ -1779,6 +1774,7 @@ package hello
func helloHelper() {}
`
WithOptions(
WriteGoSum("."),
ProxyFiles(proxy),
Modes(Default),
).Run(t, nested, func(t *testing.T, env *Env) {
Expand Down
2 changes: 1 addition & 1 deletion gopls/internal/test/integration/misc/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ var ErrFoo = errors.New("foo")
cfg.Env = map[string]string{
"AN_ARBITRARY_VAR": "FOO",
}
cfg.Settings = map[string]interface{}{
cfg.Settings = map[string]any{
"staticcheck": true,
}
env.ChangeConfiguration(cfg)
Expand Down
5 changes: 1 addition & 4 deletions gopls/internal/test/integration/misc/definition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,17 +466,14 @@ module example.com/a
go 1.14
require other.com/b v1.0.0
-- go.sum --
other.com/b v1.0.0 h1:1wb3PMGdet5ojzrKl+0iNksRLnOM9Jw+7amBNqmYwqk=
other.com/b v1.0.0/go.mod h1:TgHQFucl04oGT+vrUm/liAzukYHNxCwKNkQZEyn3m9g=
-- a.go --
package a
import "other.com/b"
const _ = b.K
`
WithOptions(
WriteGoSum("."),
ProxyFiles(proxy),
Modes(Default), // fails in 'experimental' mode
).Run(t, src, func(t *testing.T, env *Env) {
Expand Down
4 changes: 1 addition & 3 deletions gopls/internal/test/integration/misc/highlight_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,6 @@ module mod.com
go 1.12
require example.com v1.2.3
-- go.sum --
example.com v1.2.3 h1:WFzrgiQJwEDJNLDUOV1f9qlasQkvzXf2UNLaNIqbWsI=
example.com v1.2.3/go.mod h1:Y2Rc5rVWjWur0h3pd9aEvK5Pof8YKDANh9gHA2Maujo=
-- main.go --
package main
Expand All @@ -110,6 +107,7 @@ func main() {}`

WithOptions(
ProxyFiles(proxy),
WriteGoSum("."),
).Run(t, mod, func(t *testing.T, env *Env) {
env.OpenFile("main.go")

Expand Down
5 changes: 1 addition & 4 deletions gopls/internal/test/integration/misc/references_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,6 @@ module example.com/a
go 1.14
require other.com/b v1.0.0
-- go.sum --
other.com/b v1.0.0 h1:9WyCKS+BLAMRQM0CegP6zqP2beP+ShTbPaARpNY31II=
other.com/b v1.0.0/go.mod h1:TgHQFucl04oGT+vrUm/liAzukYHNxCwKNkQZEyn3m9g=
-- a.go --
package a
import "other.com/b"
Expand All @@ -388,6 +384,7 @@ var _ b.B
`
WithOptions(
WriteGoSum("."),
ProxyFiles(proxy),
Modes(Default), // fails in 'experimental' mode
).Run(t, src, func(t *testing.T, env *Env) {
Expand Down
8 changes: 2 additions & 6 deletions gopls/internal/test/integration/misc/vendor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ module mod.com
go 1.14
require golang.org/x/hello v1.2.3
-- go.sum --
golang.org/x/hello v1.2.3 h1:EcMp5gSkIhaTkPXp8/3+VH+IFqTpk3ZbpOhqk0Ncmho=
golang.org/x/hello v1.2.3/go.mod h1:WW7ER2MRNXWA6c8/4bDIek4Hc/+DofTrMaQQitGXcco=
-- vendor/modules.txt --
-- a/a1.go --
package a
Expand All @@ -48,6 +45,7 @@ func _() {
WithOptions(
Modes(Default),
ProxyFiles(basicProxy),
WriteGoSum("."),
).Run(t, pkgThatUsesVendoring, func(t *testing.T, env *Env) {
env.OpenFile("a/a1.go")
d := &protocol.PublishDiagnosticsParams{}
Expand All @@ -71,9 +69,6 @@ module mod.com
go 1.14
require golang.org/x/hello v1.2.3
-- go.sum --
golang.org/x/hello v1.2.3 h1:EcMp5gSkIhaTkPXp8/3+VH+IFqTpk3ZbpOhqk0Ncmho=
golang.org/x/hello v1.2.3/go.mod h1:WW7ER2MRNXWA6c8/4bDIek4Hc/+DofTrMaQQitGXcco=
-- main.go --
package main
Expand All @@ -86,6 +81,7 @@ func main() {
WithOptions(
Modes(Default),
ProxyFiles(basicProxy),
WriteGoSum("."),
).Run(t, src, func(t *testing.T, env *Env) {
env.OpenFile("main.go")
env.AfterChange(NoDiagnostics())
Expand Down
14 changes: 2 additions & 12 deletions gopls/internal/test/integration/misc/vuln_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,13 +368,6 @@ require (
golang.org/amod v1.0.0 // indirect
golang.org/bmod v0.5.0 // indirect
)
-- go.sum --
golang.org/amod v1.0.0 h1:EUQOI2m5NhQZijXZf8WimSnnWubaFNrrKUH/PopTN8k=
golang.org/amod v1.0.0/go.mod h1:yvny5/2OtYFomKt8ax+WJGvN6pfN1pqjGnn7DQLUi6E=
golang.org/bmod v0.5.0 h1:KgvUulMyMiYRB7suKA0x+DfWRVdeyPgVJvcishTH+ng=
golang.org/bmod v0.5.0/go.mod h1:f6o+OhF66nz/0BBc/sbCsshyPRKMSxZIlG50B/bsM4c=
golang.org/cmod v1.1.3 h1:PJ7rZFTk7xGAunBRDa0wDe7rZjZ9R/vr1S2QkVVCngQ=
golang.org/cmod v1.1.3/go.mod h1:eCR8dnmvLYQomdeAZRCPgS5JJihXtqOQrpEkNj5feQA=
-- x/x.go --
package x
Expand Down Expand Up @@ -497,7 +490,7 @@ func vulnTestEnv(proxyData string) (*vulntest.DB, []RunOption, error) {
"_GOPLS_TEST_BINARY_RUN_AS_GOPLS": "true", // needed to run `gopls vulncheck`.
"GOSUMDB": "off",
}
return db, []RunOption{ProxyFiles(proxyData), ev, settings}, nil
return db, []RunOption{ProxyFiles(proxyData), ev, settings, WriteGoSum(".")}, nil
}

func TestRunVulncheckPackageDiagnostics(t *testing.T) {
Expand Down Expand Up @@ -675,7 +668,7 @@ func TestRunGovulncheck_Expiry(t *testing.T) {
})
}

func stringify(a interface{}) string {
func stringify(a any) string {
data, _ := json.Marshal(a)
return string(data)
}
Expand Down Expand Up @@ -814,9 +807,6 @@ go 1.18
require golang.org/bmod v0.5.0
-- go.sum --
golang.org/bmod v0.5.0 h1:MT/ysNRGbCiURc5qThRFWaZ5+rK3pQRPo9w7dYZfMDk=
golang.org/bmod v0.5.0/go.mod h1:k+zl+Ucu4yLIjndMIuWzD/MnOHy06wqr3rD++y0abVs=
-- x/x.go --
package x
Expand Down
16 changes: 1 addition & 15 deletions gopls/internal/test/integration/modfile/modfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,6 @@ go 1.12
require (
example.com v1.2.3
)
-- go.sum --
-- main.go --
package main
Expand Down Expand Up @@ -918,11 +917,6 @@ module mod.com
go 1.12
require hasdep.com v1.2.3
-- go.sum --
example.com v1.2.3 h1:ihBTGWGjTU3V4ZJ9OmHITkU9WQ4lGdQkMjgyLFk0FaY=
example.com v1.2.3/go.mod h1:Y2Rc5rVWjWur0h3pd9aEvK5Pof8YKDANh9gHA2Maujo=
hasdep.com v1.2.3 h1:00y+N5oD+SpKoqV1zP2VOPawcW65Zb9NebANY3GSzGI=
hasdep.com v1.2.3/go.mod h1:ePVZOlez+KZEOejfLPGL2n4i8qiAjrkhQZ4wcImqAes=
-- main.go --
package main
Expand Down Expand Up @@ -957,19 +951,13 @@ go 1.12
require hasdep.com v1.2.3
require random.com v1.2.3
-- go.sum --
example.com v1.2.3 h1:ihBTGWGjTU3V4ZJ9OmHITkU9WQ4lGdQkMjgyLFk0FaY=
example.com v1.2.3/go.mod h1:Y2Rc5rVWjWur0h3pd9aEvK5Pof8YKDANh9gHA2Maujo=
hasdep.com v1.2.3 h1:00y+N5oD+SpKoqV1zP2VOPawcW65Zb9NebANY3GSzGI=
hasdep.com v1.2.3/go.mod h1:ePVZOlez+KZEOejfLPGL2n4i8qiAjrkhQZ4wcImqAes=
random.com v1.2.3 h1:PzYTykzqqH6+qU0dIgh9iPFbfb4Mm8zNBjWWreRKtx0=
random.com v1.2.3/go.mod h1:8EGj+8a4Hw1clAp8vbaeHAsKE4sbm536FP7nKyXO+qQ=
-- main.go --
package main
func main() {}
`
WithOptions(
WriteGoSum("."),
ProxyFiles(proxy),
).Run(t, mod, func(t *testing.T, env *Env) {
d := &protocol.PublishDiagnosticsParams{}
Expand Down Expand Up @@ -1010,7 +998,6 @@ go 1.12
require (
example.com v1.2.3
)
-- go.sum --
-- main.go --
package main
Expand Down Expand Up @@ -1078,7 +1065,6 @@ func Goodbye() {
module mod.com
go 1.12
-- go.sum --
-- main.go --
package main
Expand Down
2 changes: 1 addition & 1 deletion gopls/internal/test/integration/watch/setting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ package subdir
// use (true|false) or some other truthy value.
func TestSubdirWatchPatterns_BadValues(t *testing.T) {
tests := []struct {
badValue interface{}
badValue any
wantMessage string
}{
{true, "invalid type bool (want string)"},
Expand Down
7 changes: 3 additions & 4 deletions gopls/internal/test/integration/watch/watch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,9 +525,6 @@ module mod.com
go 1.12
require example.com v1.2.2
-- go.sum --
example.com v1.2.3 h1:OnPPkx+rW63kj9pgILsu12MORKhSlnFa3DVRJq1HZ7g=
example.com v1.2.3/go.mod h1:Y2Rc5rVWjWur0h3pd9aEvK5Pof8YKDANh9gHA2Maujo=
-- main.go --
package main
Expand All @@ -537,7 +534,9 @@ func main() {
blah.X()
}
`
WithOptions(ProxyFiles(proxy)).Run(t, mod, func(t *testing.T, env *Env) {
WithOptions(
WriteGoSum("."),
ProxyFiles(proxy)).Run(t, mod, func(t *testing.T, env *Env) {
env.WriteWorkspaceFiles(map[string]string{
"go.mod": `module mod.com
Expand Down
4 changes: 1 addition & 3 deletions gopls/internal/test/integration/workspace/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,6 @@ module b.com/nested
go 1.18
require b.com/other v1.4.6
-- go.sum --
b.com/other v1.4.6 h1:pHXSzGsk6DamYXp9uRdDB9A/ZQqAN9it+JudU0sBf94=
b.com/other v1.4.6/go.mod h1:T0TYuGdAHw4p/l0+1P/yhhYHfZRia7PaadNVDu58OWM=
-- nested.go --
package nested
Expand All @@ -228,6 +225,7 @@ import "b.com/other/foo"
const C = foo.Foo
`
WithOptions(
WriteGoSum("."),
ProxyFiles(proxy),
).Run(t, files, func(t *testing.T, env *Env) {
env.OnceMet(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func main() {}
)

cfg := env.Editor.Config()
cfg.Settings = map[string]interface{}{
cfg.Settings = map[string]any{
"standaloneTags": []string{"ignore"},
}
env.ChangeConfiguration(cfg)
Expand Down
5 changes: 1 addition & 4 deletions gopls/internal/test/integration/workspace/vendor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ module example.com/a
go 1.14
require other.com/b v1.0.0
-- go.sum --
other.com/b v1.0.0 h1:ct1+0RPozzMvA2rSYnVvIfr/GDHcd7oVnw147okdi3g=
other.com/b v1.0.0/go.mod h1:bfTSZo/4ZtAQJWBYScopwW6n9Ctfsl2mi8nXsqjDXR8=
-- a.go --
package a
Expand All @@ -49,6 +45,7 @@ var _ b.B
`
WithOptions(
WriteGoSum("."),
ProxyFiles(proxy),
Modes(Default),
).Run(t, src, func(t *testing.T, env *Env) {
Expand Down
Loading

0 comments on commit bb0a9cd

Please sign in to comment.