From ec925d8b1dc677f68459b76cf257574a0678bc75 Mon Sep 17 00:00:00 2001 From: Rebecca Stambler Date: Fri, 9 Oct 2020 23:02:04 -0400 Subject: [PATCH] gopls/internal/regtest: add a failing test for swig Fixes golang/go#37660 Change-Id: I4607142af03224820e8350a85eca722586b150b5 Reviewed-on: https://go-review.googlesource.com/c/tools/+/261140 Trust: Rebecca Stambler Run-TryBot: Rebecca Stambler gopls-CI: kokoro TryBot-Result: Go Bot Reviewed-by: Robert Findley --- gopls/internal/regtest/diagnostics_test.go | 45 ++++++++++++++++++++++ gopls/internal/regtest/expectation.go | 27 +++++++++++++ 2 files changed, 72 insertions(+) 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, + } +}