Text file src/cmd/go/testdata/script/mod_get_workspace_incomplete.txt

     1  # Enter the first set of test cases. In this test case, package
     2  # example.com/m has an import of example.com/n, which is also
     3  # in the workspace, but is not required by example.com/m, and does not exist
     4  # upstream. It also has an import of rsc.io/quote, which
     5  # is also not required by example.com/m but does exist upstream. get should resolve
     6  # rsc.io/quote and not try to resolve example.com/n.
     7  cd m
     8  cp go.mod go.mod.orig
     9  
    10  # Test go get with an incomplete module using a local query.
    11  cp go.mod.orig go.mod
    12  go get
    13  cmp go.mod go.mod.want
    14  cmp go.sum go.sum.want
    15  
    16  # Test go get with an incomplete module using a wildcard query.
    17  cp go.mod.orig go.mod
    18  rm go.sum
    19  go get ./...
    20  cmp go.mod go.mod.want
    21  cmp go.sum go.sum.want
    22  
    23  # Test go get with an incomplete module using a "work" query.
    24  cp go.mod.orig go.mod
    25  rm go.sum
    26  go get work
    27  cmp go.mod go.mod.want
    28  cmp go.sum go.sum.want
    29  
    30  # Test go get with an incomplete module using a path query that can be resolved.
    31  cp go.mod.orig go.mod
    32  rm go.sum
    33  go get rsc.io/quote
    34  cmp go.mod go.mod.want.path_query # query wasn't resolved through import, so don't know if it's direct
    35  cmp go.sum go.sum.want
    36  
    37  # Test go get with a path query that is to a workspace module but that can't be resolved.
    38  # Normally, when we encounter an unresolved import of a workspace module, it's
    39  # ignored, but a path query of the module was asked for explicitly and isn't ignored.
    40  cp go.mod.orig go.mod
    41  rm go.sum
    42  ! go get example.com/n
    43  # The following error is returned because module example.com does exist in the proxy we use
    44  # to run these tests, and because its is a prefix of example.com/n, it is a candidate to
    45  # satisfy the import.
    46  stderr 'module example.com@upgrade found \(v1\.0\.0\), but does not contain package example.com/n'
    47  
    48  # Test go get with an incomplete module using an "all" query.
    49  cp go.mod.orig go.mod
    50  rm go.sum
    51  go get all
    52  cmp go.mod go.mod.want.all # all loads a different graph so the requirements get bumped up
    53  cmp go.sum go.sum.want.all
    54  
    55  # Test go get with an incomplete module using a tool query
    56  # The hastool directory has its own go.work file than includes example.com/n and hastool.
    57  cd ../hastool
    58  go get tool
    59  cmp go.mod go.mod.want
    60  
    61  # Test that missing imports from loading the workspace are reported.
    62  # In this example, there is a workspace with the
    63  # example.com/missingworkspaceimport and example.com/withmissing modules.
    64  # missingworkspaceimport imports withmissing, and withmissing in turn
    65  # imports rsc.io/quote, but doesn't have a requirement on it.
    66  # The get operation won't resolve rsc.io/quote because it doesn't
    67  # appear in the missingworkspaceimport's module graph, and the
    68  # workspace will fail to load in checkPackageProblems because of the missing import.
    69  cd ../missingworkspaceimport
    70  ! go get ./...
    71  stderr 'cannot find module providing package rsc.io/quote'
    72  
    73  # Test that missing imports are not reported if they're not in the package
    74  # graph. This test case is the same as the above except that there's no
    75  # import from the missingworkspaceimport package to the one that
    76  # imports the unresolved rsc.io/quote dependency. The example.com/missingworkspaceimport
    77  # package imports example.com/withmissing/other so it still depends on the example.com/missing
    78  # module, but not on the withmissing package itself. The example.com/withmissing
    79  # module still has an import on the rsc.io/quote package, but the package
    80  # with the import doesn't appear in the loaded package graph.
    81  cd ../missingworkspaceimport_disconnected
    82  go get ./...
    83  
    84  # Test that deprecations are reported using the workspace.
    85  # First, the control case: without the workspace, the deprecated module
    86  # is an indirect dependency of example.com/withdeprecation/indirect,
    87  # so we shouldn't get a deprecation warning.
    88  cd ../withdeprecation/indirect
    89  cp go.mod go.mod.orig
    90  env GOWORK=off
    91  go get ./...
    92  ! stderr 'is deprecated'
    93  cmp go.mod go.mod.want
    94  # Now, in the workspace, we should get a deprecation warning, because
    95  # the deprecated module is a direct dependency of example.com/withdeprecation/direct, which
    96  # is a workspace module.
    97  cp go.mod.orig go.mod
    98  env GOWORK=
    99  go get ./...
   100  stderr 'go: module example.com/deprecated/b is deprecated: in example.com/deprecated/b@v1.9.0'
   101  cmp go.mod go.mod.want
   102  
   103  # Test that retractions are reported using the workspace.
   104  # First, the control case. Even though a workspace module depends on
   105  # a retracted version, because we didn't ask for it on the command line,
   106  # we didn't resolve that retracted module to satisfy an import,
   107  # or need it to build a requested package, we don't produce the warning.
   108  cd ../../withretraction/doesnotrequireretracted
   109  cp go.mod go.mod.orig
   110  go get rsc.io/quote
   111  ! stderr 'retracted'
   112  # If we do request a non-retracted version of the module but the workspace
   113  # is off, we also won't see the retraction warning because the retracted
   114  # module isn't selected in the graph.
   115  cp go.mod.orig go.mod
   116  env GOWORK=off
   117  go get example.com/retract@v1.0.0-good
   118  ! stderr 'retracted'
   119  # Now, with the workspace on, because example.com/retract@v1.0.0-unused
   120  # is a higher version, it will be selected and the retraction will
   121  # be reported.
   122  cp go.mod.orig go.mod
   123  env GOWORK=
   124  go get example.com/retract@v1.0.0-good
   125  stderr 'retracted'
   126  # Finally, with the workspace on, if the other workspace depends on
   127  # example.com/retract@v1.0.0-bad rather than 'v1.0.0-unused', because
   128  # 'v1.0.0-bad' is considered a lower version than 'v1.0.0-good', 'v1.0.0-good'
   129  # will be selected and the deprecation will not be reported.
   130  cp go.mod.orig go.mod
   131  cd ../requiresretracted
   132  go get example.com/retract@v1.0.0-bad # set the verison to 'v1.0.0-bad'
   133  stderr 'retracted'
   134  cd ../doesnotrequireretracted
   135  go get example.com/retract@v1.0.0-good
   136  ! stderr 'retracted'
   137  
   138  -- go.work --
   139  go 1.25
   140  
   141  use (
   142  	m
   143  	n
   144  )
   145  -- q/go.mod --
   146  module example.com/q
   147  
   148  go 1.25
   149  -- q/q.go --
   150  package q
   151  
   152  import "rsc.io/quote"
   153  
   154  func Q() {
   155  	quote.Hello()
   156  }
   157  -- m/go.mod --
   158  module example.com/m
   159  
   160  go 1.25
   161  -- m/go.mod.want --
   162  module example.com/m
   163  
   164  go 1.25
   165  
   166  require rsc.io/quote v1.5.2
   167  
   168  require (
   169  	golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c // indirect
   170  	rsc.io/sampler v1.3.0 // indirect
   171  )
   172  -- m/go.mod.want.path_query --
   173  module example.com/m
   174  
   175  go 1.25
   176  
   177  require (
   178  	golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c // indirect
   179  	rsc.io/quote v1.5.2 // indirect
   180  	rsc.io/sampler v1.3.0 // indirect
   181  )
   182  -- m/go.sum.want --
   183  golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c h1:pvCbr/wm8HzDD3fVywevekufpn6tCGPY3spdHeZJEsw=
   184  golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
   185  rsc.io/quote v1.5.2 h1:3fEykkD9k7lYzXqCYrwGAf7iNhbk4yCjHmKBN9td4L0=
   186  rsc.io/quote v1.5.2/go.mod h1:LzX7hefJvL54yjefDEDHNONDjII0t9xZLPXsUe+TKr0=
   187  rsc.io/sampler v1.3.0 h1:HLGR/BgEtI3r0uymSP/nl2uPLsUnNJX8toRyhfpBTII=
   188  rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
   189  -- m/go.mod.want.all --
   190  module example.com/m
   191  
   192  go 1.25
   193  
   194  require rsc.io/quote v1.5.2
   195  
   196  require (
   197  	golang.org/x/text v0.3.0 // indirect
   198  	rsc.io/sampler v1.99.99 // indirect
   199  )
   200  -- m/go.sum.want.all --
   201  golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
   202  golang.org/x/text v0.3.0 h1:ivTorhoiROmZ1mcs15mO2czVF0uy0tnezXpBVNzgrmA=
   203  golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
   204  rsc.io/quote v1.5.2 h1:3fEykkD9k7lYzXqCYrwGAf7iNhbk4yCjHmKBN9td4L0=
   205  rsc.io/quote v1.5.2/go.mod h1:LzX7hefJvL54yjefDEDHNONDjII0t9xZLPXsUe+TKr0=
   206  rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
   207  rsc.io/sampler v1.99.99 h1:iMG9lbEG/8MdeR4lgL+Q8IcwbLNw7ijW7fTiK8Miqts=
   208  rsc.io/sampler v1.99.99/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
   209  -- m/m.go --
   210  package m
   211  
   212  import (
   213  	"example.com/n"
   214  	"rsc.io/quote"
   215  )
   216  
   217  func M() {
   218  	n.Hello()
   219  	quote.Hello()
   220  }
   221  -- n/go.mod --
   222  module example.com/n
   223  
   224  go 1.25
   225  -- n/n.go --
   226  package n
   227  
   228  func Hello() {
   229  }
   230  -- hastool/go.work --
   231  go 1.25
   232  
   233  use (
   234  	.
   235  	../n
   236  )
   237  -- hastool/go.mod --
   238  module example.com/hastool
   239  
   240  go 1.25
   241  
   242  tool rsc.io/fortune
   243  -- hastool/go.mod.want --
   244  module example.com/hastool
   245  
   246  go 1.25
   247  
   248  tool rsc.io/fortune
   249  
   250  require (
   251  	golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c // indirect
   252  	rsc.io/fortune v1.0.0 // indirect
   253  	rsc.io/quote v1.5.2 // indirect
   254  	rsc.io/sampler v1.3.0 // indirect
   255  )
   256  -- hastool/p.go --
   257  package hastool
   258  
   259  import "example.com/n"
   260  
   261  func T() {
   262  	n.Hello()
   263  }
   264  -- missingworkspaceimport/go.work --
   265  go 1.25
   266  
   267  use (
   268  	.
   269  	withmissing
   270  )
   271  -- missingworkspaceimport/go.mod --
   272  module example.com/missingworkspaceimport
   273  
   274  go 1.25
   275  -- missingworkspaceimport/m.go --
   276  package m
   277  
   278  import _ "example.com/withmissing"
   279  -- missingworkspaceimport/withmissing/go.mod --
   280  module example.com/withmissing
   281  
   282  go 1.25
   283  -- missingworkspaceimport/withmissing/w.go --
   284  package w
   285  
   286  import _ "rsc.io/quote"
   287  -- missingworkspaceimport_disconnected/go.work --
   288  go 1.25
   289  
   290  use (
   291  	.
   292  	withmissing
   293  )
   294  -- missingworkspaceimport_disconnected/go.mod --
   295  module example.com/missingworkspaceimport
   296  
   297  go 1.25
   298  -- missingworkspaceimport_disconnected/m.go --
   299  package m
   300  
   301  import _ "example.com/withmissing/other"
   302  -- missingworkspaceimport_disconnected/withmissing/go.mod --
   303  module example.com/withmissing
   304  
   305  go 1.25
   306  -- missingworkspaceimport_disconnected/withmissing/w.go --
   307  package w
   308  
   309  import _ "rsc.io/quote"
   310  -- missingworkspaceimport_disconnected/withmissing/other/other.go --
   311  package other
   312  -- withdeprecation/go.work --
   313  go 1.25
   314  
   315  use (
   316  	indirect
   317  	direct
   318  )
   319  
   320  replace example.com/requiresdeprecatednotworkspace => ./requiresdeprecatednotworkspace
   321  -- withdeprecation/indirect/go.mod --
   322  module example.com/withdeprecation/indirect
   323  
   324  go 1.25
   325  
   326  replace example.com/requiresdeprecatednotworkspace => ../requiresdeprecatednotworkspace
   327  -- withdeprecation/indirect/go.mod.want --
   328  module example.com/withdeprecation/indirect
   329  
   330  go 1.25
   331  
   332  replace example.com/requiresdeprecatednotworkspace => ../requiresdeprecatednotworkspace
   333  
   334  require example.com/requiresdeprecatednotworkspace v0.0.0-00010101000000-000000000000
   335  
   336  require example.com/deprecated/b v1.9.0 // indirect
   337  -- withdeprecation/indirect/go.mod.want.direct --
   338  module example.com/withdeprecation/indirect
   339  
   340  go 1.25
   341  
   342  replace example.com/requiresdeprecatednotworkspace => ../requiresdeprecatednotworkspace
   343  
   344  require example.com/requiresdeprecatednotworkspace v0.0.0-00010101000000-000000000000
   345  
   346  require example.com/deprecated/b v1.9.0
   347  -- withdeprecation/indirect/a.go --
   348  package indirect
   349  
   350  import "example.com/requiresdeprecatednotworkspace"
   351  -- withdeprecation/direct/go.mod --
   352  module example.com/withdeprecation/direct
   353  
   354  go 1.25
   355  
   356  require "example.com/deprecated/b" v1.9.0
   357  -- withdeprecation/direct/import.go --
   358  package direct
   359  
   360  import "example.com/deprecated/b"
   361  -- withdeprecation/requiresdeprecatednotworkspace/go.mod --
   362  module example.com/requiresdeprecatednotworkspace
   363  
   364  go 1.25
   365  -- withdeprecation/requiresdeprecatednotworkspace/a.go --
   366  package a
   367  
   368  import "example.com/deprecated/b"
   369  -- withretraction/go.work --
   370  go 1.25
   371  
   372  use (
   373  	doesnotrequireretracted
   374  	requiresretracted
   375  )
   376  -- withretraction/doesnotrequireretracted/go.mod --
   377  module example.com/withretraction/doesnotrequireretracted
   378  
   379  go 1.25
   380  -- withretraction/requiresretracted/go.mod --
   381  module example.com/withretraction/requiresretracted
   382  
   383  go 1.25
   384  
   385  require example.com/retract v1.0.0-unused
   386  

View as plain text