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

     1  # Regression test for https://golang.org/issue/46078:
     2  # 'go mod tidy' should not panic if the main module initially
     3  # requires an older version of itself.
     4  
     5  # A module may require an older version of itself without error. This is
     6  # inconsistent (the required version is never selected), but we still get
     7  # a reproducible build list.
     8  go list -m all
     9  stdout '^golang.org/issue/46078$'
    10  
    11  # 'go mod tidy' should fix this (and not crash).
    12  go mod tidy
    13  
    14  
    15  # We prune out redundant roots very early on in module loading, and at that
    16  # point the indirect requirement on example.net/x v0.1.0 appears to be
    17  # irrelevant. It should be pruned out; when the import of "example.net/x" is
    18  # later resolved, it should resolve at the latest version (v0.2.0), not the
    19  # version implied by the (former) misleading requirement on the older version of
    20  # the main module.
    21  
    22  cmp go.mod go.mod.tidy
    23  
    24  
    25  -- go.mod --
    26  module golang.org/issue/46078
    27  
    28  go 1.17
    29  
    30  replace (
    31  	example.net/x v0.1.0 => ./x
    32  	example.net/x v0.2.0 => ./x
    33  	golang.org/issue/46078 v0.1.0 => ./old
    34  )
    35  
    36  require golang.org/issue/46078 v0.1.0
    37  -- go.mod.tidy --
    38  module golang.org/issue/46078
    39  
    40  go 1.17
    41  
    42  replace (
    43  	example.net/x v0.1.0 => ./x
    44  	example.net/x v0.2.0 => ./x
    45  	golang.org/issue/46078 v0.1.0 => ./old
    46  )
    47  
    48  require example.net/x v0.2.0
    49  -- issue46078/issue.go --
    50  package issue46078
    51  
    52  import _ "example.net/x"
    53  
    54  -- old/go.mod --
    55  module golang.org/issue/46078
    56  
    57  go 1.17
    58  
    59  require example.net/x v0.1.0
    60  
    61  -- x/go.mod --
    62  module example.net/x
    63  
    64  go 1.17
    65  -- x/x.go --
    66  package x
    67  

View as plain text