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 <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
diff --git a/gopls/internal/regtest/diagnostics_test.go b/gopls/internal/regtest/diagnostics_test.go
index 109561a..9d652e1 100644
--- a/gopls/internal/regtest/diagnostics_test.go
+++ b/gopls/internal/regtest/diagnostics_test.go
@@ -1382,3 +1382,48 @@
 		)
 	})
 }
+
+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 697363f..70601cc 100644
--- a/gopls/internal/regtest/expectation.go
+++ b/gopls/internal/regtest/expectation.go
@@ -11,6 +11,7 @@
 
 	"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 @@
 		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,
+	}
+}