...

Text file src/cmd/go/testdata/script/mod_tidy_compat_ambiguous.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# For this module, the dependency providing package
    13# example.net/ambiguous/nested/pkg is unambiguous in Go 1.17 (because only one
    14# root of the module graph contains the package), whereas it is ambiguous in
    15# Go 1.16 (because two different modules contain plausible packages and Go 1.16
    16# does not privilege roots above other dependencies).
    17#
    18# However, the overall build list is identical for both versions.
    19
    20cp go.mod go.mod.orig
    21
    22! go mod tidy
    23
    24stderr '^go: example\.com/m imports\n\texample\.net/indirect imports\n\texample\.net/ambiguous/nested/pkg loaded from example\.net/ambiguous/nested@v0\.1\.0,\n\tbut go 1.16 would fail to locate it:\n\tambiguous import: found package example\.net/ambiguous/nested/pkg in multiple modules:\n\texample\.net/ambiguous v0.1.0 \(.*\)\n\texample\.net/ambiguous/nested v0.1.0 \(.*\)\n\n'
    25
    26stderr '\n\nTo proceed despite packages unresolved in go 1\.16:\n\tgo mod tidy -e\nIf reproducibility with go 1.16 is not needed:\n\tgo mod tidy -compat=1\.17\nFor other options, see:\n\thttps://golang\.org/doc/modules/pruning\n'
    27
    28cmp go.mod go.mod.orig
    29
    30
    31# If we run 'go mod tidy -e', we should still save enough checksums to run
    32# 'go list -m all' reproducibly with go 1.16, even though we can't list
    33# the specific package.
    34
    35go mod tidy -e
    36! stderr '\n\tgo mod tidy'
    37cmp go.mod go.mod.orig
    38
    39go list -m all
    40cmp stdout all-m.txt
    41
    42go list -f $MODFMT example.net/ambiguous/nested/pkg
    43stdout '^example.net/ambiguous/nested v0\.1\.0$'
    44! stderr .
    45
    46go mod edit -go=1.16
    47go list -m all
    48cmp stdout all-m.txt
    49
    50! go list -f $MODFMT example.net/ambiguous/nested/pkg
    51stderr '^ambiguous import: found package example\.net/ambiguous/nested/pkg in multiple modules:\n\texample\.net/ambiguous v0\.1\.0 \(.*\)\n\texample\.net/ambiguous/nested v0\.1\.0 \(.*\)\n'
    52
    53
    54# On the other hand, if we use -compat=1.17, 1.16 can't even load
    55# the build list (due to missing checksums).
    56
    57cp go.mod.orig go.mod
    58go mod tidy -compat=1.17
    59! stderr .
    60go list -m all
    61cmp stdout all-m.txt
    62
    63go mod edit -go=1.16
    64! go list -m all
    65stderr '^go: example\.net/indirect@v0\.1\.0 requires\n\texample\.net/ambiguous@v0\.1\.0: missing go\.sum entry for go\.mod file; to add it:\n\tgo mod download example\.net/ambiguous\n'
    66
    67
    68-- go.mod --
    69module example.com/m
    70
    71go 1.17
    72
    73replace example.net/indirect v0.1.0 => ./indirect
    74
    75require example.net/indirect v0.1.0
    76
    77require example.net/ambiguous/nested v0.1.0 // indirect
    78-- all-m.txt --
    79example.com/m
    80example.net/ambiguous v0.1.0
    81example.net/ambiguous/nested v0.1.0
    82example.net/indirect v0.1.0 => ./indirect
    83-- m.go --
    84package m
    85
    86import _ "example.net/indirect"
    87
    88-- indirect/go.mod --
    89module example.net/indirect
    90
    91go 1.17
    92
    93require example.net/ambiguous v0.1.0
    94-- indirect/indirect.go --
    95package indirect
    96
    97import _ "example.net/ambiguous/nested/pkg"

View as plain text