...

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# Make sure that -diff behaves the same as tidy.
    31[exec:patch] cp go.mod.orig go.mod
    32[exec:patch] ! exists go.sum
    33[exec:patch] ! go mod tidy -diff
    34[exec:patch] ! stdout .
    35[exec:patch] stderr '^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'
    36[exec:patch] stderr '\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'
    37
    38
    39# If we run 'go mod tidy -e', we should still save enough checksums to run
    40# 'go list -m all' reproducibly with go 1.16, even though we can't list
    41# the specific package.
    42
    43go mod tidy -e
    44! stderr '\n\tgo mod tidy'
    45cmp go.mod go.mod.orig
    46
    47# Make sure that -diff behaves the same as tidy.
    48[exec:patch] mv go.mod go.mod.tidyResult
    49[exec:patch] mv go.sum go.sum.tidyResult
    50[exec:patch] cp go.mod.orig go.mod
    51[exec:patch] ! go mod tidy -e -diff
    52[exec:patch] ! stderr '\n\tgo mod tidy'
    53[exec:patch] cp stdout diff.patch
    54[exec:patch] exec patch -p1 -i diff.patch
    55[exec:patch] go mod tidy -e -diff
    56[exec:patch] ! stdout .
    57[exec:patch] cmp go.mod go.mod.tidyResult
    58[exec:patch] cmp go.sum go.sum.tidyResult
    59
    60go list -m all
    61cmp stdout all-m.txt
    62
    63go list -f $MODFMT example.net/ambiguous/nested/pkg
    64stdout '^example.net/ambiguous/nested v0\.1\.0$'
    65! stderr .
    66
    67go mod edit -go=1.16
    68go list -m all
    69cmp stdout all-m.txt
    70
    71! go list -f $MODFMT example.net/ambiguous/nested/pkg
    72stderr '^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'
    73
    74
    75# On the other hand, if we use -compat=1.17, 1.16 can't even load
    76# the build list (due to missing checksums).
    77
    78cp go.mod.orig go.mod
    79go mod tidy -compat=1.17
    80! stderr .
    81go list -m all
    82cmp stdout all-m.txt
    83
    84# Make sure that -diff behaves the same as tidy.
    85[exec:patch] mv go.mod go.mod.tidyResult
    86[exec:patch] mv go.sum go.sum.tidyResult
    87[exec:patch] cp go.mod.orig go.mod
    88[exec:patch] ! go mod tidy -compat=1.17 -diff
    89[exec:patch] ! stderr .
    90[exec:patch] cp stdout diff.patch
    91[exec:patch] exec patch -p1 -i diff.patch
    92[exec:patch] go mod tidy -compat=1.17 -diff
    93[exec:patch] ! stdout .
    94[exec:patch] cmp go.mod go.mod.tidyResult
    95[exec:patch] cmp go.sum go.sum.tidyResult
    96
    97go mod edit -go=1.16
    98! go list -m all
    99stderr '^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'
   100
   101
   102-- go.mod --
   103module example.com/m
   104
   105go 1.17
   106
   107replace example.net/indirect v0.1.0 => ./indirect
   108
   109require example.net/indirect v0.1.0
   110
   111require example.net/ambiguous/nested v0.1.0 // indirect
   112-- all-m.txt --
   113example.com/m
   114example.net/ambiguous v0.1.0
   115example.net/ambiguous/nested v0.1.0
   116example.net/indirect v0.1.0 => ./indirect
   117-- m.go --
   118package m
   119
   120import _ "example.net/indirect"
   121
   122-- indirect/go.mod --
   123module example.net/indirect
   124
   125go 1.17
   126
   127require example.net/ambiguous v0.1.0
   128-- indirect/indirect.go --
   129package indirect
   130
   131import _ "example.net/ambiguous/nested/pkg"

View as plain text