gopls/internal/regtests: add a test for bad go.work files

Add a test that would have reproduced the panic from
golang/vscode-go#2121.

For golang/vscode-go#2121

Change-Id: Idb07dc0789b51e3056e0b3d0910916ec35931ac4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/397355
Run-TryBot: Robert Findley <rfindley@google.com>
Auto-Submit: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
diff --git a/gopls/internal/regtest/workspace/workspace_test.go b/gopls/internal/regtest/workspace/workspace_test.go
index 9289b83..9098bd4 100644
--- a/gopls/internal/regtest/workspace/workspace_test.go
+++ b/gopls/internal/regtest/workspace/workspace_test.go
@@ -644,6 +644,19 @@
 	})
 }
 
+// TestBadGoWork exercises the panic from golang/vscode-go#2121.
+func TestBadGoWork(t *testing.T) {
+	const files = `
+-- go.work --
+use ./bar
+-- bar/go.mod --
+module example.com/bar
+`
+	Run(t, files, func(t *testing.T, env *Env) {
+		env.OpenFile("go.work")
+	})
+}
+
 func TestUseGoWork(t *testing.T) {
 	// This test validates certain functionality related to using a go.work
 	// file to specify workspace modules.