Skip to content

Commit c47ba5f

Browse files
author
Bryan C. Mills
committed
cmd/go: test the behavior of 'go get' in module mode with package vs. module arguments
Updates #37438 Change-Id: I5beb380b37532571768a92bea50003f6ff1757e1 Reviewed-on: https://go-review.googlesource.com/c/go/+/255054 Trust: Bryan C. Mills <[email protected]> Run-TryBot: Bryan C. Mills <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Michael Matloob <[email protected]> Reviewed-by: Jay Conrod <[email protected]>
1 parent 06f7e65 commit c47ba5f

File tree

1 file changed

+124
-0
lines changed

1 file changed

+124
-0
lines changed
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
go mod tidy
2+
cp go.mod go.mod.orig
3+
4+
# If there is no sensible *package* meaning for 'm/p', perhaps it should refer
5+
# to *module* m/p?
6+
# Today, it still seems to refer to the package.
7+
8+
! go get -d m/[email protected]
9+
stderr 'go get m/[email protected]: module m/p@latest found \(v0.1.0, replaced by ./mp01\), but does not contain package m/p'
10+
cmp go.mod.orig go.mod
11+
12+
13+
# TODO(#37438): If we add v0.2.0 before this point, we end up (somehow!)
14+
# resolving m/[email protected] as *both* a module and a package.
15+
16+
cp go.mod.orig go.mod
17+
go mod edit [email protected]=./m02
18+
go mod edit -replace=m/[email protected]=./mp02
19+
20+
# The argument 'm/p' in 'go get m/p' refers to *package* m/p,
21+
# which is in module m.
22+
#
23+
# (It only refers to *module* m/p if there is no such package at the
24+
# requested version.)
25+
26+
go get -d m/[email protected]
27+
go list -m all
28+
stdout '^m v0.2.0 '
29+
stdout '^m/p v0.1.0 '
30+
31+
# Repeating the above with module m/p already in the module graph does not
32+
# change its meaning.
33+
34+
go get -d m/[email protected]
35+
go list -m all
36+
stdout '^m v0.2.0 '
37+
stdout '^m/p v0.1.0 '
38+
39+
40+
# TODO(#37438): If we add v0.3.0 before this point, we get a totally bogus error
41+
# today, because 'go get' ends up attempting to resolve package 'm/p' without a
42+
# specific version and can't find it if module m no longer contains v0.3.0.
43+
44+
cp go.mod.orig go.mod
45+
go mod edit [email protected]=./m03
46+
go mod edit -replace=m/[email protected]=./mp03
47+
48+
! go get -d m/[email protected]
49+
stderr 'go get m/[email protected]: module m/p@latest found \(v0.3.0, replaced by ./mp03\), but does not contain package m/p$'
50+
51+
# If there is no sensible package meaning for 'm/p', perhaps it should refer
52+
# to *module* m/p?
53+
# Today, it still seems to refer to the package.
54+
55+
! go get -d m/[email protected]
56+
stderr '^go get m/[email protected]: module m/p@latest found \(v0\.3\.0, replaced by \./mp03\), but does not contain package m/p$'
57+
58+
59+
-- go.mod --
60+
module example.com
61+
62+
go 1.16
63+
64+
replace (
65+
m v0.1.0 => ./m01
66+
m/p v0.1.0 => ./mp01
67+
)
68+
-- m01/go.mod --
69+
module m
70+
71+
go 1.16
72+
-- m01/README.txt --
73+
Module m at v0.3.0 does not yet contain package p.
74+
75+
-- m02/go.mod --
76+
module m
77+
78+
go 1.16
79+
80+
require m/p v0.1.0
81+
-- m02/p/p.go --
82+
// Package p is present in module m, but not module m/p.
83+
package p
84+
85+
-- m03/go.mod --
86+
module m
87+
88+
go 1.16
89+
90+
require m/p v0.1.0
91+
-- m03/README.txt --
92+
Module m at v0.3.0 no longer contains package p.
93+
94+
-- mv2/go.mod --
95+
module m/v2
96+
97+
go 1.16
98+
-- mv2/README.txt --
99+
This module is m/v2. It doesn't actually need to exist,
100+
but it explains how module m could plausibly exist
101+
and still contain package p at 'latest' even when module
102+
m/p also exists.
103+
104+
-- mp01/go.mod --
105+
module m/p
106+
107+
go 1.16
108+
-- mp01/README.txt --
109+
This module is m/p.
110+
Package m/p no longer exists.
111+
-- mp02/go.mod --
112+
module m/p
113+
114+
go 1.16
115+
-- mp02/README.txt --
116+
This module is m/p.
117+
Package m/p no longer exists.
118+
-- mp03/go.mod --
119+
module m/p
120+
121+
go 1.16
122+
-- mp03/README.txt --
123+
This module is m/p.
124+
Package m/p no longer exists.

0 commit comments

Comments
 (0)