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

     1  # This test illustrates the interaction between lazy loading and downgrading in
     2  # 'go get'.
     3  
     4  # The package import graph used in this test looks like:
     5  #
     6  # lazy ---- a
     7  #           |
     8  #           a_test ---- b
     9  #                       b_test ---- c
    10  #
    11  # The module dependency graph initially looks like:
    12  #
    13  # lazy ---- a.1 ---- b.1 ---- c.1
    14  #      \                     /
    15  #        b.3 ---- c.2    b.2
    16  #
    17  # (Note that lazy loading will prune out the dependency from b.1 on c.1.)
    18  
    19  cp go.mod go.mod.orig
    20  go mod tidy
    21  cmp go.mod.orig go.mod
    22  
    23  go list -m all
    24  stdout '^example.com/a v0.1.0 '
    25  stdout '^example.com/b v0.3.0 '
    26  stdout '^example.com/c v0.2.0 '
    27  
    28  # Downgrading c should also downgrade the b that requires it.
    29  
    30  go get example.com/c@v0.1.0
    31  go list -m all
    32  stdout '^example.com/a v0.1.0 '
    33  stdout '^example.com/b v0.2.0 '
    34  stdout '^example.com/c v0.1.0 '
    35  
    36  # Removing c entirely should also remove the a and b that require it.
    37  
    38  go get example.com/c@none
    39  go list -m all
    40  ! stdout '^example.com/a '
    41  ! stdout '^example.com/b '
    42  ! stdout '^example.com/c '
    43  
    44  
    45  # With lazy loading, downgrading c should work the same way, but dependencies
    46  # outside of the deepening scan should not affect the downgrade.
    47  
    48  cp go.mod.orig go.mod
    49  go mod edit -go=1.17
    50  
    51  go list -m all
    52  stdout '^example.com/a v0.1.0 '
    53  stdout '^example.com/b v0.3.0 '
    54  stdout '^example.com/c v0.2.0 '
    55  
    56  go get example.com/c@v0.1.0
    57  go list -m all
    58  stdout '^example.com/a v0.1.0 '
    59  stdout '^example.com/b v0.2.0 '
    60  stdout '^example.com/c v0.1.0 '
    61  
    62  # At this point, b.2 is still an explicit root, so its dependency on c
    63  # is still tracked, and it will still be downgraded away if we remove c.
    64  # ('go get' never makes a root into a non-root. Only 'go mod tidy' does that.)
    65  
    66  go get example.com/c@none
    67  go list -m all
    68  ! stdout '^example.com/a '
    69  ! stdout '^example.com/b '
    70  ! stdout '^example.com/c '
    71  
    72  
    73  # This time, we drop the explicit 'b' root by downgrading it to v0.1.0
    74  # (the version required by a.1) and running 'go mod tidy'.
    75  # It is still selected at v0.1.0 (as a dependency of a),
    76  # but its dependency on c is now pruned from the module graph, so it doesn't
    77  # result in any downgrades to b or a if we run 'go get c@none'.
    78  
    79  cp go.mod.orig go.mod
    80  go mod edit -go=1.17
    81  
    82  go list -m all
    83  stdout '^example.com/a v0.1.0 '
    84  stdout '^example.com/b v0.3.0 '
    85  stdout '^example.com/c v0.2.0 '
    86  
    87  go get example.com/c@v0.1.0 example.com/b@v0.1.0
    88  go list -m all
    89  stdout '^example.com/a v0.1.0 '
    90  stdout '^example.com/b v0.1.0 '
    91  stdout '^example.com/c v0.1.0 '
    92  
    93  go mod tidy
    94  go list -m all
    95  stdout '^example.com/a v0.1.0 '
    96  stdout '^example.com/b v0.1.0 '
    97  ! stdout '^example.com/c '
    98  
    99  go get example.com/c@none
   100  go list -m all
   101  stdout '^example.com/a v0.1.0'
   102  stdout '^example.com/b v0.1.0'
   103  ! stdout '^example.com/c '
   104  
   105  
   106  -- go.mod --
   107  module example.com/lazy
   108  
   109  go 1.15
   110  
   111  require (
   112  	example.com/a v0.1.0
   113  	example.com/b v0.3.0 // indirect
   114  )
   115  
   116  replace (
   117  	example.com/a v0.1.0 => ./a
   118  	example.com/b v0.1.0 => ./b1
   119  	example.com/b v0.2.0 => ./b2
   120  	example.com/b v0.3.0 => ./b3
   121  	example.com/c v0.1.0 => ./c
   122  	example.com/c v0.2.0 => ./c
   123  )
   124  -- lazy.go --
   125  package lazy
   126  
   127  import _ "example.com/a"
   128  
   129  -- a/go.mod --
   130  module example.com/a
   131  
   132  go 1.17
   133  
   134  require example.com/b v0.1.0
   135  -- a/a.go --
   136  package a
   137  -- a/a_test.go --
   138  package a_test
   139  
   140  import _ "example.com/b"
   141  
   142  -- b1/go.mod --
   143  module example.com/b
   144  
   145  go 1.17
   146  
   147  require example.com/c v0.1.0
   148  -- b1/b.go --
   149  package b
   150  -- b1/b_test.go --
   151  package b_test
   152  import _ "example.com/c"
   153  
   154  -- b2/go.mod --
   155  module example.com/b
   156  
   157  go 1.17
   158  
   159  require example.com/c v0.1.0
   160  -- b2/b.go --
   161  package b
   162  -- b2/b_test.go --
   163  package b_test
   164  import _ "example.com/c"
   165  
   166  -- b3/go.mod --
   167  module example.com/b
   168  
   169  go 1.17
   170  
   171  require example.com/c v0.2.0
   172  -- b3/b.go --
   173  package b
   174  -- b3/b_test.go --
   175  package b_test
   176  import _ "example.com/c"
   177  
   178  -- c/go.mod --
   179  module example.com/c
   180  
   181  go 1.17
   182  -- c/c.go --
   183  package c
   184  

View as plain text