...
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, Go 1.17 produces an error for one module, and Go 1.16
14# produces a different error for a different module.
15
16cp go.mod go.mod.orig
17
18! go mod tidy
19
20stderr '^go: example\.com/m imports\n\texample\.net/added: module example\.net/added@latest found \(v0\.3\.0, replaced by \./a1\), but does not contain package example\.net/added$'
21
22cmp go.mod go.mod.orig
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/added: module example\.net/added@latest found \(v0\.3\.0, replaced by \./a1\), but does not contain package example\.net/added$'
30
31# When we run 'go mod tidy -e', we should proceed past the first error and follow
32# it with a second error describing the version discrepancy.
33#
34# We should not provide advice on how to push past the version discrepancy,
35# because the '-e' flag should already do that, writing out an otherwise-tidied
36# go.mod file.
37
38go mod tidy -e
39
40stderr '^go: example\.com/m imports\n\texample\.net/added: module example\.net/added@latest found \(v0\.3\.0, replaced by \./a1\), but does not contain package example\.net/added\ngo: example\.net/added failed to load from any module,\n\tbut go 1\.16 would load it from example\.net/added@v0\.2\.0$'
41
42! stderr '\n\tgo mod tidy'
43
44cmp go.mod go.mod.tidy
45
46# Make sure that -diff behaves the same as tidy.
47[exec:patch] cp go.mod go.mod.tidyResult
48[exec:patch] ! exists go.sum
49[exec:patch] cp go.mod.orig go.mod
50[exec:patch] ! go mod tidy -e -diff
51[exec:patch] stdout 'diff current/go.mod tidy/go.mod'
52[exec:patch] stderr '^go: example\.com/m imports\n\texample\.net/added: module example\.net/added@latest found \(v0\.3\.0, replaced by \./a1\), but does not contain package example\.net/added\ngo: example\.net/added failed to load from any module,\n\tbut go 1\.16 would load it from example\.net/added@v0\.2\.0$'
53[exec:patch] ! stderr '\n\tgo mod tidy'
54[exec:patch] cp stdout diff.patch
55[exec:patch] exec patch -p1 -i diff.patch
56[exec:patch] go mod tidy -e -diff
57[exec:patch] ! stdout .
58[exec:patch] cmp go.mod go.mod.tidyResult
59[exec:patch] ! exists go.sum
60
61-- go.mod --
62module example.com/m
63
64go 1.17
65
66replace (
67 example.net/added v0.1.0 => ./a1
68 example.net/added v0.2.0 => ./a2
69 example.net/added v0.3.0 => ./a1
70 example.net/lazy v0.1.0 => ./lazy
71 example.net/pruned v0.1.0 => ./pruned
72)
73
74require (
75 example.net/added v0.1.0
76 example.net/lazy v0.1.0
77)
78-- go.mod.tidy --
79module example.com/m
80
81go 1.17
82
83replace (
84 example.net/added v0.1.0 => ./a1
85 example.net/added v0.2.0 => ./a2
86 example.net/added v0.3.0 => ./a1
87 example.net/lazy v0.1.0 => ./lazy
88 example.net/pruned v0.1.0 => ./pruned
89)
90
91require example.net/lazy v0.1.0
92-- m.go --
93package m
94
95import (
96 _ "example.net/added"
97 _ "example.net/lazy"
98)
99
100-- a1/go.mod --
101module example.net/added
102
103go 1.17
104-- a2/go.mod --
105module example.net/added
106
107go 1.17
108-- a2/added.go --
109package added
110
111-- lazy/go.mod --
112module example.net/lazy
113
114go 1.17
115
116require example.net/pruned v0.1.0
117-- lazy/lazy.go --
118package lazy
119
120-- pruned/go.mod --
121module example.net/pruned
122
123go 1.17
124
125require example.net/added v0.2.0
View as plain text