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

     1  # https://golang.org/issue/46141: 'go mod tidy' for a Go 1.17 module should by
     2  # default preserve enough checksums for the module to be used by Go 1.16.
     3  #
     4  # We don't have a copy of Go 1.16 handy, but we can simulate it by editing the
     5  # 'go' version in the go.mod file to 1.16, without actually updating the
     6  # requirements to match.
     7  
     8  [short] skip
     9  
    10  env MODFMT='{{with .Module}}{{.Path}} {{.Version}}{{end}}'
    11  
    12  
    13  # This module has the same module dependency graph in Go 1.16 as in Go 1.17,
    14  # but in 1.16 requires (checksums for) additional (irrelevant) go.mod files.
    15  #
    16  # The module graph under both versions looks like:
    17  #
    18  # m ---- example.com/version v1.1.0
    19  # |
    20  # + ---- example.net/lazy v0.1.0 ---- example.com/version v1.0.1
    21  #
    22  # Go 1.17 avoids loading the go.mod file for example.com/version v1.0.1
    23  # (because it is lower than the version explicitly required by m,
    24  # and the module that requires it — m — specifies 'go 1.17').
    25  #
    26  # That go.mod file happens not to affect the final 1.16 module graph anyway,
    27  # so the pruned graph is equivalent to the unpruned one.
    28  
    29  cp go.mod go.mod.orig
    30  go mod tidy
    31  cmp go.mod go.mod.orig
    32  
    33  go list -m all
    34  cmp stdout m_all.txt
    35  
    36  go mod edit -go=1.16
    37  go list -m all
    38  cmp stdout m_all.txt
    39  
    40  
    41  # If we explicitly drop compatibility with 1.16, we retain fewer checksums,
    42  # which gives a cleaner go.sum file but causes 1.16 to fail in readonly mode.
    43  
    44  cp go.mod.orig go.mod
    45  go mod tidy -compat=1.17
    46  cmp go.mod go.mod.orig
    47  
    48  go list -m all
    49  cmp stdout m_all.txt
    50  
    51  go mod edit -go=1.16
    52  ! go list -m all
    53  stderr '^go: example.net/lazy@v0.1.0 requires\n\texample.com/version@v1.0.1: missing go.sum entry for go.mod file; to add it:\n\tgo mod download example.com/version$'
    54  
    55  
    56  -- go.mod --
    57  // Module m happens to have the exact same build list as what would be
    58  // selected under Go 1.16, but computes that build list without looking at
    59  // as many go.mod files.
    60  module example.com/m
    61  
    62  go 1.17
    63  
    64  replace example.net/lazy v0.1.0 => ./lazy
    65  
    66  require (
    67  	example.com/version v1.1.0
    68  	example.net/lazy v0.1.0
    69  )
    70  -- m_all.txt --
    71  example.com/m
    72  example.com/version v1.1.0
    73  example.net/lazy v0.1.0 => ./lazy
    74  -- compatible.go --
    75  package compatible
    76  
    77  import (
    78  	_ "example.com/version"
    79  	_ "example.net/lazy"
    80  )
    81  -- lazy/go.mod --
    82  // Module lazy requires example.com/version v1.0.1.
    83  //
    84  // However, since this module is lazy, its dependents
    85  // should not need checksums for that version of the module
    86  // unless they actually import packages from it.
    87  module example.net/lazy
    88  
    89  go 1.17
    90  
    91  require example.com/version v1.0.1
    92  -- lazy/lazy.go --
    93  package lazy
    94  
    95  import _ "example.com/version"
    96  

View as plain text