1 // Copyright 2019 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.
15 "golang.org/x/tools/internal/lsp/cmd"
16 cmdtest "golang.org/x/tools/internal/lsp/cmd/test"
17 "golang.org/x/tools/internal/lsp/tests"
18 "golang.org/x/tools/internal/testenv"
21 func TestMain(m *testing.M) {
22 testenv.ExitIfSmallMachine()
26 func TestCommandLine(t *testing.T) {
27 cmdtest.TestCommandLine(t, "../testdata", tests.DefaultOptions)
30 func TestDefinitionHelpExample(t *testing.T) {
31 // TODO: https://golang.org/issue/32794.
33 if runtime.GOOS == "android" {
34 t.Skip("not all source files are available on android")
36 dir, err := os.Getwd()
38 t.Errorf("could not get wd: %v", err)
41 ctx := tests.Context(t)
42 ts := cmdtest.NewTestServer(ctx, nil)
43 thisFile := filepath.Join(dir, "definition.go")
44 baseArgs := []string{"query", "definition"}
45 expect := regexp.MustCompile(`(?s)^[\w/\\:_-]+flag[/\\]flag.go:\d+:\d+-\d+: defined here as FlagSet struct {.*}$`)
46 for _, query := range []string{
47 fmt.Sprintf("%v:%v:%v", thisFile, cmd.ExampleLine, cmd.ExampleColumn),
48 fmt.Sprintf("%v:#%v", thisFile, cmd.ExampleOffset)} {
49 args := append(baseArgs, query)
50 r := cmdtest.NewRunner(nil, ctx, ts.Addr, nil)
51 got, _ := r.NormalizeGoplsCmd(t, args...)
52 if !expect.MatchString(got) {
53 t.Errorf("test with %v\nexpected:\n%s\ngot:\n%s", args, expect, got)