Skip to content

Commit 6d345e8

Browse files
committed
gopls/internal/regtest: remove redundant 'With' from run options
Now that the correct way to invoke regtests is via withOptions(...).run, all the 'With' prefixes in option names seem redundant. Change-Id: Icbbb00e15d034726d1e0cb13ff82b4f832add286 Reviewed-on: https://go-review.googlesource.com/c/tools/+/276974 Run-TryBot: Robert Findley <[email protected]> gopls-CI: kokoro <[email protected]> TryBot-Result: Go Bot <[email protected]> Trust: Robert Findley <[email protected]> Reviewed-by: Rebecca Stambler <[email protected]>
1 parent f31efc5 commit 6d345e8

File tree

11 files changed

+62
-62
lines changed

11 files changed

+62
-62
lines changed

gopls/internal/regtest/codelens_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func main() {
117117
} {
118118
t.Run(commandTitle, func(t *testing.T) {
119119
withOptions(
120-
WithProxyFiles(proxyWithLatest),
120+
ProxyFiles(proxyWithLatest),
121121
).run(t, shouldUpdateDep, func(t *testing.T, env *Env) {
122122
env.OpenFile("go.mod")
123123
var lens protocol.CodeLens
@@ -210,7 +210,7 @@ require golang.org/x/hello v1.0.0
210210
if got != wantGoMod {
211211
t.Fatalf("go.mod tidy failed:\n%s", tests.Diff(wantGoMod, got))
212212
}
213-
}, WithProxyFiles(proxy))
213+
}, ProxyFiles(proxy))
214214
}
215215

216216
func TestRegenerateCgo(t *testing.T) {

gopls/internal/regtest/diagnostics_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ func Hello() {
290290

291291
t.Run("without workspace module", func(t *testing.T) {
292292
withOptions(
293-
WithModes(Singleton),
293+
Modes(Singleton),
294294
).run(t, noMod, func(t *testing.T, env *Env) {
295295
env.Await(
296296
env.DiagnosticAtRegexp("main.go", `"mod.com/bob"`),
@@ -424,7 +424,7 @@ func TestResolveDiagnosticWithDownload(t *testing.T) {
424424
// diagnostic for the wrong formatting type.
425425
// TODO: we should be able to easily also match the diagnostic message.
426426
env.Await(env.DiagnosticAtRegexp("print.go", "fmt.Printf"))
427-
}, WithProxyFiles(testPackageWithRequireProxy))
427+
}, ProxyFiles(testPackageWithRequireProxy))
428428
}
429429

430430
func TestMissingDependency(t *testing.T) {
@@ -655,7 +655,7 @@ func main() {
655655
}
656656
`
657657
withOptions(
658-
WithProxyFiles(ardanLabsProxy),
658+
ProxyFiles(ardanLabsProxy),
659659
).run(t, ardanLabs, func(t *testing.T, env *Env) {
660660
// Expect a diagnostic with a suggested fix to add
661661
// "github.com/ardanlabs/conf" to the go.mod file.
@@ -713,7 +713,7 @@ go 1.12
713713
-- main.go --
714714
`
715715
withOptions(
716-
WithProxyFiles(ardanLabsProxy),
716+
ProxyFiles(ardanLabsProxy),
717717
).run(t, emptyFile, func(t *testing.T, env *Env) {
718718
env.OpenFile("main.go")
719719
env.EditBuffer("main.go", fake.NewEdit(0, 0, 0, 0, `package main
@@ -1251,13 +1251,13 @@ func main() {
12511251
var x int
12521252
}
12531253
`
1254-
withOptions(WithRootPath("a")).run(t, mod, func(t *testing.T, env *Env) {
1254+
withOptions(RootPath("a")).run(t, mod, func(t *testing.T, env *Env) {
12551255
env.OpenFile("a/main.go")
12561256
env.Await(
12571257
env.DiagnosticAtRegexp("main.go", "x"),
12581258
)
12591259
})
1260-
withOptions(WithRootPath("a"), LimitWorkspaceScope()).run(t, mod, func(t *testing.T, env *Env) {
1260+
withOptions(RootPath("a"), LimitWorkspaceScope()).run(t, mod, func(t *testing.T, env *Env) {
12611261
env.OpenFile("a/main.go")
12621262
env.Await(
12631263
NoDiagnostics("main.go"),
@@ -1475,7 +1475,7 @@ package foo_
14751475
`
14761476

14771477
withOptions(
1478-
WithProxyFiles(proxy),
1478+
ProxyFiles(proxy),
14791479
InGOPATH(),
14801480
).run(t, contents, func(t *testing.T, env *Env) {
14811481
// Simulate typing character by character.
@@ -1625,7 +1625,7 @@ import (
16251625
EditorConfig{
16261626
Env: map[string]string{"GO111MODULE": "off"},
16271627
},
1628-
WithModes(Singleton),
1628+
Modes(Singleton),
16291629
).run(t, mod, func(t *testing.T, env *Env) {
16301630
env.Await(
16311631
env.DiagnosticAtRegexpWithMessage("main.go", `"nosuchpkg"`, `cannot find package "nosuchpkg" in any of`),
@@ -1652,7 +1652,7 @@ package b
16521652
for _, go111module := range []string{"on", "auto"} {
16531653
t.Run("GO111MODULE="+go111module, func(t *testing.T) {
16541654
withOptions(
1655-
WithModes(Singleton),
1655+
Modes(Singleton),
16561656
EditorConfig{
16571657
Env: map[string]string{
16581658
"GO111MODULE": go111module,
@@ -1673,7 +1673,7 @@ package b
16731673
// Expect no warning if GO111MODULE=auto in a directory in GOPATH.
16741674
t.Run("GOPATH_GO111MODULE_auto", func(t *testing.T) {
16751675
withOptions(
1676-
WithModes(Singleton),
1676+
Modes(Singleton),
16771677
EditorConfig{
16781678
Env: map[string]string{
16791679
"GO111MODULE": "auto",
@@ -1738,8 +1738,8 @@ package hello
17381738
func helloHelper() {}
17391739
`
17401740
withOptions(
1741-
WithProxyFiles(proxy),
1742-
WithModes(Singleton),
1741+
ProxyFiles(proxy),
1742+
Modes(Singleton),
17431743
).run(t, nested, func(t *testing.T, env *Env) {
17441744
// Expect a diagnostic in a nested module.
17451745
env.OpenFile("nested/hello/hello.go")

gopls/internal/regtest/imports_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ var _, _ = x.X, y.Y
150150
editorConfig := EditorConfig{Env: map[string]string{"GOMODCACHE": modcache}}
151151
withOptions(
152152
editorConfig,
153-
WithProxyFiles(proxy),
153+
ProxyFiles(proxy),
154154
).run(t, files, func(t *testing.T, env *Env) {
155155
env.OpenFile("main.go")
156156
env.Await(env.DiagnosticAtRegexp("main.go", `y.Y`))

gopls/internal/regtest/link_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,5 @@ const Hello = "Hello"
8787
if len(links) != 0 {
8888
t.Errorf("documentLink: got %d document links for go.mod, want 0\nlinks: %v", len(links), links)
8989
}
90-
}, WithProxyFiles(proxy))
90+
}, ProxyFiles(proxy))
9191
}

gopls/internal/regtest/modfile_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ const Name = "Hello"
3535

3636
func runModfileTest(t *testing.T, files, proxy string, f TestFunc) {
3737
t.Run("normal", func(t *testing.T) {
38-
withOptions(WithProxyFiles(proxy)).run(t, files, f)
38+
withOptions(ProxyFiles(proxy)).run(t, files, f)
3939
})
4040
t.Run("nested", func(t *testing.T) {
41-
withOptions(WithProxyFiles(proxy), NestWorkdir(), WithModes(Singleton|Experimental)).run(t, files, f)
41+
withOptions(ProxyFiles(proxy), NestWorkdir(), Modes(Singleton|Experimental)).run(t, files, f)
4242
})
4343
}
4444

@@ -434,7 +434,7 @@ import "example.com/blah/v2"
434434
435435
var _ = blah.Name
436436
`
437-
withOptions(WithProxyFiles(proxy)).run(t, files, func(t *testing.T, env *Env) {
437+
withOptions(ProxyFiles(proxy)).run(t, files, func(t *testing.T, env *Env) {
438438
env.OpenFile("main.go")
439439
env.OpenFile("go.mod")
440440
var d protocol.PublishDiagnosticsParams
@@ -620,8 +620,8 @@ func main() {
620620
"GOFLAGS": "-mod=readonly",
621621
},
622622
},
623-
WithProxyFiles(proxy),
624-
WithModes(Singleton),
623+
ProxyFiles(proxy),
624+
Modes(Singleton),
625625
).run(t, mod, func(t *testing.T, env *Env) {
626626
env.OpenFile("main.go")
627627
original := env.ReadWorkspaceFile("go.mod")
@@ -670,8 +670,8 @@ func main() {
670670
}
671671
`
672672
withOptions(
673-
WithProxyFiles(workspaceProxy),
674-
WithModes(Experimental),
673+
ProxyFiles(workspaceProxy),
674+
Modes(Experimental),
675675
).run(t, mod, func(t *testing.T, env *Env) {
676676
env.Await(
677677
env.DiagnosticAtRegexp("a/go.mod", "example.com v1.2.3"),
@@ -700,7 +700,7 @@ func main() {
700700
}
701701
`
702702
withOptions(
703-
WithProxyFiles(workspaceProxy),
703+
ProxyFiles(workspaceProxy),
704704
EditorConfig{
705705
BuildFlags: []string{"-tags", "bob"},
706706
},

gopls/internal/regtest/runner.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,22 +100,22 @@ func (f optionSetter) set(opts *runConfig) {
100100
f(opts)
101101
}
102102

103-
// WithTimeout configures a custom timeout for this test run.
104-
func WithTimeout(d time.Duration) RunOption {
103+
// Timeout configures a custom timeout for this test run.
104+
func Timeout(d time.Duration) RunOption {
105105
return optionSetter(func(opts *runConfig) {
106106
opts.timeout = d
107107
})
108108
}
109109

110-
// WithProxyFiles configures a file proxy using the given txtar-encoded string.
111-
func WithProxyFiles(txt string) RunOption {
110+
// ProxyFiles configures a file proxy using the given txtar-encoded string.
111+
func ProxyFiles(txt string) RunOption {
112112
return optionSetter(func(opts *runConfig) {
113113
opts.sandbox.ProxyFiles = txt
114114
})
115115
}
116116

117-
// WithModes configures the execution modes that the test should run in.
118-
func WithModes(modes Mode) RunOption {
117+
// Modes configures the execution modes that the test should run in.
118+
func Modes(modes Mode) RunOption {
119119
return optionSetter(func(opts *runConfig) {
120120
opts.modes = modes
121121
})
@@ -144,10 +144,10 @@ func WithoutWorkspaceFolders() RunOption {
144144
})
145145
}
146146

147-
// WithRootPath specifies the rootURI of the workspace folder opened in the
147+
// RootPath specifies the rootURI of the workspace folder opened in the
148148
// editor. By default, the sandbox opens the top-level directory, but some
149149
// tests need to check other cases.
150-
func WithRootPath(path string) RunOption {
150+
func RootPath(path string) RunOption {
151151
return optionSetter(func(opts *runConfig) {
152152
opts.editor.WorkspaceRoot = path
153153
})
@@ -161,10 +161,10 @@ func InGOPATH() RunOption {
161161
})
162162
}
163163

164-
// WithDebugAddress configures a debug server bound to addr. This option is
164+
// DebugAddress configures a debug server bound to addr. This option is
165165
// currently only supported when executing in Singleton mode. It is intended to
166166
// be used for long-running stress tests.
167-
func WithDebugAddress(addr string) RunOption {
167+
func DebugAddress(addr string) RunOption {
168168
return optionSetter(func(opts *runConfig) {
169169
opts.debugAddr = addr
170170
})
@@ -196,10 +196,10 @@ func SkipHooks(skip bool) RunOption {
196196
})
197197
}
198198

199-
// WithGOPROXY configures the test environment to have an explicit proxy value.
199+
// GOPROXY configures the test environment to have an explicit proxy value.
200200
// This is intended for stress tests -- to ensure their isolation, regtests
201201
// should instead use WithProxyFiles.
202-
func WithGOPROXY(goproxy string) RunOption {
202+
func GOPROXY(goproxy string) RunOption {
203203
return optionSetter(func(opts *runConfig) {
204204
opts.sandbox.GOPROXY = goproxy
205205
})

gopls/internal/regtest/shared_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func runShared(t *testing.T, program string, testFunc func(env1 *Env, env2 *Env)
3030
// as the first.
3131
env2 := NewEnv(env1.Ctx, t, env1.Sandbox, env1.Server, env1.Editor.Config, true)
3232
testFunc(env1, env2)
33-
}, WithModes(modes))
33+
}, Modes(modes))
3434
}
3535

3636
func TestSimultaneousEdits(t *testing.T) {

gopls/internal/regtest/stress_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,20 @@ func stressTestOptions(dir string) []RunOption {
2727
InExistingDir(dir),
2828

2929
// Enable live debugging.
30-
WithDebugAddress(":8087"),
30+
DebugAddress(":8087"),
3131

3232
// Skip logs as they buffer up memory unnaturally.
3333
SkipLogs(),
3434
// Similarly to logs: disable hooks so that they don't affect performance.
3535
SkipHooks(true),
3636
// The Debug server only makes sense if running in singleton mode.
37-
WithModes(Singleton),
37+
Modes(Singleton),
3838
// Set a generous timeout. Individual tests should control their own
3939
// graceful termination.
40-
WithTimeout(20 * time.Minute),
40+
Timeout(20 * time.Minute),
4141

4242
// Use the actual proxy, since we want our builds to succeed.
43-
WithGOPROXY("https://proxy.golang.org"),
43+
GOPROXY("https://proxy.golang.org"),
4444
}
4545
}
4646

gopls/internal/regtest/vendor_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ func _() {
4646
`
4747
// TODO(rstambler): Remove this when golang/go#41819 is resolved.
4848
withOptions(
49-
WithModes(Singleton),
50-
WithProxyFiles(basicProxy),
49+
Modes(Singleton),
50+
ProxyFiles(basicProxy),
5151
).run(t, pkgThatUsesVendoring, func(t *testing.T, env *Env) {
5252
env.OpenFile("a/a1.go")
5353
env.Await(

gopls/internal/regtest/watch_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ func main() {
565565
blah.X()
566566
}
567567
`
568-
withOptions(WithProxyFiles(proxy)).run(t, mod, func(t *testing.T, env *Env) {
568+
withOptions(ProxyFiles(proxy)).run(t, mod, func(t *testing.T, env *Env) {
569569
env.WriteWorkspaceFiles(map[string]string{
570570
"go.mod": `module mod.com
571571
@@ -611,7 +611,7 @@ func main() {
611611
`
612612
withOptions(
613613
InGOPATH(),
614-
WithModes(Experimental), // module is in a subdirectory
614+
Modes(Experimental), // module is in a subdirectory
615615
).run(t, files, func(t *testing.T, env *Env) {
616616
env.OpenFile("foo/main.go")
617617
env.Await(env.DiagnosticAtRegexp("foo/main.go", `"blah"`))

0 commit comments

Comments
 (0)