...

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

Documentation: cmd/go/testdata/script

     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
    10env 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
    29cp go.mod go.mod.orig
    30go mod tidy
    31cmp go.mod go.mod.orig
    32
    33go list -m all
    34cmp stdout m_all.txt
    35
    36go mod edit -go=1.16
    37go list -m all
    38cmp 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
    44cp go.mod.orig go.mod
    45go mod tidy -compat=1.17
    46cmp go.mod go.mod.orig
    47
    48go list -m all
    49cmp stdout m_all.txt
    50
    51go mod edit -go=1.16
    52! go list -m all
    53stderr '^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.
    60module example.com/m
    61
    62go 1.17
    63
    64replace example.net/lazy v0.1.0 => ./lazy
    65
    66require (
    67	example.com/version v1.1.0
    68	example.net/lazy v0.1.0
    69)
    70-- m_all.txt --
    71example.com/m
    72example.com/version v1.1.0
    73example.net/lazy v0.1.0 => ./lazy
    74-- compatible.go --
    75package compatible
    76
    77import (
    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.
    87module example.net/lazy
    88
    89go 1.17
    90
    91require example.com/version v1.0.1
    92-- lazy/lazy.go --
    93package lazy
    94
    95import _ "example.com/version"

View as plain text