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>
diff --git a/internal/lsp/lsp_test.go b/internal/lsp/lsp_test.go
index 418da42..840966d 100644
--- a/internal/lsp/lsp_test.go
+++ b/internal/lsp/lsp_test.go
@@ -7,6 +7,7 @@
import (
"bytes"
"context"
+ "fmt"
"go/token"
"os/exec"
"path/filepath"
@@ -184,7 +185,16 @@
})
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())
}
}
}
diff --git a/internal/lsp/protocol/printers.go b/internal/lsp/protocol/printers.go
index e658af9..f4f80db 100644
--- a/internal/lsp/protocol/printers.go
+++ b/internal/lsp/protocol/printers.go
@@ -37,3 +37,20 @@
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)
+}
diff --git a/internal/lsp/testdata/bad/bad.go b/internal/lsp/testdata/bad/bad.go
index 8500d06..75f728e 100644
--- a/internal/lsp/testdata/bad/bad.go
+++ b/internal/lsp/testdata/bad/bad.go
@@ -1,5 +1,3 @@
-// +build go1.11
-
package bad
func stuff() {
@@ -14,8 +12,7 @@
}
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")
}
}
diff --git a/internal/lsp/testdata/bad/bad_util.go b/internal/lsp/testdata/bad/bad_util.go
index f6a0e7d..9ab8a73 100644
--- a/internal/lsp/testdata/bad/bad_util.go
+++ b/internal/lsp/testdata/bad/bad_util.go
@@ -1,5 +1,3 @@
-// +build go1.11
-
package bad
func random2(y int) int {
diff --git a/internal/lsp/testdata/noparse_format/noparse_format.1_10.go.in b/internal/lsp/testdata/noparse_format/noparse_format.1_10.go.in
new file mode 100644
index 0000000..f450053
--- /dev/null
+++ b/internal/lsp/testdata/noparse_format/noparse_format.1_10.go.in
@@ -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 {}
+}
\ No newline at end of file