...
1# This test makes sure workspace mode's handling of the module graph
2# is compatible with module pruning. The graph we load from either of
3# the workspace modules should be the same, even if their graphs
4# don't overlap.
5#
6# This is the module graph in the test:
7#
8# example.com/p -> example.com/q v1.0.0
9# example.com/a -> example.com/b v1.0.0 -> example.com/q v1.1.0 -> example.com/w v1.0.0 -> example.com/x v1.0.0 -> example.com/y v1.0.0
10# |-> example.com/z v1.0.0 |-> example.com/z v1.1.0
11# |-> example.com/q v1.0.5 -> example.com/r v1.0.0
12# If we didn't load the whole graph and didn't load the dependencies of b
13# when loading p, we would end up loading q v1.0.0, rather than v1.1.0,
14# which is selected by MVS.
15
16go list -m all
17stdout 'example.com/w v1.0.0'
18stdout 'example.com/q v1.1.0'
19stdout 'example.com/z v1.1.0'
20stdout 'example.com/x v1.0.0'
21! stdout 'example.com/r'
22! stdout 'example.com/y'
23
24-- go.work --
25go 1.18
26
27use (
28 ./a
29 ./p
30)
31
32replace example.com/b v1.0.0 => ./b
33replace example.com/q v1.0.0 => ./q1_0_0
34replace example.com/q v1.0.5 => ./q1_0_5
35replace example.com/q v1.1.0 => ./q1_1_0
36replace example.com/r v1.0.0 => ./r
37replace example.com/w v1.0.0 => ./w
38replace example.com/x v1.0.0 => ./x
39replace example.com/y v1.0.0 => ./y
40replace example.com/z v1.0.0 => ./z1_0_0
41replace example.com/z v1.1.0 => ./z1_1_0
42
43-- a/go.mod --
44module example.com/a
45
46go 1.18
47
48require example.com/b v1.0.0
49require example.com/z v1.0.0
50-- a/foo.go --
51package main
52
53import "example.com/b"
54
55func main() {
56 b.B()
57}
58-- b/go.mod --
59module example.com/b
60
61go 1.18
62
63require example.com/q v1.1.0
64-- b/b.go --
65package b
66
67func B() {
68}
69-- p/go.mod --
70module example.com/p
71
72go 1.18
73
74require example.com/q v1.0.0
75
76replace example.com/q v1.0.0 => ../q1_0_0
77replace example.com/q v1.1.0 => ../q1_1_0
78-- p/main.go --
79package main
80
81import "example.com/q"
82
83func main() {
84 q.PrintVersion()
85}
86-- q1_0_0/go.mod --
87module example.com/q
88
89go 1.18
90-- q1_0_0/q.go --
91package q
92
93import "fmt"
94
95func PrintVersion() {
96 fmt.Println("version 1.0.0")
97}
98-- q1_0_5/go.mod --
99module example.com/q
100
101go 1.18
102
103require example.com/r v1.0.0
104-- q1_0_5/q.go --
105package q
106
107import _ "example.com/r"
108-- q1_1_0/go.mod --
109module example.com/q
110
111require example.com/w v1.0.0
112require example.com/z v1.1.0
113
114go 1.18
115-- q1_1_0/q.go --
116package q
117
118import _ "example.com/w"
119import _ "example.com/z"
120
121import "fmt"
122
123func PrintVersion() {
124 fmt.Println("version 1.1.0")
125}
126-- r/go.mod --
127module example.com/r
128
129go 1.18
130
131require example.com/r v1.0.0
132-- r/r.go --
133package r
134-- w/go.mod --
135module example.com/w
136
137go 1.18
138
139require example.com/x v1.0.0
140-- w/w.go --
141package w
142-- w/w_test.go --
143package w
144
145import _ "example.com/x"
146-- x/go.mod --
147module example.com/x
148
149go 1.18
150-- x/x.go --
151package x
152-- x/x_test.go --
153package x
154import _ "example.com/y"
155-- y/go.mod --
156module example.com/y
157
158go 1.18
159-- y/y.go --
160package y
161-- z1_0_0/go.mod --
162module example.com/z
163
164go 1.18
165
166require example.com/q v1.0.5
167-- z1_0_0/z.go --
168package z
169
170import _ "example.com/q"
171-- z1_1_0/go.mod --
172module example.com/z
173
174go 1.18
175-- z1_1_0/z.go --
176package z
View as plain text