Skip to content

Commit

Permalink
gopls/internal/regtest: test metadata validation only on save for go.mod
Browse files Browse the repository at this point in the history
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 <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
  • Loading branch information
stamblerre authored and findleyr committed Dec 17, 2020
1 parent 5b43ef9 commit 11a5667
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions gopls/internal/regtest/modfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package regtest

import (
"path/filepath"
"strings"
"testing"

Expand Down Expand Up @@ -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")
}
})
}

0 comments on commit 11a5667

Please sign in to comment.