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

     1  # This test illustrates a case where downgrading one module may upgrade another.
     2  # Compare to the downcross1 test case in cmd/go/internal/mvs/mvs_test.go.
     3  
     4  # The package import graph used in this test looks like:
     5  #
     6  # a ---- b
     7  #   \     \
     8  #    \     \
     9  #     ----- c ---- d
    10  #
    11  # The module dependency graph originally looks like:
    12  #
    13  # a ---- b.2
    14  #   \      \
    15  #    \      \
    16  #     ----- c.1 ---- d.2
    17  #
    18  # b.1 ---- c.2
    19  #
    20  # If we downgrade module d to version 1, we must downgrade b as well.
    21  # If that downgrade selects b version 1, we will upgrade module c to version 2.
    22  
    23  cp go.mod go.mod.orig
    24  go mod tidy
    25  cmp go.mod.orig go.mod
    26  
    27  # Downgrading d to version 1 downgrades b, which upgrades c.
    28  go get example.com/d@v0.1.0
    29  go list -m all
    30  stdout '^example.com/b v0.1.0 '
    31  stdout '^example.com/c v0.2.0 '
    32  stdout '^example.com/d v0.1.0 '
    33  cmp go.mod go.mod.down1
    34  
    35  # Restoring c to version 1 upgrades d to meet c's requirements.
    36  go get example.com/c@v0.1.0
    37  go list -m all
    38  ! stdout '^example.com/b '
    39  stdout '^example.com/c v0.1.0 '
    40  stdout '^example.com/d v0.2.0 '
    41  cmp go.mod go.mod.down2
    42  
    43  # If a user explicitly requests the incompatible versions together,
    44  # 'go get' should explain why they are not compatible.
    45  ! go get example.com/c@v0.1.0 example.com/d@v0.1.0
    46  stderr '^go: example\.com/c@v0\.1\.0 requires example\.com/d@v0\.2\.0, not example\.com/d@v0\.1\.0'
    47  
    48  -- go.mod --
    49  module example.com/a
    50  
    51  go 1.15
    52  
    53  require (
    54  	example.com/b v0.2.0
    55  	example.com/c v0.1.0
    56  )
    57  
    58  replace (
    59  	example.com/b v0.1.0 => ./b1
    60  	example.com/b v0.2.0 => ./b2
    61  	example.com/c v0.1.0 => ./c1
    62  	example.com/c v0.2.0 => ./c2
    63  	example.com/d v0.1.0 => ./d
    64  	example.com/d v0.2.0 => ./d
    65  )
    66  -- go.mod.down1 --
    67  module example.com/a
    68  
    69  go 1.15
    70  
    71  require (
    72  	example.com/b v0.1.0
    73  	example.com/c v0.2.0
    74  	example.com/d v0.1.0 // indirect
    75  )
    76  
    77  replace (
    78  	example.com/b v0.1.0 => ./b1
    79  	example.com/b v0.2.0 => ./b2
    80  	example.com/c v0.1.0 => ./c1
    81  	example.com/c v0.2.0 => ./c2
    82  	example.com/d v0.1.0 => ./d
    83  	example.com/d v0.2.0 => ./d
    84  )
    85  -- go.mod.down2 --
    86  module example.com/a
    87  
    88  go 1.15
    89  
    90  require example.com/c v0.1.0
    91  
    92  replace (
    93  	example.com/b v0.1.0 => ./b1
    94  	example.com/b v0.2.0 => ./b2
    95  	example.com/c v0.1.0 => ./c1
    96  	example.com/c v0.2.0 => ./c2
    97  	example.com/d v0.1.0 => ./d
    98  	example.com/d v0.2.0 => ./d
    99  )
   100  -- a.go --
   101  package a
   102  
   103  import (
   104  	_ "example.com/b"
   105  	_ "example.com/c"
   106  )
   107  
   108  -- b1/go.mod --
   109  module example.com/b
   110  
   111  go 1.15
   112  
   113  require example.com/c v0.2.0
   114  -- b1/b.go --
   115  package b
   116  
   117  import _ "example.com/c"
   118  
   119  -- b2/go.mod --
   120  module example.com/b
   121  
   122  go 1.15
   123  
   124  require example.com/c v0.1.0
   125  -- b2/b.go --
   126  package b
   127  
   128  import _ "example.com/c"
   129  
   130  -- c1/go.mod --
   131  module example.com/c
   132  
   133  go 1.15
   134  
   135  require example.com/d v0.2.0
   136  -- c1/c.go --
   137  package c
   138  
   139  -- c2/go.mod --
   140  module example.com/c
   141  
   142  go 1.15
   143  -- c2/c.go --
   144  package c
   145  
   146  -- d/go.mod --
   147  module example.com/d
   148  
   149  go 1.15
   150  

View as plain text