aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/testdata/script/mod_vendor.txt
blob: 4eb80c23324c68f7e78cfe09c56e7edec27a4e49 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
env GO111MODULE=on

# Without vendoring, a build should succeed unless -mod=vendor is set.
[!short] go build
[!short] ! go build -mod=vendor

# Without vendoring, 'go list' should report the replacement directory for
# a package in a replaced module.
go list -f {{.Dir}} x
stdout 'src[\\/]x'

# 'go mod vendor' should copy all replaced modules to the vendor directory.
go mod vendor -v
stderr '^# x v1.0.0 => ./x'
stderr '^x'
stderr '^# y v1.0.0 => ./y'
stderr '^y'
stderr '^# z v1.0.0 => ./z'
stderr '^z'
! stderr '^w'
grep 'a/foo/bar/b\na/foo/bar/c' vendor/modules.txt # must be sorted

# An explicit '-mod=mod' should ignore the vendor directory.
go list -mod=mod -f {{.Dir}} x
stdout 'src[\\/]x'

go list -mod=mod -f {{.Dir}} -m x
stdout 'src[\\/]x'

# An explicit '-mod=vendor' should report package directories within
# the vendor directory.
go list -mod=vendor -f {{.Dir}} x
stdout 'src[\\/]vendor[\\/]x'

# 'go list -mod=vendor -m' should successfully list vendored modules,
# but should not provide a module directory because no directory contains
# the complete module.
go list -mod=vendor -f '{{.Version}} {{.Dir}}' -m x
stdout '^v1.0.0 $'

# -mod=vendor should cause 'go list' flags that look up versions to fail.
! go list -mod=vendor -versions -m x
stderr '^go: can''t determine available versions using the vendor directory\n\t\(Use -mod=mod or -mod=readonly to bypass.\)$'
! go list -mod=vendor -u -m x
stderr '^go: can''t determine available upgrades using the vendor directory\n\t\(Use -mod=mod or -mod=readonly to bypass.\)$'

# 'go list -mod=vendor -m' on a transitive dependency that does not
# provide vendored packages should give a helpful error rather than
# 'not a known dependency'.
! go list -mod=vendor -f '{{.Version}} {{.Dir}}' -m diamondright
stderr 'go: module diamondright: can''t resolve module using the vendor directory\n\t\(Use -mod=mod or -mod=readonly to bypass.\)'

# 'go list -mod=mod' should report packages outside the import graph,
# but 'go list -mod=vendor' should error out for them.
go list -mod=mod -f {{.Dir}} w
stdout 'src[\\/]w'
! go list -mod=vendor -f {{.Dir}} w
stderr 'src[\\/]vendor[\\/]w'

go list -mod=mod -f {{.Dir}} diamondright
stdout 'src[\\/]diamondright'

# Test dependencies should not be copied.
! exists vendor/x/testdata
! exists vendor/a/foo/bar/b/ignored.go
! exists vendor/a/foo/bar/b/main_test.go

# Licenses and other metadata for each module should be copied
# if any package within their module is copied.
exists vendor/a/foo/AUTHORS.txt
exists vendor/a/foo/CONTRIBUTORS
exists vendor/a/foo/LICENSE
exists vendor/a/foo/PATENTS
exists vendor/a/foo/COPYING
exists vendor/a/foo/COPYLEFT
exists vendor/x/NOTICE!
exists vendor/mysite/myname/mypkg/LICENSE.txt

! exists vendor/a/foo/licensed-to-kill
! exists vendor/w
! exists vendor/w/LICENSE
! exists vendor/x/x2
! exists vendor/x/x2/LICENSE

[short] stop

# 'go build' and 'go test' using vendored packages should succeed.
go build -mod=mod
go build -mod=vendor
go test -mod=vendor . ./subdir
go test -mod=vendor ./...
go fmt -mod=vendor ./...

-- go.mod --
module m

go 1.13

require (
	a v1.0.0
	diamondroot v0.0.0
	mysite/myname/mypkg v1.0.0
	w v1.0.0 // indirect
	x v1.0.0
	y v1.0.0
	z v1.0.0
)

replace (
	a v1.0.0 => ./a
	diamondleft => ./diamondleft
	diamondpoint => ./diamondpoint
	diamondright => ./diamondright
	diamondroot => ./diamondroot
	mysite/myname/mypkg v1.0.0 => ./mypkg
	w v1.0.0 => ./w
	x v1.0.0 => ./x
	y v1.0.0 => ./y
	z v1.0.0 => ./z
)

-- a/foo/AUTHORS.txt --
-- a/foo/CONTRIBUTORS --
-- a/foo/LICENSE --
-- a/foo/PATENTS --
-- a/foo/COPYING --
-- a/foo/COPYLEFT --
-- a/foo/licensed-to-kill --
-- w/LICENSE --
-- x/NOTICE! --
-- x/x2/LICENSE --
-- mypkg/LICENSE.txt --

-- a/foo/bar/b/main.go --
package b
-- a/foo/bar/b/ignored.go --
// This file is intended for use with "go run"; it isn't really part of the package.

// +build ignore

package main

func main() {}
-- a/foo/bar/b/main_test.go --
package b

import (
	"os"
	"testing"
)

func TestDir(t *testing.T) {
	if _, err := os.Stat("../testdata/1"); err != nil {
		t.Fatalf("testdata: %v", err)
	}
}
-- a/foo/bar/c/main.go --
package c
import _ "a/foo/bar/b"
-- a/foo/bar/c/main_test.go --
package c

import (
	"os"
	"testing"
)

func TestDir(t *testing.T) {
	if _, err := os.Stat("../../../testdata/1"); err != nil {
		t.Fatalf("testdata: %v", err)
	}
	if _, err := os.Stat("./testdata/1"); err != nil {
		t.Fatalf("testdata: %v", err)
	}
}
-- a/foo/bar/c/testdata/1 --
-- a/foo/bar/testdata/1 --
-- a/go.mod --
module a
-- a/main.go --
package a
-- a/main_test.go --
package a

import (
	"os"
	"testing"
)

func TestDir(t *testing.T) {
	if _, err := os.Stat("./testdata/1"); err != nil {
		t.Fatalf("testdata: %v", err)
	}
}
-- a/testdata/1 --
-- appengine.go --
// +build appengine

package m

import _ "appengine"
import _ "appengine/datastore"
-- mypkg/go.mod --
module me
-- mypkg/mydir/d.go --
package mydir
-- subdir/v1_test.go --
package m

import _ "mysite/myname/mypkg/mydir"
-- testdata1.go --
package m

import _ "a"
-- testdata2.go --
package m

import _ "a/foo/bar/c"
-- v1.go --
package m

import _ "x"
-- v2.go --
// +build abc

package mMmMmMm

import _ "y"
-- v3.go --
// +build !abc

package m

import _ "z"
-- v4.go --
// +build notmytag

package m

import _ "x/x1"
-- importdiamond.go --
package m

import _ "diamondroot"
-- w/go.mod --
module w
-- w/w.go --
package w
-- x/go.mod --
module x
-- x/testdata/x.txt --
placeholder - want directory with no go files
-- x/x.go --
package x
-- x/x1/x1.go --
// +build notmytag

package x1
-- x/x2/dummy.txt --
dummy
-- x/x_test.go --
package x

import _ "w"
-- y/go.mod --
module y
-- y/y.go --
package y
-- z/go.mod --
module z
-- z/z.go --
package z

-- diamondroot/go.mod --
module diamondroot

require (
	diamondleft v0.0.0
	diamondright v0.0.0
)
-- diamondroot/x.go --
package diamondroot

import _ "diamondleft"
-- diamondroot/unused/unused.go --
package unused

import _ "diamondright"
-- diamondleft/go.mod --
module diamondleft

require (
	diamondpoint v0.0.0
)
-- diamondleft/x.go --
package diamondleft

import _ "diamondpoint"
-- diamondright/go.mod --
module diamondright

require (
	diamondpoint v0.0.0
)
-- diamondright/x.go --
package diamondright

import _ "diamondpoint"
-- diamondpoint/go.mod --
module diamondpoint
-- diamondpoint/x.go --
package diamondpoint