...
1# This test exercises that vendoring works properly using the workspace in the
2# the work_prune test case.
3
4go work vendor
5cmp vendor/modules.txt modules.txt.want
6cmp vendor/example.com/b/b.go b/b.go
7cmp vendor/example.com/q/q.go q1_1_0/q.go
8go list -m -f '{{.Version}}' example.com/q
9stdout '^v1.1.0$'
10
11go list -f '{{.Dir}}' example.com/q
12stdout $GOPATH[\\/]src[\\/]vendor[\\/]example.com[\\/]q
13go list -f '{{.Dir}}' example.com/b
14stdout $GOPATH[\\/]src[\\/]vendor[\\/]example.com[\\/]b
15
16[short] skip
17
18rm b
19rm q1_0_0
20rm q1_1_0
21go run example.com/p
22stdout 'version 1.1.0'
23
24-- modules.txt.want --
25## workspace
26# example.com/b v1.0.0 => ./b
27## explicit; go 1.18
28example.com/b
29# example.com/q v1.0.0 => ./q1_0_0
30## explicit; go 1.18
31# example.com/q v1.1.0 => ./q1_1_0
32## go 1.18
33example.com/q
34-- go.work --
35go 1.18
36
37use (
38 ./a
39 ./p
40)
41-- a/go.mod --
42module example.com/a
43
44go 1.18
45
46require example.com/b v1.0.0
47
48replace example.com/b v1.0.0 => ../b
49-- a/foo.go --
50package main
51
52import "example.com/b"
53
54func main() {
55 b.B()
56}
57-- b/go.mod --
58module example.com/b
59
60go 1.18
61
62require example.com/q v1.1.0
63-- b/b.go --
64package b
65
66func B() {
67}
68-- b/b_test.go --
69package b
70
71import "example.com/q"
72
73func TestB() {
74 q.PrintVersion()
75}
76-- p/go.mod --
77module example.com/p
78
79go 1.18
80
81require example.com/q v1.0.0
82
83replace example.com/q v1.0.0 => ../q1_0_0
84replace example.com/q v1.1.0 => ../q1_1_0
85-- p/main.go --
86package main
87
88import "example.com/q"
89
90func main() {
91 q.PrintVersion()
92}
93-- q1_0_0/go.mod --
94module example.com/q
95
96go 1.18
97-- q1_0_0/q.go --
98package q
99
100import "fmt"
101
102func PrintVersion() {
103 fmt.Println("version 1.0.0")
104}
105-- q1_1_0/go.mod --
106module example.com/q
107
108go 1.18
109-- q1_1_0/q.go --
110package q
111
112import "fmt"
113
114func PrintVersion() {
115 fmt.Println("version 1.1.0")
116}
View as plain text