From 44db4ebc77065950a456a990d2eeb9b0b0dd2471 Mon Sep 17 00:00:00 2001 From: Robert Findley Date: Thu, 31 Mar 2022 15:38:16 -0400 Subject: [PATCH] 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 Auto-Submit: Robert Findley gopls-CI: kokoro Reviewed-by: Hyang-Ah Hana Kim TryBot-Result: Gopher Robot --- gopls/internal/regtest/workspace/workspace_test.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/gopls/internal/regtest/workspace/workspace_test.go b/gopls/internal/regtest/workspace/workspace_test.go index 9289b83735..9098bd4c5a 100644 --- a/gopls/internal/regtest/workspace/workspace_test.go +++ b/gopls/internal/regtest/workspace/workspace_test.go @@ -644,6 +644,19 @@ replace a.com => %s/moda/a }) } +// 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.