...
1# This test illustrates a case where an upgrade–downgrade–upgrade cycle can
2# result in upgrades of otherwise-irrelevant dependencies.
3#
4# This case has no corresponding test in the mvs package, because it is an
5# artifact that results from the composition of *multiple* MVS operations.
6
7# The initial package import graph used in the test looks like:
8#
9# m ---- a
10# | |
11# +----- b
12# | |
13# +----- c
14# |
15# +----- d
16#
17# b version 2 adds its own import of package d.
18#
19# The module dependency graph initially looks like:
20#
21# m ---- a.1
22# | |
23# +----- b.1
24# | |
25# +----- c.1
26# |
27# +----- d.1
28#
29# b.2 ---- c.2
30# |
31# +------ d.2
32# |
33# +------ e.1
34#
35# If we upgrade module b to version 2, we will upgrade c and d and add a new
36# dependency on e. If b version 2 is disallowed because of any of those
37# dependencies, the other dependencies should not be upgraded as a side-effect.
38
39cp go.mod go.mod.orig
40go mod tidy
41cmp go.mod go.mod.orig
42
43go list -m all
44stdout '^example.com/a v0.1.0 '
45stdout '^example.com/b v0.1.0 '
46stdout '^example.com/c v0.1.0 '
47stdout '^example.com/d v0.1.0 '
48! stdout '^example.com/e '
49
50# b is imported by a, so the -u flag would normally upgrade it to v0.2.0.
51# However, that would conflict with the explicit c@v0.1.0 constraint,
52# so b must remain at v0.1.0.
53#
54# If we're not careful, we might temporarily add b@v0.2.0 and pull in its
55# upgrades of module d and addition of module e, which are not relevant to
56# b@v0.1.0 and should not be added to the main module's dependencies.
57
58go get -u example.com/a@latest example.com/c@v0.1.0
59
60go list -m all
61stdout '^example.com/a v0.1.0 '
62stdout '^example.com/b v0.1.0 '
63stdout '^example.com/c v0.1.0 '
64stdout '^example.com/d v0.1.0 '
65! stdout '^example.com/e '
66
67-- go.mod --
68module example.com/m
69
70go 1.16
71
72require (
73 example.com/a v0.1.0
74 example.com/b v0.1.0
75 example.com/c v0.1.0
76 example.com/d v0.1.0
77)
78
79replace (
80 example.com/a v0.1.0 => ./a1
81 example.com/b v0.1.0 => ./b1
82 example.com/b v0.2.0 => ./b2
83 example.com/c v0.1.0 => ./c
84 example.com/c v0.2.0 => ./c
85 example.com/d v0.1.0 => ./d
86 example.com/d v0.2.0 => ./d
87 example.com/e v0.1.0 => ./e
88)
89-- m.go --
90package m
91
92import (
93 _ "example.com/a"
94 _ "example.com/b"
95 _ "example.com/c"
96 _ "example.com/d"
97)
98
99-- a1/go.mod --
100module example.com/a
101
102go 1.16
103
104require example.com/b v0.1.0
105-- a1/a.go --
106package a
107
108import _ "example.com/b"
109
110-- b1/go.mod --
111module example.com/b
112
113go 1.16
114
115require example.com/c v0.1.0
116-- b1/b.go --
117package b
118
119import _ "example.com/c"
120
121-- b2/go.mod --
122module example.com/b
123
124go 1.16
125
126require (
127 example.com/c v0.2.0
128 example.com/d v0.2.0
129 example.com/e v0.1.0
130)
131-- b2/b.go --
132package b
133
134import (
135 "example.com/c"
136 "example.com/d"
137 "example.com/e"
138)
139
140-- c/go.mod --
141module example.com/c
142
143go 1.16
144-- c/c.go --
145package c
146
147-- d/go.mod --
148module example.com/d
149
150go 1.16
151-- d/d.go --
152package d
153
154-- e/go.mod --
155module example.com/e
156
157go 1.16
158-- e/e.go --
159package e
View as plain text