gopls/internal/test: Completion benchmarks use empty range CL 728881 enforced that gopls completions that pass a `Range` in the TextDocumentPositionParams only do so with an empty range (start = end). The benchmark tests weren't enforcing that, so many have been failing. I fixed the failing tests and added a better error message to the test code that encourages the regex string to only contain an empty group: `()`. Updates golang/go#80113 Change-Id: I1bdb82b4618e6c3eb04506eed93d81166a6a6964 Reviewed-on: https://go-review.googlesource.com/c/tools/+/797720 Reviewed-by: Madeline Kalil <mkalil@google.com> LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
diff --git a/gopls/internal/test/integration/bench/completion_test.go b/gopls/internal/test/integration/bench/completion_test.go index 640c21e..1dbd299 100644 --- a/gopls/internal/test/integration/bench/completion_test.go +++ b/gopls/internal/test/integration/bench/completion_test.go
@@ -39,6 +39,9 @@ // Run a completion to make sure the system is warm. loc := env.RegexpSearch(options.file, options.locationRegexp) + if !loc.Range.Empty() { + b.Errorf("Completion locationRegexp only allows for empty ranges, so use an empty regex group: ()") + } completions := env.Completion(loc) if testing.Verbose() { @@ -88,7 +91,7 @@ benchmarkCompletion(completionBenchOptions{ file: file, - locationRegexp: `var testVariable map\[string\]bool = Session{}(\.)`, + locationRegexp: `var testVariable map\[string\]bool = Session{}\.()`, setup: setup, }, b) } @@ -117,7 +120,7 @@ benchmarkCompletion(completionBenchOptions{ file: file, - locationRegexp: `var testVariable \[\]byte (=)`, + locationRegexp: `var testVariable \[\]byte =()`, setup: setup, }, b) } @@ -142,7 +145,7 @@ benchmarkCompletion(completionBenchOptions{ file: file, - locationRegexp: `func \(c \*completer\) _\(\) {\n\tc\.inference\.kindMatches\((c)`, + locationRegexp: `func \(c \*completer\) _\(\) {\n\tc\.inference\.kindMatches\(c()`, setup: setup, }, b) } @@ -152,7 +155,7 @@ name string file string // repo-relative file to create content string // file content - locationRegexp string // regexp for completion + locationRegexp string // regexp for completion, use empty group: () } var completionTests = []completionTest{ @@ -167,7 +170,7 @@ c.inference.kindMatches(c.) } `, - `func \(c \*completer\) _\(\) {\n\tc\.inference\.kindMatches\((c)`, + `func \(c \*completer\) _\(\) {\n\tc\.inference\.kindMatches\(c()`, }, { "tools", @@ -305,6 +308,10 @@ // Run a completion to make sure the system is warm. loc := env.RegexpSearch(test.file, test.locationRegexp) + if !loc.Range.Empty() { + b.Errorf("Completion locationRegexp only allows for empty ranges, so use an empty regex group: ()") + } + loc.Range.End = loc.Range.Start completions := env.Completion(loc) if testing.Verbose() { @@ -323,6 +330,9 @@ editPlaceholder() } loc := env.RegexpSearch(test.file, test.locationRegexp) + if !loc.Range.Empty() { + b.Errorf("Completion locationRegexp only allows for empty ranges, so use an empty regex group: ()") + } env.Completion(loc) } }