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
10 env 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
16 cp go.mod go.mod.orig
17
18 ! go mod tidy
19
20 stderr '^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
22 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'
23
24
25 # The suggested 'go mod tidy -e' command should proceed anyway.
26
27 go mod tidy -e
28 cmp go.mod go.mod.tidy
29
30
31 # In 'go 1.16' mode we should error out in the way we claimed.
32
33 cd 116-outside
34 ! go list -deps -f $MODFMT example.com/m
35 stderr '^\.\.[/\\]m\.go:4:2: no required module provides package example\.net/deleted; to add it:\n\tgo get example\.net/deleted$'
36 cd ..
37
38 go mod edit -go=1.16
39 ! go list -deps -f $MODFMT example.com/m
40 stderr '^go: updates to go\.mod needed; to update it:\n\tgo mod tidy$'
41
42 ! go mod tidy
43 stderr '^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 --
47 module example.com/m
48
49 go 1.17
50
51 replace (
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
58 require (
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 --
64 module example.com/m
65
66 go 1.17
67
68 replace (
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
75 require (
76 example.net/deleted v0.1.0
77 example.net/lazy v0.1.0
78 )
79 -- 116-outside/go.mod --
80 module outside
81
82 go 1.16
83
84 replace (
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
92 require example.com/m v0.1.0
93 -- m.go --
94 package m
95
96 import (
97 _ "example.net/deleted"
98 _ "example.net/lazy"
99 )
100
101 -- d1/go.mod --
102 module example.net/deleted
103
104 go 1.17
105 -- d1/deleted.go --
106 package deleted
107 -- d2/go.mod --
108 module example.net/deleted
109
110 go 1.17
111 -- d2/README --
112 There is no longer a Go package here.
113
114 -- lazy/go.mod --
115 module example.net/lazy
116
117 go 1.17
118
119 require example.net/pruned v0.1.0
120 -- lazy/lazy.go --
121 package lazy
122
123 -- pruned/go.mod --
124 module example.net/pruned
125
126 go 1.17
127
128 require example.net/deleted v0.2.0
129
View as plain text