Skip to content

Commit 310ea71

Browse files
committed
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 <[email protected]> gopls-CI: kokoro <[email protected]> Reviewed-by: Suzy Mueller <[email protected]> Run-TryBot: Robert Findley <[email protected]>
1 parent 21861e6 commit 310ea71

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

gopls/internal/regtest/workspace/metadata_test.go

+60
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,63 @@ const C = 42
4141
))
4242
})
4343
}
44+
45+
// Test that moving ignoring a file via build constraints causes diagnostics to
46+
// be resolved.
47+
func TestIgnoreFile(t *testing.T) {
48+
testenv.NeedsGo1Point(t, 16) // needs native overlays
49+
50+
const src = `
51+
-- go.mod --
52+
module mod.test
53+
54+
go 1.12
55+
-- foo.go --
56+
package main
57+
58+
func main() {}
59+
-- bar.go --
60+
package main
61+
62+
func main() {}
63+
`
64+
65+
WithOptions(
66+
// TODO(golang/go#54180): we don't run in 'experimental' mode here, because
67+
// with "experimentalUseInvalidMetadata", this test fails because the
68+
// orphaned bar.go is diagnosed using stale metadata, and then not
69+
// re-diagnosed when new metadata arrives.
70+
//
71+
// We could fix this by re-running diagnostics after a load, but should
72+
// consider whether that is worthwhile.
73+
Modes(Default),
74+
).Run(t, src, func(t *testing.T, env *Env) {
75+
env.OpenFile("foo.go")
76+
env.OpenFile("bar.go")
77+
env.Await(
78+
OnceMet(
79+
env.DoneWithOpen(),
80+
env.DiagnosticAtRegexp("foo.go", "func (main)"),
81+
env.DiagnosticAtRegexp("bar.go", "func (main)"),
82+
),
83+
)
84+
// Ignore bar.go. This should resolve diagnostics.
85+
env.RegexpReplace("bar.go", "package main", "// +build ignore\n\npackage main")
86+
87+
// To make this test pass with experimentalUseInvalidMetadata, we could make
88+
// an arbitrary edit that invalidates the snapshot, at which point the
89+
// orphaned diagnostics will be invalidated.
90+
//
91+
// But of course, this should not be necessary: we should invalidate stale
92+
// information when fresh metadata arrives.
93+
// env.RegexpReplace("foo.go", "package main", "package main // test")
94+
env.Await(
95+
OnceMet(
96+
env.DoneWithChange(),
97+
EmptyDiagnostics("foo.go"),
98+
env.DiagnosticAtRegexpWithMessage("bar.go", "package (main)", "No packages"),
99+
env.NoDiagnosticAtRegexp("bar.go", "func (main)"),
100+
),
101+
)
102+
})
103+
}

0 commit comments

Comments
 (0)