| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
package workspace |
| 6 |
|
| 7 |
import ( |
| 8 |
"os" |
| 9 |
"os/exec" |
| 10 |
"path/filepath" |
| 11 |
"runtime" |
| 12 |
"strings" |
| 13 |
"testing" |
| 14 |
|
| 15 |
. "golang.org/x/tools/gopls/internal/test/integration" |
| 16 |
) |
| 17 |
|
| 18 |
func TestStdWorkspace(t *testing.T) { |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
if testing.Short() { |
| 28 |
t.Skip("skipping with -short: loads GOROOT") |
| 29 |
} |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
if runtime.GOOS == "windows" { |
| 35 |
t.Skip("skipping on windows: fails to misspelled paths") |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
cmd := exec.Command("go", "env", "GOROOT") |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
cmd.Env = append(os.Environ(), "GOTOOLCHAIN=local") |
| 45 |
goroot, err := cmd.Output() |
| 46 |
if err != nil { |
| 47 |
t.Fatal(err) |
| 48 |
} |
| 49 |
stdDir := filepath.Join(strings.TrimSpace(string(goroot)), "src") |
| 50 |
WithOptions( |
| 51 |
Modes(Default), |
| 52 |
WorkspaceFolders(stdDir), |
| 53 |
).Run(t, "", func(t *testing.T, env *Env) { |
| 54 |
|
| 55 |
syms := env.Symbol("'go/parser.ParseFile") |
| 56 |
if len(syms) != 1 { |
| 57 |
t.Fatalf("got %d symbols, want exactly 1. Symbols:\n%v", len(syms), syms) |
| 58 |
} |
| 59 |
parserPath := syms[0].Location.URI.Path() |
| 60 |
env.OpenFile(parserPath) |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
astFile := env.RegexpSearch(parserPath, `func ParseFile\(.*ast\.(File)`) |
| 65 |
refs := env.References(astFile) |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
foundGoTypesReference := false |
| 70 |
for _, ref := range refs { |
| 71 |
if strings.Contains(string(ref.URI), "go/types") { |
| 72 |
foundGoTypesReference = true |
| 73 |
} |
| 74 |
} |
| 75 |
if !foundGoTypesReference { |
| 76 |
t.Errorf("references(ast.File) did not return a go/types reference. Refs:\n%v", refs) |
| 77 |
} |
| 78 |
}) |
| 79 |
} |