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/a -> example.com/b v1.0.0 -> example.com/q v1.1.0
9 # example.com/p -> example.com/q v1.0.0
10 #
11 # If we didn't load the whole graph and didn't load the dependencies of b
12 # when loading p, we would end up loading q v1.0.0, rather than v1.1.0,
13 # which is selected by MVS.
14 # TODO(#48331): We currently load the wrong version of q. Fix this.
15
16 go list -m -f '{{.Version}}' example.com/q
17 stdout '^v1.1.0$'
18
19 -- go.work --
20 go 1.18
21
22 use (
23 ./a
24 ./p
25 )
26 -- a/go.mod --
27 module example.com/a
28
29 go 1.18
30
31 require example.com/b v1.0.0
32
33 replace example.com/b v1.0.0 => ../b
34 -- a/foo.go --
35 package main
36
37 import "example.com/b"
38
39 func main() {
40 b.B()
41 }
42 -- b/go.mod --
43 module example.com/b
44
45 go 1.18
46
47 require example.com/q v1.1.0
48
49 replace example.com/q v1.0.0 => ../q1_0_0
50 replace example.com/q v1.1.0 => ../q1_1_0
51 -- b/b.go --
52 package b
53
54 func B() {
55 }
56 -- b/b_test.go --
57 package b
58
59 import "example.com/q"
60
61 func TestB() {
62 q.PrintVersion()
63 }
64 -- p/go.mod --
65 module example.com/p
66
67 go 1.18
68
69 require example.com/q v1.0.0
70
71 replace example.com/q v1.0.0 => ../q1_0_0
72 replace example.com/q v1.1.0 => ../q1_1_0
73 -- p/main.go --
74 package main
75
76 import "example.com/q"
77
78 func main() {
79 q.PrintVersion()
80 }
81 -- q1_0_0/go.mod --
82 module example.com/q
83
84 go 1.18
85 -- q1_0_0/q.go --
86 package q
87
88 import "fmt"
89
90 func PrintVersion() {
91 fmt.Println("version 1.0.0")
92 }
93 -- q1_1_0/go.mod --
94 module example.com/q
95
96 go 1.18
97 -- q1_1_0/q.go --
98 package q
99
100 import "fmt"
101
102 func PrintVersion() {
103 fmt.Println("version 1.1.0")
104 }
105
View as plain text