...
1cp go.mod go.mod.orig
2
3# For modules whose go.mod file does not include a 'go' directive,
4# we assume the language and dependency semantics of Go 1.16,
5# but do not trigger “automatic vendoring” mode (-mod=vendor),
6# which was added in Go 1.14 and was not triggered
7# under the same conditions in Go 1.16 (which would instead
8# default to -mod=readonly when no 'go' directive is present).
9
10# For Go 1.16 modules, 'all' should prune out dependencies of tests,
11# even if the 'go' directive is missing.
12
13go list -mod=readonly all
14stdout '^example.com/dep$'
15! stdout '^example.com/testdep$'
16cp stdout list-1.txt
17cmp go.mod go.mod.orig
18
19# We should only default to -mod=vendor if the 'go' directive is explicit in the
20# go.mod file. Otherwise, we don't actually know whether the module was written
21# against Go 1.11 or 1.16. We would have to update the go.mod file to clarify,
22# and as of Go 1.16 we don't update the go.mod file by default.
23#
24# If we set -mod=vendor explicitly, we shouldn't apply the Go 1.14
25# consistency check, because — again — we don't know whether we're in a 1.11
26# module or a bad-script-edited 1.16 module.
27
28! go list -mod=vendor all
29! stderr '^go: inconsistent vendoring'
30stderr 'cannot find module providing package example.com/badedit: import lookup disabled by -mod=vendor'
31
32# When we set -mod=mod, the go version should be updated immediately,
33# to the current version, converting the requirements from eager to lazy.
34#
35# Since we don't know which requirements are actually relevant to the main
36# module, all requirements are added as roots, making the requirements untidy.
37
38go list -mod=mod all
39! stdout '^example.com/testdep$'
40cmp stdout list-1.txt
41cmpenv go.mod go.mod.untidy
42
43go mod tidy
44cmpenv go.mod go.mod.tidy
45
46# On the other hand, if we jump straight to 'go mod tidy',
47# the requirements remain tidy from the start.
48
49cp go.mod.orig go.mod
50go mod tidy
51cmpenv go.mod go.mod.tidy
52
53
54# The updated version should have been written back to go.mod, so now the 'go'
55# directive is explicit. -mod=vendor should trigger by default, and the stronger
56# Go 1.14 consistency check should apply.
57! go list all
58stderr '^go: inconsistent vendoring'
59! stderr badedit
60
61
62-- go.mod --
63module example.com/m
64
65require example.com/dep v0.1.0
66
67replace (
68 example.com/dep v0.1.0 => ./dep
69 example.com/testdep v0.1.0 => ./testdep
70)
71-- go.mod.untidy --
72module example.com/m
73
74go $goversion
75
76require example.com/dep v0.1.0
77
78require example.com/testdep v0.1.0 // indirect
79
80replace (
81 example.com/dep v0.1.0 => ./dep
82 example.com/testdep v0.1.0 => ./testdep
83)
84-- go.mod.tidy --
85module example.com/m
86
87go $goversion
88
89require example.com/dep v0.1.0
90
91replace (
92 example.com/dep v0.1.0 => ./dep
93 example.com/testdep v0.1.0 => ./testdep
94)
95-- vendor/example.com/dep/dep.go --
96package dep
97import _ "example.com/badedit"
98-- vendor/modules.txt --
99HAHAHA this is broken.
100
101-- m.go --
102package m
103
104import _ "example.com/dep"
105
106const x = 1_000
107
108-- dep/go.mod --
109module example.com/dep
110
111require example.com/testdep v0.1.0
112-- dep/dep.go --
113package dep
114-- dep/dep_test.go --
115package dep_test
116
117import _ "example.com/testdep"
118
119-- testdep/go.mod --
120module example.com/testdep
121-- testdep/testdep.go --
122package testdep
View as plain text