1
0
mirror of https://github.com/golang/go synced 2024-11-18 14:14:46 -07:00

internal/lsp: make all the tests work on 1.10

Also improve the error messages from a failing diagnostic tests so you can read
them.

Change-Id: I3554ce5a029de22a55a9636ed26ba02d95fc3246
Reviewed-on: https://go-review.googlesource.com/c/150042
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
Ian Cottrell 2018-11-16 18:15:25 -05:00
parent 31e4346e36
commit 68f7e630ce
5 changed files with 40 additions and 7 deletions

View File

@ -7,6 +7,7 @@ package lsp
import (
"bytes"
"context"
"fmt"
"go/token"
"os/exec"
"path/filepath"
@ -184,7 +185,16 @@ func testDiagnostics(t *testing.T, v *source.View, pkgs []*packages.Package, wan
})
want := wants[filename]
if equal := reflect.DeepEqual(want, got); !equal {
t.Errorf("diagnostics failed for %s: (expected: %v), (got: %v)", filepath.Base(filename), want, got)
msg := &bytes.Buffer{}
fmt.Fprintf(msg, "diagnostics failed for %s: expected:\n", filepath.Base(filename))
for _, d := range want {
fmt.Fprintf(msg, " %v\n", d)
}
fmt.Fprintf(msg, "got:\n")
for _, d := range got {
fmt.Fprintf(msg, " %v\n", d)
}
t.Error(msg.String())
}
}
}

View File

@ -37,3 +37,20 @@ func (r Range) Format(f fmt.State, c rune) {
func (l Location) Format(f fmt.State, c rune) {
fmt.Fprintf(f, "%s:%v", l.URI, l.Range)
}
func (s DiagnosticSeverity) Format(f fmt.State, c rune) {
switch s {
case SeverityError:
fmt.Fprint(f, "Error")
case SeverityWarning:
fmt.Fprint(f, "Warning")
case SeverityInformation:
fmt.Fprint(f, "Information")
case SeverityHint:
fmt.Fprint(f, "Hint")
}
}
func (d Diagnostic) Format(f fmt.State, c rune) {
fmt.Fprintf(f, "%v:%v from %v at %v: %v", d.Severity, d.Code, d.Source, d.Range, d.Message)
}

View File

@ -1,5 +1,3 @@
// +build go1.11
package bad
func stuff() {
@ -14,8 +12,7 @@ type bob struct {
}
func _() {
var q int
_ = &bob{
f: q, //@diag("f", "unknown field f in struct literal")
f: 0, //@diag("f", "unknown field f in struct literal")
}
}

View File

@ -1,5 +1,3 @@
// +build go1.11
package bad
func random2(y int) int {

View File

@ -0,0 +1,11 @@
// +build !go1.11
// This file does not actually test anything
// on 1.10 the errors are different
package noparse_format
func what() {
// we need a diagnostic below so we have the same count as the main file
var b int //@diag("b", "b declared but not used")
if true {}
}