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

     1  # This test makes sure workspace mode's handling of the module graph
     2  # is compatible with module pruning. The graph we load from either of
     3  # the workspace modules should be the same, even if their graphs
     4  # don't overlap.
     5  #
     6  # This is the module graph in the test:
     7  #
     8  #  example.com/a -> example.com/b v1.0.0 -> example.com/q v1.1.0
     9  #  example.com/p -> example.com/q v1.0.0
    10  #
    11  # If we didn't load the whole graph and didn't load the dependencies of b
    12  # when loading p, we would end up loading q v1.0.0, rather than v1.1.0,
    13  # which is selected by MVS.
    14  
    15  go list -m -f '{{.Version}}' example.com/q
    16  stdout '^v1.1.0$'
    17  
    18  -- go.work --
    19  go 1.18
    20  
    21  use (
    22  	./a
    23  	./p
    24  )
    25  -- a/go.mod --
    26  module example.com/a
    27  
    28  go 1.18
    29  
    30  require example.com/b v1.0.0
    31  
    32  replace example.com/b v1.0.0 => ../b
    33  -- a/foo.go --
    34  package main
    35  
    36  import "example.com/b"
    37  
    38  func main() {
    39  	b.B()
    40  }
    41  -- b/go.mod --
    42  module example.com/b
    43  
    44  go 1.18
    45  
    46  require example.com/q v1.1.0
    47  
    48  replace example.com/q v1.0.0 => ../q1_0_0
    49  replace example.com/q v1.1.0 => ../q1_1_0
    50  -- b/b.go --
    51  package b
    52  
    53  func B() {
    54  }
    55  -- b/b_test.go --
    56  package b
    57  
    58  import "example.com/q"
    59  
    60  func TestB() {
    61  	q.PrintVersion()
    62  }
    63  -- p/go.mod --
    64  module example.com/p
    65  
    66  go 1.18
    67  
    68  require example.com/q v1.0.0
    69  
    70  replace example.com/q v1.0.0 => ../q1_0_0
    71  replace example.com/q v1.1.0 => ../q1_1_0
    72  -- p/main.go --
    73  package main
    74  
    75  import "example.com/q"
    76  
    77  func main() {
    78  	q.PrintVersion()
    79  }
    80  -- q1_0_0/go.mod --
    81  module example.com/q
    82  
    83  go 1.18
    84  -- q1_0_0/q.go --
    85  package q
    86  
    87  import "fmt"
    88  
    89  func PrintVersion() {
    90  	fmt.Println("version 1.0.0")
    91  }
    92  -- q1_1_0/go.mod --
    93  module example.com/q
    94  
    95  go 1.18
    96  -- q1_1_0/q.go --
    97  package q
    98  
    99  import "fmt"
   100  
   101  func PrintVersion() {
   102  	fmt.Println("version 1.1.0")
   103  }
   104  

View as plain text