@@ -234,6 +234,7 @@ func Hello() {}
234234`
235235
236236func TestAutomaticWorkspaceModule_Interdependent (t * testing.T ) {
237+ testenv .NeedsGo1Point (t , 18 ) // uses go.work
237238 const multiModule = `
238239-- moda/a/go.mod --
239240module a.com
@@ -265,17 +266,18 @@ func Hello() int {
265266`
266267 WithOptions (
267268 ProxyFiles (workspaceModuleProxy ),
268- Modes (Experimental ),
269269 ).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 (
271273 env .DiagnosticAtRegexp ("moda/a/a.go" , "x" ),
272274 env .DiagnosticAtRegexp ("modb/b/b.go" , "x" ),
273275 env .NoDiagnosticAtRegexp ("moda/a/a.go" , `"b.com/b"` ),
274276 )
275277 })
276278}
277279
278- func TestMultiModuleWithExclude (t * testing.T ) {
280+ func TestModuleWithExclude (t * testing.T ) {
279281 const proxy = `
280282-- c.com@v1.2.3/go.mod --
281283module c.com
@@ -323,7 +325,6 @@ func main() {
323325`
324326 WithOptions (
325327 ProxyFiles (proxy ),
326- Modes (Experimental ),
327328 ).Run (t , multiModule , func (t * testing.T , env * Env ) {
328329 env .Await (
329330 env .DiagnosticAtRegexp ("main.go" , "x" ),
@@ -337,9 +338,15 @@ func main() {
337338// TODO(golang/go#55331): delete this placeholder along with experimental
338339// workspace module.
339340func 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
342342 const multiModule = `
343+ -- go.work --
344+ go 1.18
345+
346+ use (
347+ moda/a
348+ modb
349+ )
343350-- moda/a/go.mod --
344351module a.com
345352
@@ -370,7 +377,6 @@ func Hello() int {
370377`
371378 WithOptions (
372379 ProxyFiles (workspaceModuleProxy ),
373- Modes (Experimental ),
374380 ).Run (t , multiModule , func (t * testing.T , env * Env ) {
375381 env .OpenFile ("moda/a/a.go" )
376382 env .Await (env .DoneWithOpen ())
@@ -380,13 +386,12 @@ func Hello() int {
380386 t .Errorf ("expected %s, got %v" , want , original )
381387 }
382388 env .CloseBuffer (original )
383- env .Await ( env . DoneWithClose () )
389+ env .AfterChange ( )
384390
385391 env .RemoveWorkspaceFile ("modb/b/b.go" )
386392 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 ()
390395
391396 got , _ := env .GoToDefinition ("moda/a/a.go" , env .RegexpSearch ("moda/a/a.go" , "Hello" ))
392397 if want := "b.com@v1.2.3/b/b.go" ; ! strings .HasSuffix (got , want ) {
@@ -398,7 +403,14 @@ func Hello() int {
398403// Tests that the version of the module used changes after it has been added
399404// to the workspace.
400405func TestCreateModule_Interdependent (t * testing.T ) {
406+ testenv .NeedsGo1Point (t , 18 ) // uses go.work
401407 const multiModule = `
408+ -- go.work --
409+ go 1.18
410+
411+ use (
412+ moda/a
413+ )
402414-- moda/a/go.mod --
403415module a.com
404416
@@ -419,7 +431,6 @@ func main() {
419431}
420432`
421433 WithOptions (
422- Modes (Experimental ),
423434 ProxyFiles (workspaceModuleProxy ),
424435 ).Run (t , multiModule , func (t * testing.T , env * Env ) {
425436 env .OpenFile ("moda/a/a.go" )
@@ -429,6 +440,13 @@ func main() {
429440 }
430441 env .CloseBuffer (original )
431442 env .WriteWorkspaceFiles (map [string ]string {
443+ "go.work" : `go 1.18
444+
445+ use (
446+ moda/a
447+ modb
448+ )
449+ ` ,
432450 "modb/go.mod" : "module b.com" ,
433451 "modb/b/b.go" : `package b
434452
@@ -437,12 +455,7 @@ func Hello() int {
437455}
438456` ,
439457 })
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" ))
446459 got , _ := env .GoToDefinition ("moda/a/a.go" , env .RegexpSearch ("moda/a/a.go" , "Hello" ))
447460 if want := "modb/b/b.go" ; ! strings .HasSuffix (got , want ) {
448461 t .Errorf ("expected %s, got %v" , want , original )
@@ -453,7 +466,17 @@ func Hello() int {
453466// This test confirms that a gopls workspace can recover from initialization
454467// with one invalid module.
455468func 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
456472 const multiModule = `
473+ -- go.work --
474+ go 1.18
475+
476+ use (
477+ moda/a
478+ modb
479+ )
457480-- moda/a/go.mod --
458481module a.com
459482
@@ -482,7 +505,6 @@ func Hello() int {
482505`
483506 WithOptions (
484507 ProxyFiles (workspaceModuleProxy ),
485- Modes (Experimental ),
486508 ).Run (t , multiModule , func (t * testing.T , env * Env ) {
487509 env .OpenFile ("modb/go.mod" )
488510 env .Await (
@@ -941,8 +963,32 @@ var _ = fmt.Printf
941963 })
942964}
943965
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/v2@v2.1.9/go.mod --
971+ module b.com/v2
972+
973+ go 1.12
974+ -- b.com/v2@v2.1.9/b/b.go --
975+ package b
976+
977+ func Ciao()() int {
978+ return 0
979+ }
980+ `
981+
945982 const multiModule = `
983+ -- go.work --
984+ go 1.18
985+
986+ use (
987+ moda/a
988+ modb
989+ modb/v2
990+ modc
991+ )
946992-- moda/a/go.mod --
947993module a.com
948994
@@ -985,22 +1031,42 @@ func main() {
9851031 var x int
9861032}
9871033`
1034+
9881035 WithOptions (
989- Modes ( Experimental ),
1036+ ProxyFiles ( proxy ),
9901037 ).Run (t , multiModule , func (t * testing.T , env * Env ) {
9911038 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+ ),
9961048 )
9971049 })
9981050}
9991051
10001052// Confirm that a fix for a tidy module will correct all modules in the
10011053// workspace.
10021054func 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 --
10041070-- a/go.mod --
10051071module a.com
10061072
@@ -1027,8 +1093,7 @@ func main() {
10271093`
10281094 WithOptions (
10291095 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 ) {
10321097 params := & protocol.PublishDiagnosticsParams {}
10331098 env .OpenFile ("b/go.mod" )
10341099 env .Await (
0 commit comments