@@ -41,3 +41,63 @@ const C = 42
41
41
))
42
42
})
43
43
}
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 \n package 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