Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Test tip on travis (#236)
Browse files Browse the repository at this point in the history
* Test tip on travis

* Only test if godef to GOROOT matches path

* Install all instead of ...

go1.10 introduces the cache directory. So now objects will only appear in `pkg` if
they are explicitly installed. Previous versions of go would create entries for
the transitive dependencies. So for our vendor tests running `go install -i ...`
would not create a corresponding file in `pkg` for the vendored packages since
`...` does not list vendor. Using `all` instead does include the vendored pkg,
so will include the vendored pkgs. This will likely have wider effects on go
tooling that rely on pkg. Already filed nsf/gocode#500
for gocode.

* Handle differing diagnostic output

* Correctly remove range in def test on windows
  • Loading branch information
keegancsmith authored Feb 14, 2018
1 parent 0cbfbb7 commit 20886c7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ language: go
go:
- 1.8.x
- 1.9.x
- tip

go_import_path: github.com/sourcegraph/go-langserver

Expand Down
14 changes: 11 additions & 3 deletions langserver/langserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ package main; import "test/pkg"; func B() { p.A(); B() }`,
// "a.go:1:53": "type int int",
},
overrideGodefDefinition: map[string]string{
"a.go:1:40": "/goroot/src/fmt/print.go:256:6-256:13", // hitting the real GOROOT
"a.go:1:40": "/goroot/src/fmt/print.go", // hitting the real GOROOT
"a.go:1:53": "/goroot/src/builtin/builtin.go:1:1-1:1", // TODO: accurate builtin positions
},
wantDefinition: map[string]string{
Expand Down Expand Up @@ -1257,12 +1257,12 @@ func lspTests(t testing.TB, ctx context.Context, h *LangHandler, c *jsonrpc2.Con
// Install all Go packages in the $GOPATH.
oldGOPATH := os.Getenv("GOPATH")
os.Setenv("GOPATH", tmpDir)
out, err := exec.Command("go", "install", "-v", "...").CombinedOutput()
out, err := exec.Command("go", "install", "-v", "all").CombinedOutput()
os.Setenv("GOPATH", oldGOPATH)
if err != nil {
t.Fatal(err)
}
t.Logf("$ go install -v ...\n%s", out)
t.Logf("$ go install -v all\n%s", out)

testOSToVFSPath = func(osPath string) string {
return strings.TrimPrefix(osPath, util.UriToPath(util.PathToURI(tmpDir)))
Expand Down Expand Up @@ -1389,6 +1389,14 @@ func definitionTest(t testing.TB, ctx context.Context, c *jsonrpc2.Conn, rootURI
definition = strings.TrimPrefix(definition, util.UriToPath(util.PathToURI(trimPrefix)))
}
}
if want != "" && !strings.Contains(path.Base(want), ":") {
// our want is just a path, so we only check that matches. This is
// used by our godef tests into GOROOT. The GOROOT changes over time,
// but the file for a symbol is usually pretty stable.
dir := path.Dir(definition)
base := strings.Split(path.Base(definition), ":")[0]
definition = path.Join(dir, base)
}
if definition != want {
t.Errorf("got %q, want %q", definition, want)
}
Expand Down
30 changes: 24 additions & 6 deletions langserver/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ func TestLoaderDiagnostics(t *testing.T) {
cases := []struct {
Name string
FS map[string]string
Want diagnostics
// Want is a slice to cater for slight changes in error messages
// across go versions.
Want []diagnostics
}{
{
Name: "none",
Expand All @@ -99,12 +101,17 @@ func TestLoaderDiagnostics(t *testing.T) {
{
Name: "malformed",
FS: map[string]string{"/src/p/f.go": `234ljsdfjb2@#%$`},
Want: m(`{"/src/p/f.go":[{"range":{"start":{"line":0,"character":0},"end":{"line":0,"character":0}},"severity":1,"source":"go","message":"expected 'package', found 'INT' 234 (and 4 more errors)"}]}`),
Want: []diagnostics{
m(`{"/src/p/f.go":[{"range":{"start":{"line":0,"character":0},"end":{"line":0,"character":0}},"severity":1,"source":"go","message":"expected 'package', found 'INT' 234 (and 4 more errors)"}]}`),
m(`{"/src/p/f.go":[{"range":{"start":{"line":0,"character":0},"end":{"line":0,"character":0}},"severity":1,"source":"go","message":"expected 'package', found 234 (and 4 more errors)"}]}`),
},
},
{
Name: "undeclared",
FS: map[string]string{"/src/p/f.go": `package p; var _ = http.Get`},
Want: m(`{"/src/p/f.go":[{"range":{"start":{"line":0,"character":19},"end":{"line":0,"character":23}},"severity":1,"source":"go","message":"undeclared name: http"}]}`),
Want: []diagnostics{
m(`{"/src/p/f.go":[{"range":{"start":{"line":0,"character":19},"end":{"line":0,"character":23}},"severity":1,"source":"go","message":"undeclared name: http"}]}`),
},
},
}
ctx := context.Background()
Expand All @@ -115,10 +122,21 @@ func TestLoaderDiagnostics(t *testing.T) {
if err != nil {
t.Error(err)
}
if !reflect.DeepEqual(diag, tc.Want) {
found := false
for _, want := range tc.Want {
found = found || reflect.DeepEqual(diag, want)
}
if found {
return
}
var want diagnostics
if len(tc.Want) > 0 {
want = tc.Want[0]
}
if !reflect.DeepEqual(diag, want) {
got, _ := json.Marshal(diag)
want, _ := json.Marshal(tc.Want)
t.Errorf("got %s\nwant %s", string(got), string(want))
wantS, _ := json.Marshal(want)
t.Errorf("got %s\nwant %s", string(got), string(wantS))
}
})
}
Expand Down

0 comments on commit 20886c7

Please sign in to comment.