From 0112737ef1243cde87956b0ea9c864fcd1f32ab6 Mon Sep 17 00:00:00 2001 From: Rebecca Stambler Date: Tue, 13 Oct 2020 01:13:42 -0400 Subject: [PATCH] gopls/internal/regtest: add a test for switching from modules to GOPATH Fixes golang/go#40487 Change-Id: I79457a8de559da2a9a3ffabdb315f4d35345c8a0 Reviewed-on: https://go-review.googlesource.com/c/tools/+/261738 Trust: Rebecca Stambler Run-TryBot: Rebecca Stambler gopls-CI: kokoro TryBot-Result: Go Bot Reviewed-by: Heschi Kreinick --- gopls/internal/regtest/watch_test.go | 40 ++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/gopls/internal/regtest/watch_test.go b/gopls/internal/regtest/watch_test.go index 1462bb3a2..3b5b69dcd 100644 --- a/gopls/internal/regtest/watch_test.go +++ b/gopls/internal/regtest/watch_test.go @@ -622,6 +622,46 @@ func main() { }) } +// Reproduces golang/go#40487. +func TestSwitchFromModulesToGOPATH(t *testing.T) { + testenv.NeedsGo1Point(t, 13) + + const files = ` +-- foo/go.mod -- +module mod.com + +go 1.14 +-- foo/blah/blah.go -- +package blah + +const Name = "" +-- foo/main.go -- +package main + +import "mod.com/blah" + +func main() { + _ = blah.Name +} +` + withOptions( + InGOPATH(), + ).run(t, files, func(t *testing.T, env *Env) { + env.OpenFile("foo/main.go") + env.RemoveWorkspaceFile("foo/go.mod") + env.Await( + OnceMet( + CompletedWork(lsp.DiagnosticWorkTitle(lsp.FromDidChangeWatchedFiles), 1), + env.DiagnosticAtRegexp("foo/main.go", `"mod.com/blah"`), + ), + ) + env.RegexpReplace("foo/main.go", `"mod.com/blah"`, `"foo/blah"`) + env.Await( + EmptyDiagnostics("foo/main.go"), + ) + }) +} + func TestNewSymbolInTestVariant(t *testing.T) { const files = ` -- go.mod --