1 cp 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
13 go list -mod=readonly all
14 stdout '^example.com/dep$'
15 ! stdout '^example.com/testdep$'
16 cp stdout list-1.txt
17 cmp 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'
30 stderr 'cannot find package "vendor/example.com/badedit" in:\n\t.*[/\\]vendor[/\\]example.com[/\\]badedit$'
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
38 go list -mod=mod all
39 ! stdout '^example.com/testdep$'
40 cmp stdout list-1.txt
41 cmpenv go.mod go.mod.untidy
42
43 go mod tidy
44 cmpenv 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
49 cp go.mod.orig go.mod
50 go mod tidy
51 cmpenv 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
58 stderr '^go: inconsistent vendoring'
59 ! stderr badedit
60
61
62 -- go.mod --
63 module example.com/m
64
65 require example.com/dep v0.1.0
66
67 replace (
68 example.com/dep v0.1.0 => ./dep
69 example.com/testdep v0.1.0 => ./testdep
70 )
71 -- go.mod.untidy --
72 module example.com/m
73
74 go $goversion
75
76 require example.com/dep v0.1.0
77
78 require example.com/testdep v0.1.0 // indirect
79
80 replace (
81 example.com/dep v0.1.0 => ./dep
82 example.com/testdep v0.1.0 => ./testdep
83 )
84 -- go.mod.tidy --
85 module example.com/m
86
87 go $goversion
88
89 require example.com/dep v0.1.0
90
91 replace (
92 example.com/dep v0.1.0 => ./dep
93 example.com/testdep v0.1.0 => ./testdep
94 )
95 -- vendor/example.com/dep/dep.go --
96 package dep
97 import _ "example.com/badedit"
98 -- vendor/modules.txt --
99 HAHAHA this is broken.
100
101 -- m.go --
102 package m
103
104 import _ "example.com/dep"
105
106 const x = 1_000
107
108 -- dep/go.mod --
109 module example.com/dep
110
111 require example.com/testdep v0.1.0
112 -- dep/dep.go --
113 package dep
114 -- dep/dep_test.go --
115 package dep_test
116
117 import _ "example.com/testdep"
118
119 -- testdep/go.mod --
120 module example.com/testdep
121 -- testdep/testdep.go --
122 package testdep
123
View as plain text