Skip to content

Commit 11a5667

Browse files
stamblerrefindleyr
authored andcommitted
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 <[email protected]> Run-TryBot: Rebecca Stambler <[email protected]> gopls-CI: kokoro <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Robert Findley <[email protected]>
1 parent 5b43ef9 commit 11a5667

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

gopls/internal/regtest/modfile_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package regtest
66

77
import (
8+
"path/filepath"
89
"strings"
910
"testing"
1011

@@ -770,3 +771,42 @@ func main() {
770771
)
771772
})
772773
}
774+
775+
// This test confirms that editing a go.mod file only causes metadata
776+
// to be invalidated when it's saved.
777+
func TestGoModInvalidatesOnSave(t *testing.T) {
778+
t.Skipf("golang/go#42529 has not been resolved yet.")
779+
780+
const mod = `
781+
-- go.mod --
782+
module mod.com
783+
784+
go 1.12
785+
-- main.go --
786+
package main
787+
788+
func main() {
789+
hello()
790+
}
791+
-- hello.go --
792+
package main
793+
794+
func hello() {}
795+
`
796+
run(t, mod, func(t *testing.T, env *Env) {
797+
env.OpenFile("go.mod")
798+
env.RegexpReplace("go.mod", "module", "modul")
799+
// Confirm that we still have metadata with only on-disk edits.
800+
env.OpenFile("main.go")
801+
file, _ := env.GoToDefinition("main.go", env.RegexpSearch("main.go", "hello"))
802+
if filepath.Base(file) != "hello.go" {
803+
t.Fatalf("expected definition in hello.go, got %s", file)
804+
}
805+
// Confirm that we no longer have metadata when the file is saved.
806+
env.Editor.SaveBufferWithoutActions(env.Ctx, "go.mod")
807+
_, _, err := env.Editor.GoToDefinition(env.Ctx, "main.go", env.RegexpSearch("main.go", "hello"))
808+
if err == nil {
809+
t.Fatalf("expected error, got none")
810+
}
811+
})
812+
}

0 commit comments

Comments
 (0)