Skip to content

Commit d7fc70a

Browse files
committed
gopls/internal/regtest: always await InitialWorkspaceLoad
There's very little reason not to always await IWL, and none of our tests actually need to be able to execute before it completes. Await IWL before running the test func. Change-Id: Ia0626aa4e4c6cfa89dc5d03075b6bd797574a8dc Reviewed-on: https://go-review.googlesource.com/c/tools/+/258078 Run-TryBot: Robert Findley <[email protected]> gopls-CI: kokoro <[email protected]> Trust: Robert Findley <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Heschi Kreinick <[email protected]>
1 parent a0ef9b6 commit d7fc70a

11 files changed

+5
-37
lines changed

gopls/internal/regtest/bench_test.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ func TestBenchmarkIWL(t *testing.T) {
3737

3838
results := testing.Benchmark(func(b *testing.B) {
3939
for i := 0; i < b.N; i++ {
40-
withOptions(opts...).run(t, "", func(t *testing.T, env *Env) {
41-
env.Await(InitialWorkspaceLoad)
42-
})
40+
withOptions(opts...).run(t, "", func(t *testing.T, env *Env) {})
4341
}
4442
})
4543

gopls/internal/regtest/codelens_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,6 @@ func main() {
253253
withOptions(
254254
EditorConfig{CodeLens: map[string]bool{"gc_details": true}},
255255
).run(t, mod, func(t *testing.T, env *Env) {
256-
env.Await(InitialWorkspaceLoad)
257256
env.OpenFile("main.go")
258257
env.ExecuteCodeLensCommand("main.go", source.CommandToggleDetails)
259258
d := &protocol.PublishDiagnosticsParams{}

gopls/internal/regtest/completion_bench_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ func benchmarkCompletion(options completionBenchOptions, t *testing.T) {
4646
opts = append(opts, SkipHooks(false))
4747

4848
withOptions(opts...).run(t, "", func(t *testing.T, env *Env) {
49-
env.Await(InitialWorkspaceLoad)
5049
env.OpenFile(options.file)
5150

5251
// Run edits required for this completion.

gopls/internal/regtest/configuration_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ package a
2626
const ThisVariable = 7
2727
`
2828
run(t, files, func(t *testing.T, env *Env) {
29-
env.Await(InitialWorkspaceLoad)
3029
env.OpenFile("a/a.go")
3130
env.Await(
3231
CompletedWork(lsp.DiagnosticWorkTitle(lsp.FromDidOpen), 1),

gopls/internal/regtest/diagnostics_test.go

-6
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,6 @@ func TestCreateOnlyXTest(t *testing.T) {
847847
-- foo/bar_test.go --
848848
`
849849
run(t, mod, func(t *testing.T, env *Env) {
850-
env.Await(InitialWorkspaceLoad)
851850
env.OpenFile("foo/bar_test.go")
852851
env.EditBuffer("foo/bar_test.go", fake.NewEdit(0, 0, 0, 0, `package foo
853852
`))
@@ -876,7 +875,6 @@ package foo
876875
package foo_
877876
`
878877
run(t, mod, func(t *testing.T, env *Env) {
879-
env.Await(InitialWorkspaceLoad)
880878
env.OpenFile("foo/bar_test.go")
881879
env.RegexpReplace("foo/bar_test.go", "package foo_", "package foo_test")
882880
env.SaveBuffer("foo/bar_test.go")
@@ -1101,7 +1099,6 @@ func Foo() {
11011099
runner.Run(t, basic, func(t *testing.T, env *Env) {
11021100
testenv.NeedsGo1Point(t, 15)
11031101

1104-
env.Await(InitialWorkspaceLoad)
11051102
env.WriteWorkspaceFile("foo/foo_test.go", `package main
11061103
11071104
func main() {
@@ -1130,7 +1127,6 @@ package main
11301127
func main() {}
11311128
`
11321129
runner.Run(t, basic, func(t *testing.T, env *Env) {
1133-
env.Await(InitialWorkspaceLoad)
11341130
env.Editor.OpenFileWithContent(env.Ctx, "foo.go", `package main`)
11351131
env.Await(
11361132
CompletedWork(lsp.DiagnosticWorkTitle(lsp.FromDidOpen), 1),
@@ -1289,7 +1285,6 @@ func main() {}
12891285
log.SetFlags(log.Lshortfile)
12901286
env.OpenFile("main.go")
12911287
env.OpenFile("other.go")
1292-
env.Await(InitialWorkspaceLoad)
12931288
x := env.DiagnosticsFor("main.go")
12941289
if x == nil {
12951290
t.Fatalf("expected 1 diagnostic, got none")
@@ -1338,7 +1333,6 @@ func _() {
13381333
}
13391334
`
13401335
run(t, files, func(t *testing.T, env *Env) {
1341-
env.Await(InitialWorkspaceLoad)
13421336
env.OpenFile("a/a.go")
13431337
env.Await(
13441338
env.DiagnosticAtRegexp("a/a.go", "x"),

gopls/internal/regtest/fix_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ func Foo() {
2828
}
2929
`
3030
runner.Run(t, basic, func(t *testing.T, env *Env) {
31-
env.Await(InitialWorkspaceLoad)
3231
env.OpenFile("main.go")
3332
if err := env.Editor.RefactorRewrite(env.Ctx, "main.go", &protocol.Range{
3433
Start: protocol.Position{

gopls/internal/regtest/imports_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ func TestA(t *testing.T) {
189189
}
190190
`
191191
run(t, pkg, func(t *testing.T, env *Env) {
192-
env.Await(InitialWorkspaceLoad)
193192
env.OpenFile("a/a.go")
194193
var d protocol.PublishDiagnosticsParams
195194
env.Await(

gopls/internal/regtest/modfile_test.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -317,10 +317,7 @@ func main() {
317317
go 1.12
318318
`
319319
runner.Run(t, mod, func(t *testing.T, env *Env) {
320-
env.Await(
321-
InitialWorkspaceLoad,
322-
env.DiagnosticAtRegexp("go.mod", "require"),
323-
)
320+
env.Await(env.DiagnosticAtRegexp("go.mod", "require"))
324321
env.Sandbox.RunGoCommand(env.Ctx, "", "mod", []string{"tidy"})
325322
env.Await(
326323
EmptyDiagnostics("go.mod"),
@@ -436,7 +433,6 @@ func main() {
436433
// Start from a bad state/bad IWL, and confirm that we recover.
437434
t.Run("bad", func(t *testing.T) {
438435
runner.Run(t, unknown, func(t *testing.T, env *Env) {
439-
env.Await(InitialWorkspaceLoad)
440436
env.OpenFile("go.mod")
441437
env.Await(
442438
env.DiagnosticAtRegexp("go.mod", "example.com v1.2.2"),

gopls/internal/regtest/runner.go

+2
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,8 @@ func (r *Runner) Run(t *testing.T, files string, test TestFunc, opts ...RunOptio
281281
}
282282
env.CloseEditor()
283283
}()
284+
// Always await the initial workspace load.
285+
env.Await(InitialWorkspaceLoad)
284286
test(t, env)
285287
})
286288
}

gopls/internal/regtest/watch_test.go

+1-12
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,6 @@ func _() {
309309
// Add the new method before the implementation. Expect diagnostics.
310310
t.Run("method before implementation", func(t *testing.T) {
311311
runner.Run(t, pkg, func(t *testing.T, env *Env) {
312-
env.Await(InitialWorkspaceLoad)
313312
env.WriteWorkspaceFile("b/b.go", newMethod)
314313
env.Await(
315314
OnceMet(
@@ -326,7 +325,6 @@ func _() {
326325
// Add the new implementation before the new method. Expect no diagnostics.
327326
t.Run("implementation before method", func(t *testing.T) {
328327
runner.Run(t, pkg, func(t *testing.T, env *Env) {
329-
env.Await(InitialWorkspaceLoad)
330328
env.WriteWorkspaceFile("a/a.go", implementation)
331329
env.Await(
332330
OnceMet(
@@ -343,7 +341,6 @@ func _() {
343341
// Add both simultaneously. Expect no diagnostics.
344342
t.Run("implementation and method simultaneously", func(t *testing.T) {
345343
runner.Run(t, pkg, func(t *testing.T, env *Env) {
346-
env.Await(InitialWorkspaceLoad)
347344
env.WriteWorkspaceFiles(map[string]string{
348345
"a/a.go": implementation,
349346
"b/b.go": newMethod,
@@ -473,7 +470,6 @@ package a
473470
func _() {}
474471
`
475472
runner.Run(t, pkg, func(t *testing.T, env *Env) {
476-
env.Await(InitialWorkspaceLoad)
477473
env.ChangeFilesOnDisk([]fake.FileEvent{
478474
{
479475
Path: "a/a3.go",
@@ -560,7 +556,6 @@ func main() {
560556
}
561557
`
562558
withOptions(WithProxyFiles(proxy)).run(t, mod, func(t *testing.T, env *Env) {
563-
env.Await(InitialWorkspaceLoad)
564559
env.WriteWorkspaceFiles(map[string]string{
565560
"go.mod": `module mod.com
566561
@@ -606,12 +601,7 @@ func main() {
606601
`
607602
withOptions(InGOPATH()).run(t, files, func(t *testing.T, env *Env) {
608603
env.OpenFile("foo/main.go")
609-
env.Await(
610-
OnceMet(
611-
InitialWorkspaceLoad,
612-
env.DiagnosticAtRegexp("foo/main.go", `"blah"`),
613-
),
614-
)
604+
env.Await(env.DiagnosticAtRegexp("foo/main.go", `"blah"`))
615605
if err := env.Sandbox.RunGoCommand(env.Ctx, "foo", "mod", []string{"init", "mod.com"}); err != nil {
616606
t.Fatal(err)
617607
}
@@ -651,7 +641,6 @@ func TestBob(t *testing.T) {
651641
}
652642
`
653643
run(t, files, func(t *testing.T, env *Env) {
654-
env.Await(InitialWorkspaceLoad)
655644
// Add a new symbol to the package under test and use it in the test
656645
// variant. Expect no diagnostics.
657646
env.WriteWorkspaceFiles(map[string]string{

gopls/internal/regtest/workspace_test.go

-6
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ func TestClearAnalysisDiagnostics(t *testing.T) {
140140
// replace target is added to the go.mod.
141141
func TestWatchReplaceTargets(t *testing.T) {
142142
withOptions(WithProxyFiles(workspaceProxy), WithRootPath("pkg")).run(t, workspaceModule, func(t *testing.T, env *Env) {
143-
env.Await(InitialWorkspaceLoad)
144143
// Add a replace directive and expect the files that gopls is watching
145144
// to change.
146145
dir := env.Sandbox.Workdir.URI("goodbye").SpanURI().Filename()
@@ -198,7 +197,6 @@ func Hello() int {
198197
withOptions(
199198
WithProxyFiles(workspaceModuleProxy),
200199
).run(t, multiModule, func(t *testing.T, env *Env) {
201-
env.Await(InitialWorkspaceLoad)
202200
env.Await(
203201
env.DiagnosticAtRegexp("moda/a/a.go", "x"),
204202
env.DiagnosticAtRegexp("modb/b/b.go", "x"),
@@ -240,7 +238,6 @@ func Hello() int {
240238
withOptions(
241239
WithProxyFiles(workspaceModuleProxy),
242240
).run(t, multiModule, func(t *testing.T, env *Env) {
243-
env.Await(InitialWorkspaceLoad)
244241
env.OpenFile("moda/a/a.go")
245242

246243
original, _ := env.GoToDefinition("moda/a/a.go", env.RegexpSearch("moda/a/a.go", "Hello"))
@@ -284,7 +281,6 @@ func main() {
284281
withOptions(
285282
WithProxyFiles(workspaceModuleProxy),
286283
).run(t, multiModule, func(t *testing.T, env *Env) {
287-
env.Await(InitialWorkspaceLoad)
288284
env.OpenFile("moda/a/a.go")
289285
original, _ := env.GoToDefinition("moda/a/a.go", env.RegexpSearch("moda/a/a.go", "Hello"))
290286
if want := "[email protected]/b/b.go"; !strings.HasSuffix(original, want) {
@@ -343,7 +339,6 @@ func Hello() int {
343339
}
344340
`
345341
run(t, multiModule, func(t *testing.T, env *Env) {
346-
env.Await(InitialWorkspaceLoad)
347342
env.OpenFile("modb/go.mod")
348343
env.Await(
349344
OnceMet(
@@ -399,7 +394,6 @@ replace a.com => $SANDBOX_WORKDIR/moda/a
399394
withOptions(
400395
WithProxyFiles(workspaceModuleProxy),
401396
).run(t, multiModule, func(t *testing.T, env *Env) {
402-
env.Await(InitialWorkspaceLoad)
403397
env.OpenFile("moda/a/a.go")
404398
original, _ := env.GoToDefinition("moda/a/a.go", env.RegexpSearch("moda/a/a.go", "Hello"))
405399
if want := "[email protected]/b/b.go"; !strings.HasSuffix(original, want) {

0 commit comments

Comments
 (0)