...

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
    25# The suggested 'go mod tidy -e' command should proceed anyway.
    26
    27go mod tidy -e
    28cmp go.mod go.mod.tidy
    29
    30
    31# In 'go 1.16' mode we should error out in the way we claimed.
    32
    33cd 116-outside
    34! go list -deps -f $MODFMT example.com/m
    35stderr '^\.\.[/\\]m\.go:4:2: no required module provides package example\.net/deleted; to add it:\n\tgo get example\.net/deleted$'
    36cd ..
    37
    38go mod edit -go=1.16
    39! go list -deps -f $MODFMT example.com/m
    40stderr '^go: updates to go\.mod needed; to update it:\n\tgo mod tidy$'
    41
    42! go mod tidy
    43stderr '^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$'
    44
    45
    46-- go.mod --
    47module example.com/m
    48
    49go 1.17
    50
    51replace (
    52	example.net/deleted v0.1.0 => ./d1
    53	example.net/deleted v0.2.0 => ./d2
    54	example.net/lazy v0.1.0 => ./lazy
    55	example.net/pruned v0.1.0 => ./pruned
    56)
    57
    58require (
    59	example.net/deleted v0.1.0
    60	example.net/deleted v0.1.0 // redundant
    61	example.net/lazy v0.1.0
    62)
    63-- go.mod.tidy --
    64module example.com/m
    65
    66go 1.17
    67
    68replace (
    69	example.net/deleted v0.1.0 => ./d1
    70	example.net/deleted v0.2.0 => ./d2
    71	example.net/lazy v0.1.0 => ./lazy
    72	example.net/pruned v0.1.0 => ./pruned
    73)
    74
    75require (
    76	example.net/deleted v0.1.0
    77	example.net/lazy v0.1.0
    78)
    79-- 116-outside/go.mod --
    80module outside
    81
    82go 1.16
    83
    84replace (
    85	example.com/m => ../
    86	example.net/deleted v0.1.0 => ../d1
    87	example.net/deleted v0.2.0 => ../d2
    88	example.net/lazy v0.1.0 => ../lazy
    89	example.net/pruned v0.1.0 => ../pruned
    90)
    91
    92require example.com/m v0.1.0
    93-- m.go --
    94package m
    95
    96import (
    97	_ "example.net/deleted"
    98	_ "example.net/lazy"
    99)
   100
   101-- d1/go.mod --
   102module example.net/deleted
   103
   104go 1.17
   105-- d1/deleted.go --
   106package deleted
   107-- d2/go.mod --
   108module example.net/deleted
   109
   110go 1.17
   111-- d2/README --
   112There is no longer a Go package here.
   113
   114-- lazy/go.mod --
   115module example.net/lazy
   116
   117go 1.17
   118
   119require example.net/pruned v0.1.0
   120-- lazy/lazy.go --
   121package lazy
   122
   123-- pruned/go.mod --
   124module example.net/pruned
   125
   126go 1.17
   127
   128require example.net/deleted v0.2.0

View as plain text