gopls/internal/regtest: update TestEditFile to use a modified buffer
In CL 267577, the fake editor was updated to automatically refresh
unmodified buffers with on-disk changes. This created a race in
TestEditFile, which asserts that on-disk changes are NOT reflected in
open buffers.
Fix this by inserting a trivial modification to the open buffer. Also
make the test deterministic, so that it fails consistently without this
modification.
Change-Id: If20af2a3e8f33a64a7514ae3fb5469bd9c59a9c9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/270244
Run-TryBot: Robert Findley <rfindley@google.com>
Trust: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
diff --git a/gopls/internal/regtest/watch_test.go b/gopls/internal/regtest/watch_test.go
index 9786480..46ed48a 100644
--- a/gopls/internal/regtest/watch_test.go
+++ b/gopls/internal/regtest/watch_test.go
@@ -45,11 +45,16 @@
t.Run("opened", func(t *testing.T) {
runner.Run(t, pkg, func(t *testing.T, env *Env) {
env.OpenFile("a/a.go")
+ // Insert a trivial edit so that we don't automatically update the buffer
+ // (see CL 267577).
+ env.EditBuffer("a/a.go", fake.NewEdit(0, 0, 0, 0, " "))
env.Await(CompletedWork(lsp.DiagnosticWorkTitle(lsp.FromDidOpen), 1))
env.WriteWorkspaceFile("a/a.go", `package a; func _() {};`)
env.Await(
- env.DiagnosticAtRegexp("a/a.go", "x"),
- )
+ OnceMet(
+ CompletedWork(lsp.DiagnosticWorkTitle(lsp.FromDidChangeWatchedFiles), 1),
+ env.DiagnosticAtRegexp("a/a.go", "x"),
+ ))
})
})
}