1 # Regression test for golang.org/issue/34822: the 'go' command should prefer not
2 # to update the go.mod file if the changes only affect formatting, and should only
3 # remove redundant requirements in 'go mod tidy'.
4
5 env GO111MODULE=on
6 [short] skip
7
8 # Control case: verify that go.mod.tidy is actually tidy.
9 cp go.mod.tidy go.mod
10 go list -mod=mod all
11 cmp go.mod go.mod.tidy
12
13
14 # If the only difference in the go.mod file is the line endings,
15 # it should not be overwritten automatically.
16 cp go.mod.crlf go.mod
17 go list all
18 cmp go.mod go.mod.crlf
19
20 # However, 'go mod tidy' should fix whitespace even if there are no other changes.
21 go mod tidy
22 cmp go.mod go.mod.tidy
23
24
25 # Out-of-order requirements should not be overwritten automatically...
26 cp go.mod.unsorted go.mod
27 go list all
28 cmp go.mod go.mod.unsorted
29
30 # ...but 'go mod edit -fmt' should sort them.
31 go mod edit -fmt
32 cmp go.mod go.mod.tidy
33
34
35 # "// indirect" comments should be removed if direct dependencies are seen.
36 # changes.
37 cp go.mod.indirect go.mod
38 go list -mod=mod all
39 cmp go.mod go.mod.tidy
40
41 # "// indirect" comments should be added if appropriate.
42 # TODO(#42504): add case for 'go list -mod=mod -tags=any all' when -tags=any
43 # is supported. Only a command that loads "all" without build constraints
44 # (except "ignore") has enough information to add "// indirect" comments.
45 # 'go mod tidy' and 'go mod vendor' are the only commands that do that,
46 # but 'go mod vendor' cannot write go.mod.
47 cp go.mod.toodirect go.mod
48 go list all
49 cmp go.mod go.mod.toodirect
50
51
52 # Redundant requirements should be preserved...
53 cp go.mod.redundant go.mod
54 go list all
55 cmp go.mod go.mod.redundant
56 go mod vendor
57 cmp go.mod go.mod.redundant
58 rm -r vendor
59
60 # ...except by 'go mod tidy'.
61 go mod tidy
62 cmp go.mod go.mod.tidy
63
64
65 # A missing "go" version directive should be added.
66 # However, that should not remove other redundant requirements.
67 # In fact, it may *add* redundant requirements due to activating lazy loading.
68 cp go.mod.nogo go.mod
69 go list -mod=mod all
70 cmpenv go.mod go.mod.addedgo
71
72
73 -- go.mod.tidy --
74 module m
75
76 go 1.14
77
78 require (
79 rsc.io/quote v1.5.2
80 rsc.io/testonly v1.0.0 // indirect
81 )
82 -- x.go --
83 package x
84 import _ "rsc.io/quote"
85 -- go.mod.crlf --
86 module m
87
88 go 1.14
89
90 require (
91 rsc.io/quote v1.5.2
92 rsc.io/testonly v1.0.0 // indirect
93 )
94 -- go.mod.unsorted --
95 module m
96
97 go 1.14
98
99 require (
100 rsc.io/testonly v1.0.0 // indirect
101 rsc.io/quote v1.5.2
102 )
103 -- go.mod.indirect --
104 module m
105
106 go 1.14
107
108 require (
109 rsc.io/quote v1.5.2 // indirect
110 rsc.io/testonly v1.0.0 // indirect
111 )
112 -- go.mod.toodirect --
113 module m
114
115 go 1.14
116
117 require (
118 rsc.io/quote v1.5.2
119 rsc.io/testonly v1.0.0
120 )
121 -- go.mod.redundant --
122 module m
123
124 go 1.14
125
126 require (
127 rsc.io/quote v1.5.2
128 rsc.io/sampler v1.3.0 // indirect
129 rsc.io/testonly v1.0.0 // indirect
130 )
131 -- go.mod.nogo --
132 module m
133
134 require (
135 rsc.io/quote v1.5.2
136 rsc.io/sampler v1.3.0 // indirect
137 rsc.io/testonly v1.0.0 // indirect
138 )
139 -- go.mod.addedgo --
140 module m
141
142 go $goversion
143
144 require rsc.io/quote v1.5.2
145
146 require (
147 golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c // indirect
148 rsc.io/sampler v1.3.0 // indirect
149 rsc.io/testonly v1.0.0 // indirect
150 )
151
View as plain text