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

     1  # Regression test for https://go.dev/issue/56494:
     2  # 'go get' in module mode was failing to prune out dependencies
     3  # through modules whose versions are too low to be selected.
     4  
     5  # Initially, modules "a", "b", and "c" are unrelated.
     6  #
     7  # The package import graph at v1 of everything looks like:
     8  #
     9  # m --- a
    10  # |
    11  # + --- b
    12  # |
    13  # + --- c
    14  #
    15  # At v2, package "a" adds imports of "b" and "c"
    16  # (and a requirement on "c" v2):
    17  #
    18  # a --- b
    19  # |
    20  # + --- c
    21  #
    22  # And "b" adds an import of "a/sub" (in module "a"):
    23  #
    24  # b --- a/sub
    25  #
    26  # At v3, "a" no longer imports (nor requires) "c":
    27  #
    28  # a --- b
    29  
    30  # So upgrading to a3 adds a dependency on b2,
    31  # b2 adds a dependency on a2 (for "a/sub"),
    32  # and a2 (but not a3) would add a dependency on c2.
    33  # Since a2 is lower than a3 it cannot possibly be selected when
    34  # upgrading to a3: normally a2 is pruned out of a3's module graph,
    35  # so 'go get' should prune it out too, and c should remain at c1
    36  # without error.
    37  
    38  go get a@v0.3.0
    39  
    40  go list -m c
    41  stdout '^c v0.1.0 '
    42  
    43  -- go.mod --
    44  module m
    45  
    46  go 1.19
    47  
    48  require (
    49  	a v0.1.0
    50  	b v0.1.0
    51  	c v0.1.0
    52  )
    53  
    54  replace (
    55  	a v0.1.0 => ./a1
    56  	a v0.2.0 => ./a2
    57  	a v0.3.0 => ./a3
    58  	b v0.1.0 => ./b1
    59  	b v0.2.0 => ./b2
    60  	c v0.1.0 => ./c1
    61  	c v0.2.0 => ./c2
    62  )
    63  -- m.go --
    64  package m
    65  
    66  import (
    67  	_ "a"
    68  	_ "b"
    69  	_ "c"
    70  )
    71  -- a1/go.mod --
    72  module a
    73  
    74  go 1.19
    75  -- a1/a.go --
    76  package a
    77  -- a2/go.mod --
    78  module a
    79  
    80  go 1.19
    81  
    82  require (
    83  	b v0.1.0
    84  	c v0.2.0
    85  )
    86  -- a2/a.go --
    87  package a
    88  
    89  import (
    90  	_ "b"
    91  	_ "c"
    92  )
    93  -- a2/sub/sub.go --
    94  package sub
    95  -- a3/go.mod --
    96  module a
    97  
    98  go 1.19
    99  
   100  require b v0.2.0
   101  -- a3/a.go --
   102  package a
   103  
   104  import _ "b"
   105  -- a3/sub/sub.go --
   106  package sub
   107  -- b1/go.mod --
   108  module b
   109  
   110  go 1.19
   111  -- b1/b.go --
   112  package b
   113  -- b2/go.mod --
   114  module b
   115  
   116  go 1.19
   117  
   118  require a v0.2.0
   119  -- b2/b.go --
   120  package b
   121  
   122  import "a/sub"
   123  -- c1/go.mod --
   124  module c
   125  
   126  go 1.19
   127  -- c1/c.go --
   128  package c
   129  -- c2/go.mod --
   130  module c
   131  
   132  go 1.19
   133  -- c2/c.go --
   134  package c
   135  

View as plain text