diff options
Diffstat (limited to 'gopls/internal/regtest/misc/shared_test.go')
-rw-r--r-- | gopls/internal/regtest/misc/shared_test.go | 58 |
1 files changed, 33 insertions, 25 deletions
diff --git a/gopls/internal/regtest/misc/shared_test.go b/gopls/internal/regtest/misc/shared_test.go index 6861743ff..410a8d327 100644 --- a/gopls/internal/regtest/misc/shared_test.go +++ b/gopls/internal/regtest/misc/shared_test.go @@ -7,10 +7,13 @@ package misc import ( "testing" - . "golang.org/x/tools/internal/lsp/regtest" + "golang.org/x/tools/gopls/internal/lsp/fake" + . "golang.org/x/tools/gopls/internal/lsp/regtest" ) -const sharedProgram = ` +// Smoke test that simultaneous editing sessions in the same workspace works. +func TestSimultaneousEdits(t *testing.T) { + const sharedProgram = ` -- go.mod -- module mod @@ -24,20 +27,26 @@ func main() { fmt.Println("Hello World.") }` -func runShared(t *testing.T, testFunc func(env1 *Env, env2 *Env)) { - // Only run these tests in forwarded modes. - modes := DefaultModes() & (Forwarded | SeparateProcess) - WithOptions(Modes(modes)).Run(t, sharedProgram, func(t *testing.T, env1 *Env) { + WithOptions( + Modes(DefaultModes()&(Forwarded|SeparateProcess)), + ).Run(t, sharedProgram, func(t *testing.T, env1 *Env) { // Create a second test session connected to the same workspace and server // as the first. - env2 := NewEnv(env1.Ctx, t, env1.Sandbox, env1.Server, env1.Editor.Config, true) + awaiter := NewAwaiter(env1.Sandbox.Workdir) + const skipApplyEdits = false + editor, err := fake.NewEditor(env1.Sandbox, env1.Editor.Config()).Connect(env1.Ctx, env1.Server, awaiter.Hooks(), skipApplyEdits) + if err != nil { + t.Fatal(err) + } + env2 := &Env{ + T: t, + Ctx: env1.Ctx, + Sandbox: env1.Sandbox, + Server: env1.Server, + Editor: editor, + Awaiter: awaiter, + } env2.Await(InitialWorkspaceLoad) - testFunc(env1, env2) - }) -} - -func TestSimultaneousEdits(t *testing.T) { - runShared(t, func(env1 *Env, env2 *Env) { // In editor #1, break fmt.Println as before. env1.OpenFile("main.go") env1.RegexpReplace("main.go", "Printl(n)", "") @@ -46,19 +55,18 @@ func TestSimultaneousEdits(t *testing.T) { env2.RegexpReplace("main.go", "\\)\n(})", "") // Now check that we got different diagnostics in each environment. - env1.Await(env1.DiagnosticAtRegexp("main.go", "Printl")) - env2.Await(env2.DiagnosticAtRegexp("main.go", "$")) - }) -} + env1.AfterChange(Diagnostics(env1.AtRegexp("main.go", "Printl"))) + env2.AfterChange(Diagnostics(env2.AtRegexp("main.go", "$"))) -func TestShutdown(t *testing.T) { - runShared(t, func(env1 *Env, env2 *Env) { - if err := env1.Editor.Close(env1.Ctx); err != nil { - t.Errorf("closing first editor: %v", err) + // Now close editor #2, and verify that operation in editor #1 is + // unaffected. + if err := env2.Editor.Close(env2.Ctx); err != nil { + t.Errorf("closing second editor: %v", err) } - // Now make an edit in editor #2 to trigger diagnostics. - env2.OpenFile("main.go") - env2.RegexpReplace("main.go", "\\)\n(})", "") - env2.Await(env2.DiagnosticAtRegexp("main.go", "$")) + + env1.RegexpReplace("main.go", "Printl", "Println") + env1.AfterChange( + NoDiagnostics(ForFile("main.go")), + ) }) } |