...

Text file src/cmd/go/testdata/script/mod_tidy_compat_deleted.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# For this module, the "deleted" dependency contains an imported package, but
    14# Go 1.16 selects a higher version (in which that package has been deleted).
    15
    16cp go.mod go.mod.orig
    17
    18! go mod tidy
    19
    20stderr '^go: example\.com/m imports\n\texample\.net/deleted loaded from example\.net/deleted@v0\.1\.0,\n\tbut go 1\.16 would fail to locate it in example\.net/deleted@v0\.2\.0\n\n'
    21
    22stderr '\n\nTo upgrade to the versions selected by go 1.16, leaving some packages unresolved:\n\tgo mod tidy -e -go=1\.16 && go mod tidy -e -go=1\.17\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'
    23
    24# Make sure that -diff behaves the same as tidy.
    25[exec:patch] cp go.mod.orig go.mod
    26[exec:patch] ! exists go.sum
    27[exec:patch] ! go mod tidy -diff
    28[exec:patch] ! stdout .
    29[exec:patch] stderr '^go: example\.com/m imports\n\texample\.net/deleted loaded from example\.net/deleted@v0\.1\.0,\n\tbut go 1\.16 would fail to locate it in example\.net/deleted@v0\.2\.0\n\n'
    30[exec:patch] stderr '\n\nTo upgrade to the versions selected by go 1.16, leaving some packages unresolved:\n\tgo mod tidy -e -go=1\.16 && go mod tidy -e -go=1\.17\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'
    31
    32# The suggested 'go mod tidy -e' command should proceed anyway.
    33
    34go mod tidy -e
    35cmp go.mod go.mod.tidy
    36
    37# Make sure that -diff behaves the same as tidy.
    38[exec:patch] cp go.mod go.mod.tidyResult
    39[exec:patch] ! exists go.sum
    40[exec:patch] cp go.mod.orig go.mod
    41[exec:patch] ! go mod tidy -e -diff
    42[exec:patch] cp stdout diff.patch
    43[exec:patch] exec patch -p1 -i diff.patch
    44[exec:patch] go mod tidy -e -diff
    45[exec:patch] ! stdout .
    46[exec:patch] cmp go.mod go.mod.tidyResult
    47[exec:patch] ! exists go.sum
    48
    49# In 'go 1.16' mode we should error out in the way we claimed.
    50
    51cd 116-outside
    52! go list -deps -f $MODFMT example.com/m
    53stderr '^\.\.[/\\]m\.go:4:2: no required module provides package example\.net/deleted; to add it:\n\tgo get example\.net/deleted$'
    54cd ..
    55
    56go mod edit -go=1.16
    57! go list -deps -f $MODFMT example.com/m
    58stderr '^go: updates to go\.mod needed; to update it:\n\tgo mod tidy$'
    59
    60[exec:patch] cp go.mod go.mod.orig
    61! go mod tidy
    62stderr '^go: example\.com/m imports\n\texample\.net/deleted: module example\.net/deleted@latest found \(v0\.2\.0, replaced by \./d2\), but does not contain package example\.net/deleted$'
    63
    64# Make sure that -diff behaves the same as tidy.
    65[exec:patch] cp go.mod.orig go.mod
    66[exec:patch] ! exists go.sum
    67[exec:patch] ! go mod tidy -diff
    68[exec:patch] ! stdout .
    69[exec:patch] stderr '^go: example\.com/m imports\n\texample\.net/deleted: module example\.net/deleted@latest found \(v0\.2\.0, replaced by \./d2\), but does not contain package example\.net/deleted$'
    70
    71-- go.mod --
    72module example.com/m
    73
    74go 1.17
    75
    76replace (
    77	example.net/deleted v0.1.0 => ./d1
    78	example.net/deleted v0.2.0 => ./d2
    79	example.net/lazy v0.1.0 => ./lazy
    80	example.net/pruned v0.1.0 => ./pruned
    81)
    82
    83require (
    84	example.net/deleted v0.1.0
    85	example.net/deleted v0.1.0 // redundant
    86	example.net/lazy v0.1.0
    87)
    88-- go.mod.tidy --
    89module example.com/m
    90
    91go 1.17
    92
    93replace (
    94	example.net/deleted v0.1.0 => ./d1
    95	example.net/deleted v0.2.0 => ./d2
    96	example.net/lazy v0.1.0 => ./lazy
    97	example.net/pruned v0.1.0 => ./pruned
    98)
    99
   100require (
   101	example.net/deleted v0.1.0
   102	example.net/lazy v0.1.0
   103)
   104-- 116-outside/go.mod --
   105module outside
   106
   107go 1.16
   108
   109replace (
   110	example.com/m => ../
   111	example.net/deleted v0.1.0 => ../d1
   112	example.net/deleted v0.2.0 => ../d2
   113	example.net/lazy v0.1.0 => ../lazy
   114	example.net/pruned v0.1.0 => ../pruned
   115)
   116
   117require example.com/m v0.1.0
   118-- m.go --
   119package m
   120
   121import (
   122	_ "example.net/deleted"
   123	_ "example.net/lazy"
   124)
   125
   126-- d1/go.mod --
   127module example.net/deleted
   128
   129go 1.17
   130-- d1/deleted.go --
   131package deleted
   132-- d2/go.mod --
   133module example.net/deleted
   134
   135go 1.17
   136-- d2/README --
   137There is no longer a Go package here.
   138
   139-- lazy/go.mod --
   140module example.net/lazy
   141
   142go 1.17
   143
   144require example.net/pruned v0.1.0
   145-- lazy/lazy.go --
   146package lazy
   147
   148-- pruned/go.mod --
   149module example.net/pruned
   150
   151go 1.17
   152
   153require example.net/deleted v0.2.0

View as plain text