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.
12 . "golang.org/x/tools/gopls/internal/regtest"
14 "golang.org/x/tools/internal/lsp/protocol"
17 func TestMain(m *testing.M) {
21 func printBenchmarkResults(result testing.BenchmarkResult) {
22 fmt.Println("Benchmark Statistics:")
23 fmt.Println(result.String())
24 fmt.Println(result.MemString())
27 var iwlOptions struct {
32 flag.StringVar(&iwlOptions.workdir, "iwl_workdir", "", "if set, run IWL benchmark in this directory")
35 func TestBenchmarkIWL(t *testing.T) {
36 if iwlOptions.workdir == "" {
37 t.Skip("-iwl_workdir not configured")
40 opts := stressTestOptions(iwlOptions.workdir)
41 // Don't skip hooks, so that we can wait for IWL.
42 opts = append(opts, SkipHooks(false))
44 results := testing.Benchmark(func(b *testing.B) {
45 for i := 0; i < b.N; i++ {
46 WithOptions(opts...).Run(t, "", func(t *testing.T, env *Env) {})
50 printBenchmarkResults(results)
53 var symbolOptions struct {
54 workdir, query, matcher, style string
59 flag.StringVar(&symbolOptions.workdir, "symbol_workdir", "", "if set, run symbol benchmark in this directory")
60 flag.StringVar(&symbolOptions.query, "symbol_query", "test", "symbol query to use in benchmark")
61 flag.StringVar(&symbolOptions.matcher, "symbol_matcher", "", "symbol matcher to use in benchmark")
62 flag.StringVar(&symbolOptions.style, "symbol_style", "", "symbol style to use in benchmark")
63 flag.BoolVar(&symbolOptions.printResults, "symbol_print_results", false, "whether to print symbol query results")
66 func TestBenchmarkSymbols(t *testing.T) {
67 if symbolOptions.workdir == "" {
68 t.Skip("-symbol_workdir not configured")
71 opts := stressTestOptions(symbolOptions.workdir)
72 conf := EditorConfig{}
73 if symbolOptions.matcher != "" {
74 conf.SymbolMatcher = &symbolOptions.matcher
76 if symbolOptions.style != "" {
77 conf.SymbolStyle = &symbolOptions.style
79 opts = append(opts, conf)
81 WithOptions(opts...).Run(t, "", func(t *testing.T, env *Env) {
82 // We can't Await in this test, since we have disabled hooks. Instead, run
83 // one symbol request to completion to ensure all necessary cache entries
85 symbols, err := env.Editor.Server.Symbol(env.Ctx, &protocol.WorkspaceSymbolParams{
86 Query: symbolOptions.query,
92 if symbolOptions.printResults {
93 fmt.Println("Results:")
94 for i := 0; i < len(symbols); i++ {
95 fmt.Printf("\t%d. %s (%s)\n", i, symbols[i].Name, symbols[i].ContainerName)
99 results := testing.Benchmark(func(b *testing.B) {
100 for i := 0; i < b.N; i++ {
101 if _, err := env.Editor.Server.Symbol(env.Ctx, &protocol.WorkspaceSymbolParams{
102 Query: symbolOptions.query,
108 printBenchmarkResults(results)