1 // Copyright 2020 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
10 . "golang.org/x/tools/gopls/internal/regtest"
13 const sharedProgram = `
24 fmt.Println("Hello World.")
27 func runShared(t *testing.T, testFunc func(env1 *Env, env2 *Env)) {
28 // Only run these tests in forwarded modes.
29 modes := DefaultModes() & (Forwarded | SeparateProcess)
30 WithOptions(Modes(modes)).Run(t, sharedProgram, func(t *testing.T, env1 *Env) {
31 // Create a second test session connected to the same workspace and server
33 env2 := NewEnv(env1.Ctx, t, env1.Sandbox, env1.Server, env1.Editor.Config, true)
38 func TestSimultaneousEdits(t *testing.T) {
39 runShared(t, func(env1 *Env, env2 *Env) {
40 // In editor #1, break fmt.Println as before.
41 env1.OpenFile("main.go")
42 env1.RegexpReplace("main.go", "Printl(n)", "")
43 // In editor #2 remove the closing brace.
44 env2.OpenFile("main.go")
45 env2.RegexpReplace("main.go", "\\)\n(})", "")
47 // Now check that we got different diagnostics in each environment.
48 env1.Await(env1.DiagnosticAtRegexp("main.go", "Printl"))
49 env2.Await(env2.DiagnosticAtRegexp("main.go", "$"))
53 func TestShutdown(t *testing.T) {
54 runShared(t, func(env1 *Env, env2 *Env) {
56 // Now make an edit in editor #2 to trigger diagnostics.
57 env2.OpenFile("main.go")
58 env2.RegexpReplace("main.go", "\\)\n(})", "")
59 env2.Await(env2.DiagnosticAtRegexp("main.go", "$"))