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.
11 const sharedProgram = `
22 fmt.Println("Hello World.")
25 func runShared(t *testing.T, program string, testFunc func(env1 *Env, env2 *Env)) {
26 // Only run these tests in forwarded modes.
27 modes := runner.DefaultModes & (Forwarded | SeparateProcess)
28 runner.Run(t, sharedProgram, func(t *testing.T, env1 *Env) {
29 // Create a second test session connected to the same workspace and server
31 env2 := NewEnv(env1.Ctx, t, env1.Sandbox, env1.Server, env1.Editor.Config, true)
36 func TestSimultaneousEdits(t *testing.T) {
37 runShared(t, exampleProgram, func(env1 *Env, env2 *Env) {
38 // In editor #1, break fmt.Println as before.
39 env1.OpenFile("main.go")
40 env1.RegexpReplace("main.go", "Printl(n)", "")
41 // In editor #2 remove the closing brace.
42 env2.OpenFile("main.go")
43 env2.RegexpReplace("main.go", "\\)\n(})", "")
45 // Now check that we got different diagnostics in each environment.
46 env1.Await(env1.DiagnosticAtRegexp("main.go", "Printl"))
47 env2.Await(env2.DiagnosticAtRegexp("main.go", "$"))
51 func TestShutdown(t *testing.T) {
52 runShared(t, sharedProgram, func(env1 *Env, env2 *Env) {
54 // Now make an edit in editor #2 to trigger diagnostics.
55 env2.OpenFile("main.go")
56 env2.RegexpReplace("main.go", "\\)\n(})", "")
57 env2.Await(env2.DiagnosticAtRegexp("main.go", "$"))