1 # This test examines the behavior of 'go get …@patch'
2 # See also mod_upgrade_patch.txt (focused on "-u=patch" specifically)
3 # and mod_get_patchmod.txt (focused on module/package ambiguities).
4
5 cp go.mod go.mod.orig
6
7 # example.net/b@patch refers to the patch for the version of b that was selected
8 # at the start of 'go get', not the version after applying other changes.
9
10 ! go get example.net/a@v0.2.0 example.net/b@patch
11 stderr '^go: example.net/a@v0.2.0 requires example.net/b@v0.2.0, not example.net/b@patch \(v0.1.1\)$'
12 cmp go.mod go.mod.orig
13
14
15 # -u=patch changes the default version for other arguments to '@patch',
16 # but they continue to be resolved against the originally-selected version,
17 # not the updated one.
18 #
19 # TODO(#42360): Reconsider the change in defaults.
20
21 ! go get -u=patch example.net/a@v0.2.0 example.net/b
22 stderr '^go: example.net/a@v0.2.0 requires example.net/b@v0.2.0, not example.net/b@patch \(v0.1.1\)$'
23 cmp go.mod go.mod.orig
24
25
26 # -u=patch refers to the patches for the selected versions of dependencies *after*
27 # applying other version changes, not the versions that were selected at the start.
28 # However, it should not patch versions determined by explicit arguments.
29
30 go get -u=patch example.net/a@v0.2.0
31 go list -m all
32 stdout '^example.net/a v0.2.0 '
33 stdout '^example.net/b v0.2.1 '
34
35
36 # "-u=patch all" should be equivalent to "all@patch", and should fail if the
37 # patched versions result in a higher-than-patch upgrade.
38
39 cp go.mod.orig go.mod
40 ! go get -u=patch all
41 stderr '^go: example.net/a@v0.1.1 \(matching all@patch\) requires example.net/b@v0.2.0, not example.net/b@v0.1.1 \(matching all@patch\)$'
42 cmp go.mod go.mod.orig
43
44
45 # On the other hand, "-u=patch ./..." should patch-upgrade dependencies until
46 # they reach a fixed point, even if that results in higher-than-patch upgrades.
47
48 go get -u=patch ./...
49 go list -m all
50 stdout '^example.net/a v0.1.1 '
51 stdout '^example.net/b v0.2.1 '
52
53
54 -- go.mod --
55 module example
56
57 go 1.16
58
59 require (
60 example.net/a v0.1.0
61 example.net/b v0.1.0 // indirect
62 )
63
64 replace (
65 example.net/a v0.1.0 => ./a10
66 example.net/a v0.1.1 => ./a11
67 example.net/a v0.2.0 => ./a20
68 example.net/a v0.2.1 => ./a21
69 example.net/b v0.1.0 => ./b
70 example.net/b v0.1.1 => ./b
71 example.net/b v0.2.0 => ./b
72 example.net/b v0.2.1 => ./b
73 example.net/b v0.3.0 => ./b
74 example.net/b v0.3.1 => ./b
75 )
76 -- example.go --
77 package example
78
79 import _ "example.net/a"
80
81 -- a10/go.mod --
82 module example.net/a
83
84 go 1.16
85
86 require example.net/b v0.1.0
87 -- a10/a.go --
88 package a
89
90 import _ "example.net/b"
91
92 -- a11/go.mod --
93 module example.net/a
94
95 go 1.16
96
97 require example.net/b v0.2.0 // upgraded
98 -- a11/a.go --
99 package a
100
101 import _ "example.net/b"
102
103 -- a20/go.mod --
104 module example.net/a
105
106 go 1.16
107
108 require example.net/b v0.2.0
109 -- a20/a.go --
110 package a
111
112 import _ "example.net/b"
113
114 -- a21/go.mod --
115 module example.net/a
116
117 go 1.16
118
119 require example.net/b v0.2.0 // not upgraded
120 -- a21/a.go --
121 package a
122
123 import _ "example.net/b"
124
125 -- b/go.mod --
126 module example.net/b
127
128 go 1.16
129 -- b/b.go --
130 package b
131
View as plain text