mirror of
https://github.com/golang/go
synced 2024-11-18 22:55:23 -07:00
2529d2857a
This change standardizes the folder structure for testdata that are used for testing the lsp. In particular, it uses the following format: - dir - primarymod - .go files - packages - go.mod (optional) - modules - repoa - mod1 - .go files - packages - go.mod (optional) As we can see, any folder inside of testdata should be of this format, where the primary test files with the markers are all located inside the primarymod folder. The modules folder is used to hold any potential dependencies that are used for testing. A consequence of this change is that we can have one directory separated by folders, where each folder is it's own module, this allows us to use internal/lsp/tests with go.mod files. Now, tests.Load() will return an array of Data objects, where each object corresponds to one of the directories structured above. Updates golang/go#36091 Change-Id: I437cc2a2a9fc1bac93779845737aa74383fbf9c3 Reviewed-on: https://go-review.googlesource.com/c/tools/+/217541 Run-TryBot: Rohan Challa <rohan@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
67 lines
1.8 KiB
Go
67 lines
1.8 KiB
Go
// Copyright 2019 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package cmd_test
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"regexp"
|
|
"runtime"
|
|
"testing"
|
|
|
|
"golang.org/x/tools/go/packages/packagestest"
|
|
"golang.org/x/tools/internal/lsp/cmd"
|
|
cmdtest "golang.org/x/tools/internal/lsp/cmd/test"
|
|
"golang.org/x/tools/internal/lsp/tests"
|
|
"golang.org/x/tools/internal/testenv"
|
|
)
|
|
|
|
func TestMain(m *testing.M) {
|
|
testenv.ExitIfSmallMachine()
|
|
os.Exit(m.Run())
|
|
}
|
|
|
|
func TestCommandLine(t *testing.T) {
|
|
packagestest.TestAll(t, testCommandLine)
|
|
}
|
|
|
|
func testCommandLine(t *testing.T, exporter packagestest.Exporter) {
|
|
data := tests.Load(t, exporter, "../testdata")
|
|
for _, datum := range data {
|
|
defer datum.Exported.Cleanup()
|
|
t.Run(datum.Folder, func(t *testing.T) {
|
|
t.Helper()
|
|
tests.Run(t, cmdtest.NewRunner(exporter, datum, tests.Context(t), nil), datum)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestDefinitionHelpExample(t *testing.T) {
|
|
// TODO: https://golang.org/issue/32794.
|
|
t.Skip()
|
|
if runtime.GOOS == "android" {
|
|
t.Skip("not all source files are available on android")
|
|
}
|
|
dir, err := os.Getwd()
|
|
if err != nil {
|
|
t.Errorf("could not get wd: %v", err)
|
|
return
|
|
}
|
|
thisFile := filepath.Join(dir, "definition.go")
|
|
baseArgs := []string{"query", "definition"}
|
|
expect := regexp.MustCompile(`(?s)^[\w/\\:_-]+flag[/\\]flag.go:\d+:\d+-\d+: defined here as FlagSet struct {.*}$`)
|
|
for _, query := range []string{
|
|
fmt.Sprintf("%v:%v:%v", thisFile, cmd.ExampleLine, cmd.ExampleColumn),
|
|
fmt.Sprintf("%v:#%v", thisFile, cmd.ExampleOffset)} {
|
|
args := append(baseArgs, query)
|
|
r := cmdtest.NewRunner(nil, nil, tests.Context(t), nil)
|
|
got, _ := r.NormalizeGoplsCmd(t, args...)
|
|
if !expect.MatchString(got) {
|
|
t.Errorf("test with %v\nexpected:\n%s\ngot:\n%s", args, expect, got)
|
|
}
|
|
}
|
|
}
|