@@ -11,7 +11,9 @@ import (
11
11
. "golang.org/x/tools/internal/lsp/regtest"
12
12
)
13
13
14
- const sharedProgram = `
14
+ // Smoke test that simultaneous editing sessions in the same workspace works.
15
+ func TestSimultaneousEdits (t * testing.T ) {
16
+ const sharedProgram = `
15
17
-- go.mod --
16
18
module mod
17
19
@@ -25,13 +27,9 @@ func main() {
25
27
fmt.Println("Hello World.")
26
28
}`
27
29
28
- // runShared is a helper to run a test in the same directory using both the
29
- // original env, and an additional other environment connected to the same
30
- // server.
31
- func runShared (t * testing.T , testFunc func (origEnv * Env , otherEnv * Env )) {
32
- // Only run these tests in forwarded modes.
33
- modes := DefaultModes () & (Forwarded | SeparateProcess )
34
- WithOptions (Modes (modes )).Run (t , sharedProgram , func (t * testing.T , env1 * Env ) {
30
+ WithOptions (
31
+ Modes (DefaultModes ()& (Forwarded | SeparateProcess )),
32
+ ).Run (t , sharedProgram , func (t * testing.T , env1 * Env ) {
35
33
// Create a second test session connected to the same workspace and server
36
34
// as the first.
37
35
awaiter := NewAwaiter (env1 .Sandbox .Workdir )
@@ -48,37 +46,29 @@ func runShared(t *testing.T, testFunc func(origEnv *Env, otherEnv *Env)) {
48
46
Awaiter : awaiter ,
49
47
}
50
48
env2 .Await (InitialWorkspaceLoad )
51
- testFunc (env1 , env2 )
52
- })
53
- }
54
-
55
- func TestSimultaneousEdits (t * testing.T ) {
56
- runShared (t , func (origEnv * Env , otherEnv * Env ) {
57
49
// In editor #1, break fmt.Println as before.
58
- origEnv .OpenFile ("main.go" )
59
- origEnv .RegexpReplace ("main.go" , "Printl(n)" , "" )
50
+ env1 .OpenFile ("main.go" )
51
+ env1 .RegexpReplace ("main.go" , "Printl(n)" , "" )
60
52
// In editor #2 remove the closing brace.
61
- otherEnv .OpenFile ("main.go" )
62
- otherEnv .RegexpReplace ("main.go" , "\\ )\n (})" , "" )
53
+ env2 .OpenFile ("main.go" )
54
+ env2 .RegexpReplace ("main.go" , "\\ )\n (})" , "" )
63
55
64
56
// Now check that we got different diagnostics in each environment.
65
- origEnv .Await (origEnv .DiagnosticAtRegexp ("main.go" , "Printl" ))
66
- otherEnv .Await (otherEnv .DiagnosticAtRegexp ("main.go" , "$" ))
67
- })
68
- }
57
+ env1 .Await (env1 .DiagnosticAtRegexp ("main.go" , "Printl" ))
58
+ env2 .Await (env2 .DiagnosticAtRegexp ("main.go" , "$" ))
69
59
70
- func TestShutdown (t * testing.T ) {
71
- runShared (t , func (origEnv * Env , otherEnv * Env ) {
72
- // Close otherEnv, and verify that operation in the original environment is
73
- // unaffected. Note: 'otherEnv' must be the environment being closed here.
74
- // If we were to instead close 'env' here, we'd run into a duplicate
75
- // shutdown when the test runner closes the original env.
76
- if err := otherEnv .Editor .Close (otherEnv .Ctx ); err != nil {
77
- t .Errorf ("closing first editor: %v" , err )
60
+ // Now close editor #2, and verify that operation in editor #1 is
61
+ // unaffected.
62
+ if err := env2 .Editor .Close (env2 .Ctx ); err != nil {
63
+ t .Errorf ("closing second editor: %v" , err )
78
64
}
79
- // Now make an edit in editor #2 to trigger diagnostics.
80
- origEnv .OpenFile ("main.go" )
81
- origEnv .RegexpReplace ("main.go" , "\\ )\n (})" , "" )
82
- origEnv .Await (origEnv .DiagnosticAtRegexp ("main.go" , "$" ))
65
+
66
+ env1 .RegexpReplace ("main.go" , "Printl" , "Println" )
67
+ env1 .Await (
68
+ OnceMet (
69
+ env1 .DoneWithChange (),
70
+ EmptyDiagnostics ("main.go" ),
71
+ ),
72
+ )
83
73
})
84
74
}
0 commit comments