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

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

View as plain text