@@ -234,6 +234,7 @@ func Hello() {}
234
234
`
235
235
236
236
func TestAutomaticWorkspaceModule_Interdependent (t * testing.T ) {
237
+ testenv .NeedsGo1Point (t , 18 ) // uses go.work
237
238
const multiModule = `
238
239
-- moda/a/go.mod --
239
240
module a.com
@@ -265,17 +266,18 @@ func Hello() int {
265
266
`
266
267
WithOptions (
267
268
ProxyFiles (workspaceModuleProxy ),
268
- Modes (Experimental ),
269
269
).Run (t , multiModule , func (t * testing.T , env * Env ) {
270
- env .Await (
270
+ env .RunGoCommand ("work" , "init" )
271
+ env .RunGoCommand ("work" , "use" , "-r" , "." )
272
+ env .AfterChange (
271
273
env .DiagnosticAtRegexp ("moda/a/a.go" , "x" ),
272
274
env .DiagnosticAtRegexp ("modb/b/b.go" , "x" ),
273
275
env .NoDiagnosticAtRegexp ("moda/a/a.go" , `"b.com/b"` ),
274
276
)
275
277
})
276
278
}
277
279
278
- func TestMultiModuleWithExclude (t * testing.T ) {
280
+ func TestModuleWithExclude (t * testing.T ) {
279
281
const proxy = `
280
282
281
283
module c.com
@@ -323,7 +325,6 @@ func main() {
323
325
`
324
326
WithOptions (
325
327
ProxyFiles (proxy ),
326
- Modes (Experimental ),
327
328
).Run (t , multiModule , func (t * testing.T , env * Env ) {
328
329
env .Await (
329
330
env .DiagnosticAtRegexp ("main.go" , "x" ),
@@ -337,9 +338,15 @@ func main() {
337
338
// TODO(golang/go#55331): delete this placeholder along with experimental
338
339
// workspace module.
339
340
func TestDeleteModule_Interdependent (t * testing.T ) {
340
- t .Skip ("golang/go#55331: the experimental workspace module is scheduled for deletion" )
341
-
341
+ testenv .NeedsGo1Point (t , 18 ) // uses go.work
342
342
const multiModule = `
343
+ -- go.work --
344
+ go 1.18
345
+
346
+ use (
347
+ moda/a
348
+ modb
349
+ )
343
350
-- moda/a/go.mod --
344
351
module a.com
345
352
@@ -370,7 +377,6 @@ func Hello() int {
370
377
`
371
378
WithOptions (
372
379
ProxyFiles (workspaceModuleProxy ),
373
- Modes (Experimental ),
374
380
).Run (t , multiModule , func (t * testing.T , env * Env ) {
375
381
env .OpenFile ("moda/a/a.go" )
376
382
env .Await (env .DoneWithOpen ())
@@ -380,13 +386,12 @@ func Hello() int {
380
386
t .Errorf ("expected %s, got %v" , want , original )
381
387
}
382
388
env .CloseBuffer (original )
383
- env .Await ( env . DoneWithClose () )
389
+ env .AfterChange ( )
384
390
385
391
env .RemoveWorkspaceFile ("modb/b/b.go" )
386
392
env .RemoveWorkspaceFile ("modb/go.mod" )
387
- env .Await (
388
- env .DoneWithChangeWatchedFiles (),
389
- )
393
+ env .WriteWorkspaceFile ("go.work" , "go 1.18\n use moda/a" )
394
+ env .AfterChange ()
390
395
391
396
got , _ := env .GoToDefinition ("moda/a/a.go" , env .RegexpSearch ("moda/a/a.go" , "Hello" ))
392
397
if want := "[email protected] /b/b.go" ;
! strings .
HasSuffix (
got ,
want ) {
@@ -398,7 +403,14 @@ func Hello() int {
398
403
// Tests that the version of the module used changes after it has been added
399
404
// to the workspace.
400
405
func TestCreateModule_Interdependent (t * testing.T ) {
406
+ testenv .NeedsGo1Point (t , 18 ) // uses go.work
401
407
const multiModule = `
408
+ -- go.work --
409
+ go 1.18
410
+
411
+ use (
412
+ moda/a
413
+ )
402
414
-- moda/a/go.mod --
403
415
module a.com
404
416
@@ -419,7 +431,6 @@ func main() {
419
431
}
420
432
`
421
433
WithOptions (
422
- Modes (Experimental ),
423
434
ProxyFiles (workspaceModuleProxy ),
424
435
).Run (t , multiModule , func (t * testing.T , env * Env ) {
425
436
env .OpenFile ("moda/a/a.go" )
@@ -429,6 +440,13 @@ func main() {
429
440
}
430
441
env .CloseBuffer (original )
431
442
env .WriteWorkspaceFiles (map [string ]string {
443
+ "go.work" : `go 1.18
444
+
445
+ use (
446
+ moda/a
447
+ modb
448
+ )
449
+ ` ,
432
450
"modb/go.mod" : "module b.com" ,
433
451
"modb/b/b.go" : `package b
434
452
@@ -437,12 +455,7 @@ func Hello() int {
437
455
}
438
456
` ,
439
457
})
440
- env .Await (
441
- OnceMet (
442
- env .DoneWithChangeWatchedFiles (),
443
- env .DiagnosticAtRegexp ("modb/b/b.go" , "x" ),
444
- ),
445
- )
458
+ env .AfterChange (env .DiagnosticAtRegexp ("modb/b/b.go" , "x" ))
446
459
got , _ := env .GoToDefinition ("moda/a/a.go" , env .RegexpSearch ("moda/a/a.go" , "Hello" ))
447
460
if want := "modb/b/b.go" ; ! strings .HasSuffix (got , want ) {
448
461
t .Errorf ("expected %s, got %v" , want , original )
@@ -453,7 +466,17 @@ func Hello() int {
453
466
// This test confirms that a gopls workspace can recover from initialization
454
467
// with one invalid module.
455
468
func TestOneBrokenModule (t * testing.T ) {
469
+ t .Skip ("golang/go#55331: this test is temporarily broken as go.work handling tries to build the workspace module" )
470
+
471
+ testenv .NeedsGo1Point (t , 18 ) // uses go.work
456
472
const multiModule = `
473
+ -- go.work --
474
+ go 1.18
475
+
476
+ use (
477
+ moda/a
478
+ modb
479
+ )
457
480
-- moda/a/go.mod --
458
481
module a.com
459
482
@@ -482,7 +505,6 @@ func Hello() int {
482
505
`
483
506
WithOptions (
484
507
ProxyFiles (workspaceModuleProxy ),
485
- Modes (Experimental ),
486
508
).Run (t , multiModule , func (t * testing.T , env * Env ) {
487
509
env .OpenFile ("modb/go.mod" )
488
510
env .Await (
@@ -941,8 +963,32 @@ var _ = fmt.Printf
941
963
})
942
964
}
943
965
944
- func TestMultiModuleV2 (t * testing.T ) {
966
+ func TestGoWork_V2Module (t * testing.T ) {
967
+ testenv .NeedsGo1Point (t , 18 ) // uses go.work
968
+ // When using a go.work, we must have proxy content even if it is replaced.
969
+ const proxy = `
970
+ -- b.com/[email protected] /go.mod --
971
+ module b.com/v2
972
+
973
+ go 1.12
974
+ -- b.com/[email protected] /b/b.go --
975
+ package b
976
+
977
+ func Ciao()() int {
978
+ return 0
979
+ }
980
+ `
981
+
945
982
const multiModule = `
983
+ -- go.work --
984
+ go 1.18
985
+
986
+ use (
987
+ moda/a
988
+ modb
989
+ modb/v2
990
+ modc
991
+ )
946
992
-- moda/a/go.mod --
947
993
module a.com
948
994
@@ -985,22 +1031,42 @@ func main() {
985
1031
var x int
986
1032
}
987
1033
`
1034
+
988
1035
WithOptions (
989
- Modes ( Experimental ),
1036
+ ProxyFiles ( proxy ),
990
1037
).Run (t , multiModule , func (t * testing.T , env * Env ) {
991
1038
env .Await (
992
- env .DiagnosticAtRegexp ("moda/a/a.go" , "x" ),
993
- env .DiagnosticAtRegexp ("modb/b/b.go" , "x" ),
994
- env .DiagnosticAtRegexp ("modb/v2/b/b.go" , "x" ),
995
- env .DiagnosticAtRegexp ("modc/main.go" , "x" ),
1039
+ OnceMet (
1040
+ InitialWorkspaceLoad ,
1041
+ // TODO(rfindley): assert on the full set of diagnostics here. We
1042
+ // should ensure that we don't have a diagnostic at b.Hi in a.go.
1043
+ env .DiagnosticAtRegexp ("moda/a/a.go" , "x" ),
1044
+ env .DiagnosticAtRegexp ("modb/b/b.go" , "x" ),
1045
+ env .DiagnosticAtRegexp ("modb/v2/b/b.go" , "x" ),
1046
+ env .DiagnosticAtRegexp ("modc/main.go" , "x" ),
1047
+ ),
996
1048
)
997
1049
})
998
1050
}
999
1051
1000
1052
// Confirm that a fix for a tidy module will correct all modules in the
1001
1053
// workspace.
1002
1054
func TestMultiModule_OneBrokenModule (t * testing.T ) {
1003
- const mod = `
1055
+ // In the earlier 'experimental workspace mode', gopls would aggregate go.sum
1056
+ // entries for the workspace module, allowing it to correctly associate
1057
+ // missing go.sum with diagnostics. With go.work files, this doesn't work:
1058
+ // the go.command will happily write go.work.sum.
1059
+ t .Skip ("golang/go#57509: go.mod diagnostics do not work in go.work mode" )
1060
+ testenv .NeedsGo1Point (t , 18 ) // uses go.work
1061
+ const files = `
1062
+ -- go.work --
1063
+ go 1.18
1064
+
1065
+ use (
1066
+ a
1067
+ b
1068
+ )
1069
+ -- go.work.sum --
1004
1070
-- a/go.mod --
1005
1071
module a.com
1006
1072
@@ -1027,8 +1093,7 @@ func main() {
1027
1093
`
1028
1094
WithOptions (
1029
1095
ProxyFiles (workspaceProxy ),
1030
- Modes (Experimental ),
1031
- ).Run (t , mod , func (t * testing.T , env * Env ) {
1096
+ ).Run (t , files , func (t * testing.T , env * Env ) {
1032
1097
params := & protocol.PublishDiagnosticsParams {}
1033
1098
env .OpenFile ("b/go.mod" )
1034
1099
env .Await (
0 commit comments