From 11a5667e27eeb5c7205b7f41cbe8450d7bcdbfd4 Mon Sep 17 00:00:00 2001 From: Rebecca Stambler Date: Thu, 17 Dec 2020 16:59:26 -0500 Subject: [PATCH] gopls/internal/regtest: test metadata validation only on save for go.mod There was never a test that actually confirmed that golang/go#42529 was fixed, so it never actually was. Updates golang/go#42529 Change-Id: I4264162e98c5fde804c780e098a1d4e21a2d88d8 Reviewed-on: https://go-review.googlesource.com/c/tools/+/279033 Trust: Rebecca Stambler Run-TryBot: Rebecca Stambler gopls-CI: kokoro TryBot-Result: Go Bot Reviewed-by: Robert Findley --- gopls/internal/regtest/modfile_test.go | 40 ++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/gopls/internal/regtest/modfile_test.go b/gopls/internal/regtest/modfile_test.go index 1af4893491..3c7d6aac96 100644 --- a/gopls/internal/regtest/modfile_test.go +++ b/gopls/internal/regtest/modfile_test.go @@ -5,6 +5,7 @@ package regtest import ( + "path/filepath" "strings" "testing" @@ -770,3 +771,42 @@ func main() { ) }) } + +// This test confirms that editing a go.mod file only causes metadata +// to be invalidated when it's saved. +func TestGoModInvalidatesOnSave(t *testing.T) { + t.Skipf("golang/go#42529 has not been resolved yet.") + + const mod = ` +-- go.mod -- +module mod.com + +go 1.12 +-- main.go -- +package main + +func main() { + hello() +} +-- hello.go -- +package main + +func hello() {} +` + run(t, mod, func(t *testing.T, env *Env) { + env.OpenFile("go.mod") + env.RegexpReplace("go.mod", "module", "modul") + // Confirm that we still have metadata with only on-disk edits. + env.OpenFile("main.go") + file, _ := env.GoToDefinition("main.go", env.RegexpSearch("main.go", "hello")) + if filepath.Base(file) != "hello.go" { + t.Fatalf("expected definition in hello.go, got %s", file) + } + // Confirm that we no longer have metadata when the file is saved. + env.Editor.SaveBufferWithoutActions(env.Ctx, "go.mod") + _, _, err := env.Editor.GoToDefinition(env.Ctx, "main.go", env.RegexpSearch("main.go", "hello")) + if err == nil { + t.Fatalf("expected error, got none") + } + }) +}