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

     1  # This test illustrates a case where an upgrade–downgrade–upgrade cycle can
     2  # result in upgrades of otherwise-irrelevant dependencies.
     3  #
     4  # This case has no corresponding test in the mvs package, because it is an
     5  # artifact that results from the composition of *multiple* MVS operations.
     6  
     7  # The initial package import graph used in the test looks like:
     8  #
     9  # m ---- a
    10  # |      |
    11  # +----- b
    12  # |      |
    13  # +----- c
    14  # |
    15  # +----- d
    16  #
    17  # b version 2 adds its own import of package d.
    18  #
    19  # The module dependency graph initially looks like:
    20  #
    21  # m ---- a.1
    22  # |       |
    23  # +----- b.1
    24  # |       |
    25  # +----- c.1
    26  # |
    27  # +----- d.1
    28  #
    29  # b.2 ---- c.2
    30  #  |
    31  #  +------ d.2
    32  #  |
    33  #  +------ e.1
    34  #
    35  # If we upgrade module b to version 2, we will upgrade c and d and add a new
    36  # dependency on e. If b version 2 is disallowed because of any of those
    37  # dependencies, the other dependencies should not be upgraded as a side-effect.
    38  
    39  cp go.mod go.mod.orig
    40  go mod tidy
    41  cmp go.mod go.mod.orig
    42  
    43  go list -m all
    44  stdout '^example.com/a v0.1.0 '
    45  stdout '^example.com/b v0.1.0 '
    46  stdout '^example.com/c v0.1.0 '
    47  stdout '^example.com/d v0.1.0 '
    48  ! stdout '^example.com/e '
    49  
    50  # b is imported by a, so the -u flag would normally upgrade it to v0.2.0.
    51  # However, that would conflict with the explicit c@v0.1.0 constraint,
    52  # so b must remain at v0.1.0.
    53  #
    54  # If we're not careful, we might temporarily add b@v0.2.0 and pull in its
    55  # upgrades of module d and addition of module e, which are not relevant to
    56  # b@v0.1.0 and should not be added to the main module's dependencies.
    57  
    58  go get -u example.com/a@latest example.com/c@v0.1.0
    59  
    60  go list -m all
    61  stdout '^example.com/a v0.1.0 '
    62  stdout '^example.com/b v0.1.0 '
    63  stdout '^example.com/c v0.1.0 '
    64  stdout '^example.com/d v0.1.0 '
    65  ! stdout '^example.com/e '
    66  
    67  -- go.mod --
    68  module example.com/m
    69  
    70  go 1.16
    71  
    72  require (
    73  	example.com/a v0.1.0
    74  	example.com/b v0.1.0
    75  	example.com/c v0.1.0
    76  	example.com/d v0.1.0
    77  )
    78  
    79  replace (
    80  	example.com/a v0.1.0 => ./a1
    81  	example.com/b v0.1.0 => ./b1
    82  	example.com/b v0.2.0 => ./b2
    83  	example.com/c v0.1.0 => ./c
    84  	example.com/c v0.2.0 => ./c
    85  	example.com/d v0.1.0 => ./d
    86  	example.com/d v0.2.0 => ./d
    87  	example.com/e v0.1.0 => ./e
    88  )
    89  -- m.go --
    90  package m
    91  
    92  import (
    93  	_ "example.com/a"
    94  	_ "example.com/b"
    95  	_ "example.com/c"
    96  	_ "example.com/d"
    97  )
    98  
    99  -- a1/go.mod --
   100  module example.com/a
   101  
   102  go 1.16
   103  
   104  require example.com/b v0.1.0
   105  -- a1/a.go --
   106  package a
   107  
   108  import _ "example.com/b"
   109  
   110  -- b1/go.mod --
   111  module example.com/b
   112  
   113  go 1.16
   114  
   115  require example.com/c v0.1.0
   116  -- b1/b.go --
   117  package b
   118  
   119  import _ "example.com/c"
   120  
   121  -- b2/go.mod --
   122  module example.com/b
   123  
   124  go 1.16
   125  
   126  require (
   127  	example.com/c v0.2.0
   128  	example.com/d v0.2.0
   129  	example.com/e v0.1.0
   130  )
   131  -- b2/b.go --
   132  package b
   133  
   134  import (
   135  	"example.com/c"
   136  	"example.com/d"
   137  	"example.com/e"
   138  )
   139  
   140  -- c/go.mod --
   141  module example.com/c
   142  
   143  go 1.16
   144  -- c/c.go --
   145  package c
   146  
   147  -- d/go.mod --
   148  module example.com/d
   149  
   150  go 1.16
   151  -- d/d.go --
   152  package d
   153  
   154  -- e/go.mod --
   155  module example.com/e
   156  
   157  go 1.16
   158  -- e/e.go --
   159  package e
   160  

View as plain text