mirror of https://github.com/golang/go.git
gopls/internal/regtest: add a test that ignoring a file resolves errors
Add a test that when a user adds a "//go:build ignore" to a file, gopls correctly invalidates diagnostics. This used to be broken, but was fixed by CL 417576. Fixes golang/go#54147 Change-Id: I554fcfc0a56b72f657e19b3c0ae53a66d1a99a76 Reviewed-on: https://go-review.googlesource.com/c/tools/+/420537 TryBot-Result: Gopher Robot <gobot@golang.org> gopls-CI: kokoro <noreply+kokoro@google.com> Reviewed-by: Suzy Mueller <suzmue@golang.org> Run-TryBot: Robert Findley <rfindley@google.com>
This commit is contained in:
parent
21861e6be5
commit
310ea71b71
|
|
@ -41,3 +41,63 @@ const C = 42
|
|||
))
|
||||
})
|
||||
}
|
||||
|
||||
// Test that moving ignoring a file via build constraints causes diagnostics to
|
||||
// be resolved.
|
||||
func TestIgnoreFile(t *testing.T) {
|
||||
testenv.NeedsGo1Point(t, 16) // needs native overlays
|
||||
|
||||
const src = `
|
||||
-- go.mod --
|
||||
module mod.test
|
||||
|
||||
go 1.12
|
||||
-- foo.go --
|
||||
package main
|
||||
|
||||
func main() {}
|
||||
-- bar.go --
|
||||
package main
|
||||
|
||||
func main() {}
|
||||
`
|
||||
|
||||
WithOptions(
|
||||
// TODO(golang/go#54180): we don't run in 'experimental' mode here, because
|
||||
// with "experimentalUseInvalidMetadata", this test fails because the
|
||||
// orphaned bar.go is diagnosed using stale metadata, and then not
|
||||
// re-diagnosed when new metadata arrives.
|
||||
//
|
||||
// We could fix this by re-running diagnostics after a load, but should
|
||||
// consider whether that is worthwhile.
|
||||
Modes(Default),
|
||||
).Run(t, src, func(t *testing.T, env *Env) {
|
||||
env.OpenFile("foo.go")
|
||||
env.OpenFile("bar.go")
|
||||
env.Await(
|
||||
OnceMet(
|
||||
env.DoneWithOpen(),
|
||||
env.DiagnosticAtRegexp("foo.go", "func (main)"),
|
||||
env.DiagnosticAtRegexp("bar.go", "func (main)"),
|
||||
),
|
||||
)
|
||||
// Ignore bar.go. This should resolve diagnostics.
|
||||
env.RegexpReplace("bar.go", "package main", "// +build ignore\n\npackage main")
|
||||
|
||||
// To make this test pass with experimentalUseInvalidMetadata, we could make
|
||||
// an arbitrary edit that invalidates the snapshot, at which point the
|
||||
// orphaned diagnostics will be invalidated.
|
||||
//
|
||||
// But of course, this should not be necessary: we should invalidate stale
|
||||
// information when fresh metadata arrives.
|
||||
// env.RegexpReplace("foo.go", "package main", "package main // test")
|
||||
env.Await(
|
||||
OnceMet(
|
||||
env.DoneWithChange(),
|
||||
EmptyDiagnostics("foo.go"),
|
||||
env.DiagnosticAtRegexpWithMessage("bar.go", "package (main)", "No packages"),
|
||||
env.NoDiagnosticAtRegexp("bar.go", "func (main)"),
|
||||
),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue