@@ -239,6 +239,62 @@ require random.org v1.2.3
239
239
})
240
240
}
241
241
242
+ // Tests that multiple missing dependencies gives good single fixes.
243
+ func TestMissingDependencyFixesWithGoWork (t * testing.T ) {
244
+ testenv .NeedsGo1Point (t , 18 )
245
+ const mod = `
246
+ -- go.work --
247
+ go 1.18
248
+
249
+ use (
250
+ ./a
251
+ )
252
+ -- a/go.mod --
253
+ module mod.com
254
+
255
+ go 1.12
256
+
257
+ -- a/main.go --
258
+ package main
259
+
260
+ import "example.com/blah"
261
+ import "random.org/blah"
262
+
263
+ var _, _ = blah.Name, hello.Name
264
+ `
265
+
266
+ const want = `module mod.com
267
+
268
+ go 1.12
269
+
270
+ require random.org v1.2.3
271
+ `
272
+
273
+ RunMultiple {
274
+ {"default" , WithOptions (ProxyFiles (proxy ), WorkspaceFolders ("a" ))},
275
+ {"nested" , WithOptions (ProxyFiles (proxy ))},
276
+ }.Run (t , mod , func (t * testing.T , env * Env ) {
277
+ env .OpenFile ("a/main.go" )
278
+ var d protocol.PublishDiagnosticsParams
279
+ env .Await (
280
+ OnceMet (
281
+ env .DiagnosticAtRegexp ("a/main.go" , `"random.org/blah"` ),
282
+ ReadDiagnostics ("a/main.go" , & d ),
283
+ ),
284
+ )
285
+ var randomDiag protocol.Diagnostic
286
+ for _ , diag := range d .Diagnostics {
287
+ if strings .Contains (diag .Message , "random.org" ) {
288
+ randomDiag = diag
289
+ }
290
+ }
291
+ env .ApplyQuickFixes ("a/main.go" , []protocol.Diagnostic {randomDiag })
292
+ if got := env .ReadWorkspaceFile ("a/go.mod" ); got != want {
293
+ t .Fatalf ("unexpected go.mod content:\n %s" , tests .Diff (t , want , got ))
294
+ }
295
+ })
296
+ }
297
+
242
298
func TestIndirectDependencyFix (t * testing.T ) {
243
299
testenv .NeedsGo1Point (t , 14 )
244
300
0 commit comments