Black Lives Matter. Support the Equal Justice Initiative.

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

Documentation: cmd/go/testdata/script

     1  # https://golang.org/issue/45094: 'go mod tidy' now accepts a '-go' flag
     2  # to change the language version in use.
     3  #
     4  # The package import graph used in this test looks like:
     5  #
     6  # m --- a --- b
     7  #             |
     8  #             b_test --- c
     9  #                        |
    10  #                        c_test --- d
    11  #
    12  # The module diagram looks like:
    13  #
    14  # m --- a --- b
    15  # |
    16  # + --- c
    17  # |
    18  # + --- d
    19  #
    20  # Module b omits its dependency on c, and module c omits its dependency on d.
    21  #
    22  # In go 1.15, the tidy main module must require a (because it is direct),
    23  # c (because it is a missing test dependency of an imported package),
    24  # and d (because it is a missing transitive test dependency).
    25  #
    26  # In go 1.16, the tidy main module can omit d because it is no longer
    27  # included in "all".
    28  #
    29  # In go 1.17, the main module must explicitly require b
    30  # (because it is transitively imported by the main module).
    31  
    32  
    33  cp go.mod go.mod.orig
    34  
    35  
    36  # An invalid argument should be rejected.
    37  
    38  ! go mod tidy -go=bananas
    39  stderr '^invalid value "bananas" for flag -go: expecting a Go version like "'$goversion'"$'
    40  cmp go.mod go.mod.orig
    41  
    42  ! go mod tidy -go=0.9
    43  stderr '^invalid value "0.9" for flag -go: expecting a Go version like "'$goversion'"$'
    44  
    45  ! go mod tidy -go=2000.0
    46  stderr '^invalid value "2000.0" for flag -go: maximum supported Go version is '$goversion'$'
    47  
    48  
    49  # Supported versions should change the go.mod file to be tidy according to the
    50  # indicated version.
    51  
    52  go mod tidy -go=1.15
    53  cmp go.mod go.mod.115
    54  
    55  go mod tidy
    56  cmp go.mod go.mod.115
    57  
    58  
    59  go mod tidy -go=1.16
    60  cmp go.mod go.mod.116
    61  
    62  go mod tidy
    63  cmp go.mod go.mod.116
    64  
    65  
    66  go mod tidy -go=1.17
    67  cmp go.mod go.mod.117
    68  
    69  go mod tidy
    70  cmp go.mod go.mod.117
    71  
    72  
    73  # If we downgrade back to 1.15, we should re-resolve d to v0.2.0 instead
    74  # of the original v0.1.0 (because the original requirement is lost).
    75  
    76  go mod tidy -go=1.15
    77  cmp go.mod go.mod.115-2
    78  
    79  
    80  # -go= (with an empty argument) maintains the existing version or adds the
    81  #  default version (just like omitting the flag).
    82  
    83  go mod tidy -go=''
    84  cmp go.mod go.mod.115-2
    85  
    86  cp go.mod.orig go.mod
    87  go mod tidy -go=''
    88  cmpenv go.mod go.mod.latest
    89  
    90  
    91  
    92  -- go.mod --
    93  module example.com/m
    94  
    95  require example.net/a v0.1.0
    96  
    97  require (
    98  	example.net/c v0.1.0 // indirect
    99  	example.net/d v0.1.0 // indirect
   100  )
   101  
   102  replace (
   103  	example.net/a v0.1.0 => ./a
   104  	example.net/a v0.2.0 => ./a
   105  	example.net/b v0.1.0 => ./b
   106  	example.net/b v0.2.0 => ./b
   107  	example.net/c v0.1.0 => ./c
   108  	example.net/c v0.2.0 => ./c
   109  	example.net/d v0.1.0 => ./d
   110  	example.net/d v0.2.0 => ./d
   111  )
   112  -- m.go --
   113  package m
   114  
   115  import _ "example.net/a"
   116  
   117  -- go.mod.115 --
   118  module example.com/m
   119  
   120  go 1.15
   121  
   122  require example.net/a v0.1.0
   123  
   124  require (
   125  	example.net/c v0.1.0 // indirect
   126  	example.net/d v0.1.0 // indirect
   127  )
   128  
   129  replace (
   130  	example.net/a v0.1.0 => ./a
   131  	example.net/a v0.2.0 => ./a
   132  	example.net/b v0.1.0 => ./b
   133  	example.net/b v0.2.0 => ./b
   134  	example.net/c v0.1.0 => ./c
   135  	example.net/c v0.2.0 => ./c
   136  	example.net/d v0.1.0 => ./d
   137  	example.net/d v0.2.0 => ./d
   138  )
   139  -- go.mod.115-2 --
   140  module example.com/m
   141  
   142  go 1.15
   143  
   144  require example.net/a v0.1.0
   145  
   146  require (
   147  	example.net/c v0.1.0 // indirect
   148  	example.net/d v0.2.0 // indirect
   149  )
   150  
   151  replace (
   152  	example.net/a v0.1.0 => ./a
   153  	example.net/a v0.2.0 => ./a
   154  	example.net/b v0.1.0 => ./b
   155  	example.net/b v0.2.0 => ./b
   156  	example.net/c v0.1.0 => ./c
   157  	example.net/c v0.2.0 => ./c
   158  	example.net/d v0.1.0 => ./d
   159  	example.net/d v0.2.0 => ./d
   160  )
   161  -- go.mod.116 --
   162  module example.com/m
   163  
   164  go 1.16
   165  
   166  require example.net/a v0.1.0
   167  
   168  require example.net/c v0.1.0 // indirect
   169  
   170  replace (
   171  	example.net/a v0.1.0 => ./a
   172  	example.net/a v0.2.0 => ./a
   173  	example.net/b v0.1.0 => ./b
   174  	example.net/b v0.2.0 => ./b
   175  	example.net/c v0.1.0 => ./c
   176  	example.net/c v0.2.0 => ./c
   177  	example.net/d v0.1.0 => ./d
   178  	example.net/d v0.2.0 => ./d
   179  )
   180  -- go.mod.117 --
   181  module example.com/m
   182  
   183  go 1.17
   184  
   185  require example.net/a v0.1.0
   186  
   187  require (
   188  	example.net/b v0.1.0 // indirect
   189  	example.net/c v0.1.0 // indirect
   190  )
   191  
   192  replace (
   193  	example.net/a v0.1.0 => ./a
   194  	example.net/a v0.2.0 => ./a
   195  	example.net/b v0.1.0 => ./b
   196  	example.net/b v0.2.0 => ./b
   197  	example.net/c v0.1.0 => ./c
   198  	example.net/c v0.2.0 => ./c
   199  	example.net/d v0.1.0 => ./d
   200  	example.net/d v0.2.0 => ./d
   201  )
   202  -- go.mod.latest --
   203  module example.com/m
   204  
   205  go $goversion
   206  
   207  require example.net/a v0.1.0
   208  
   209  require (
   210  	example.net/b v0.1.0 // indirect
   211  	example.net/c v0.1.0 // indirect
   212  )
   213  
   214  replace (
   215  	example.net/a v0.1.0 => ./a
   216  	example.net/a v0.2.0 => ./a
   217  	example.net/b v0.1.0 => ./b
   218  	example.net/b v0.2.0 => ./b
   219  	example.net/c v0.1.0 => ./c
   220  	example.net/c v0.2.0 => ./c
   221  	example.net/d v0.1.0 => ./d
   222  	example.net/d v0.2.0 => ./d
   223  )
   224  -- a/go.mod --
   225  module example.net/a
   226  
   227  go 1.15
   228  
   229  require example.net/b v0.1.0
   230  -- a/a.go --
   231  package a
   232  
   233  import _ "example.net/b"
   234  
   235  -- b/go.mod --
   236  module example.net/b
   237  
   238  go 1.15
   239  -- b/b.go --
   240  package b
   241  -- b/b_test.go --
   242  package b_test
   243  
   244  import _ "example.net/c"
   245  
   246  -- c/go.mod --
   247  module example.net/c
   248  
   249  go 1.15
   250  -- c/c.go --
   251  package c
   252  -- c/c_test.go --
   253  package c_test
   254  
   255  import _ "example.net/d"
   256  
   257  -- d/go.mod --
   258  module example.net/d
   259  
   260  go 1.15
   261  -- d/d.go --
   262  package d
   263  

View as plain text