internal/lsp/tests: skip cgo tests when not supported

I really should have read the trybot results... :(

Change-Id: If2f5d1b8078827efb0cd8ea9165941864bb94d3a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/208669
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
diff --git a/internal/lsp/testdata/cgo/declarecgo_nocgo.go b/internal/lsp/testdata/cgo/declarecgo_nocgo.go
new file mode 100644
index 0000000..efc8934
--- /dev/null
+++ b/internal/lsp/testdata/cgo/declarecgo_nocgo.go
@@ -0,0 +1,6 @@
+//+build !cgo
+
+package cgo
+
+// Set a dummy marker to keep the test framework happy. The tests should be skipped.
+var _ = "Example" //@mark(funccgoexample, "Example")
diff --git a/internal/lsp/tests/tests.go b/internal/lsp/tests/tests.go
index 7919440..2b3e25b 100644
--- a/internal/lsp/tests/tests.go
+++ b/internal/lsp/tests/tests.go
@@ -14,6 +14,7 @@
 	"go/token"
 	"io/ioutil"
 	"path/filepath"
+	"runtime"
 	"sort"
 	"strconv"
 	"strings"
@@ -197,6 +198,8 @@
 	return o
 }
 
+var haveCgo = false
+
 func Load(t testing.TB, exporter packagestest.Exporter, dir string) *Data {
 	t.Helper()
 
@@ -351,6 +354,9 @@
 			for i, e := range exp {
 				t.Run(spanName(src)+"_"+strconv.Itoa(i), func(t *testing.T) {
 					t.Helper()
+					if (!haveCgo || runtime.GOOS == "android") && strings.Contains(t.Name(), "cgo") {
+						t.Skip("test requires cgo, not supported")
+					}
 					test(t, src, e, data.CompletionItems)
 				})
 			}
@@ -462,6 +468,9 @@
 		for spn, d := range data.Definitions {
 			t.Run(spanName(spn), func(t *testing.T) {
 				t.Helper()
+				if (!haveCgo || runtime.GOOS == "android") && strings.Contains(t.Name(), "cgo") {
+					t.Skip("test requires cgo, not supported")
+				}
 				tests.Definition(t, spn, d)
 			})
 		}
diff --git a/internal/lsp/tests/tests_cgo.go b/internal/lsp/tests/tests_cgo.go
new file mode 100644
index 0000000..0f823a5
--- /dev/null
+++ b/internal/lsp/tests/tests_cgo.go
@@ -0,0 +1,7 @@
+// +build cgo
+
+package tests
+
+func init() {
+	haveCgo = true
+}