diff --git a/gopls/internal/regtest/diagnostics_test.go b/gopls/internal/regtest/diagnostics_test.go index 109561af665..9d652e18272 100644 --- a/gopls/internal/regtest/diagnostics_test.go +++ b/gopls/internal/regtest/diagnostics_test.go @@ -1382,3 +1382,48 @@ func main() { ) }) } + +func TestSwig(t *testing.T) { + t.Skipf("skipped until golang/go#37098 is resolved") + + const mod = ` +-- go.mod -- +module mod.com +-- pkg/simple/export_swig.go -- +package simple + +func ExportSimple(x, y int) int { + return Gcd(x, y) +} +-- pkg/simple/simple.swigcxx -- +%module simple + +%inline %{ +extern int gcd(int x, int y) +{ + int g; + g = y; + while (x > 0) { + g = x; + x = y % x; + y = g; + } + return g; +} +%} +-- main.go -- +package a + +func main() { + var x int +} +` + run(t, mod, func(t *testing.T, env *Env) { + env.Await( + OnceMet( + InitialWorkspaceLoad, + NoDiagnosticWithMessage("illegal character U+0023 '#'"), + ), + ) + }) +} diff --git a/gopls/internal/regtest/expectation.go b/gopls/internal/regtest/expectation.go index 697363f0af6..70601cc8cf5 100644 --- a/gopls/internal/regtest/expectation.go +++ b/gopls/internal/regtest/expectation.go @@ -11,6 +11,7 @@ import ( "golang.org/x/tools/internal/lsp" "golang.org/x/tools/internal/lsp/protocol" + "golang.org/x/tools/internal/span" ) // An Expectation asserts that the state of the editor at a point in time @@ -491,3 +492,29 @@ func NoDiagnosticAt(name string, line, col int) DiagnosticExpectation { path: name, } } + +// NoDiagnosticWithMessage asserts that there is no diagnostic entry with the +// given message. +// +// This should only be used in combination with OnceMet for a given condition, +// otherwise it may always succeed. +func NoDiagnosticWithMessage(msg string) DiagnosticExpectation { + var uri span.URI + isMet := func(diags *protocol.PublishDiagnosticsParams) bool { + for _, d := range diags.Diagnostics { + if d.Message == msg { + return true + } + } + return false + } + var path string + if uri != "" { + path = uri.Filename() + } + return DiagnosticExpectation{ + isMet: isMet, + description: fmt.Sprintf("no diagnostic with message %s", msg), + path: path, + } +}