Skip to content

Commit bb9b319

Browse files
author
Bryan C. Mills
committed
cmd/go: add yet another test case for ambiguous arguments to 'go get'
For #37438 Change-Id: Ie40971ff677d36ddadbf9834bba2d366a0fc34d0 Reviewed-on: https://go-review.googlesource.com/c/go/+/256922 Trust: Bryan C. Mills <[email protected]> Trust: Jay Conrod <[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 1eeaff7 commit bb9b319

5 files changed

+161
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Written by hand.
2+
3+
Test module containing a package that is also provided by a nested module tagged
4+
with the same version.
5+
6+
-- .mod --
7+
module example.net/ambiguous/nested
8+
9+
go 1.16
10+
-- .info --
11+
{"Version": "v0.1.0"}
12+
-- go.mod --
13+
module example.net/ambiguous/nested
14+
15+
go 1.16
16+
-- pkg/pkg.go --
17+
// Package pkg exists in both example.net/ambiguous v0.1.0
18+
// and example.net/ambiguous/nested v0.1.0
19+
package pkg
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Written by hand.
2+
3+
Test module containing a package that is also provided by a nested module tagged
4+
with the same version.
5+
6+
-- .mod --
7+
module example.net/ambiguous
8+
9+
go 1.16
10+
-- .info --
11+
{"Version": "v0.1.0"}
12+
-- go.mod --
13+
module example.net/ambiguous
14+
15+
go 1.16
16+
-- nested/pkg/pkg.go --
17+
// Package pkg exists in both example.net/ambiguous v0.1.0
18+
// and example.net/ambiguous/nested v0.1.0
19+
package pkg
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Written by hand.
2+
3+
Test module containing a package that is also provided by a nested module tagged
4+
with the same version.
5+
6+
-- .mod --
7+
module example.net/ambiguous
8+
9+
go 1.16
10+
-- .info --
11+
{"Version": "v0.2.0"}
12+
-- go.mod --
13+
module example.net/ambiguous
14+
15+
go 1.16
16+
-- nested/pkg/README.txt --
17+
// Package pkg no longer exists in this module at v0.2.0.
18+
// Find it in module example.net/ambiguous/nested instead.

src/cmd/go/testdata/script/mod_get_ambiguous_arg.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ module m
7070

7171
go 1.16
7272
-- m01/README.txt --
73-
Module m at v0.3.0 does not yet contain package p.
73+
Module m at v0.1.0 does not yet contain package p.
7474

7575
-- m02/go.mod --
7676
module m
@@ -107,18 +107,18 @@ module m/p
107107
go 1.16
108108
-- mp01/README.txt --
109109
This module is m/p.
110-
Package m/p no longer exists.
110+
Package m/p does not exist in this module.
111111
-- mp02/go.mod --
112112
module m/p
113113

114114
go 1.16
115115
-- mp02/README.txt --
116116
This module is m/p.
117-
Package m/p no longer exists.
117+
Package m/p does not exist in this module.
118118
-- mp03/go.mod --
119119
module m/p
120120

121121
go 1.16
122122
-- mp03/README.txt --
123123
This module is m/p.
124-
Package m/p no longer exists.
124+
Package m/p does not exist in this module.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# Both example.net/ambiguous v0.1.0 and example.net/ambiguous/pkg v0.1.0 exist.
2+
# 'go mod tidy' would arbitrarily choose the one with the longer path,
3+
# but 'go mod tidy' also arbitrarily chooses the latest version.
4+
5+
cp go.mod go.mod.orig
6+
7+
8+
# From a clean slate, 'go get' currently does the same thing as 'go mod tidy':
9+
# it resolves the package from the module with the longest matching prefix.
10+
11+
go get -d example.net/ambiguous/nested/[email protected]
12+
go list -m all
13+
stdout '^example.net/ambiguous/nested v0.1.0$'
14+
! stdout '^example.net/ambiguous '
15+
16+
17+
# From an initial state that already depends on the shorter path,
18+
# the same 'go get' command attempts to add the longer path and fails.
19+
#
20+
# TODO(bcmills): What should really happen here?
21+
# Should we match the versioned package path against the existing package
22+
# (reducing unexpected errors), or give it the same meaning regardless of the
23+
# initial state?
24+
25+
cp go.mod.orig go.mod
26+
go mod edit -require=example.net/[email protected]
27+
28+
! go get -d example.net/ambiguous/nested/[email protected]
29+
stderr '^go get example.net/ambiguous/nested/[email protected]: ambiguous import: found package example.net/ambiguous/nested/pkg in multiple modules:\n\texample.net/ambiguous v0.1.0 \(.*\)\n\texample.net/ambiguous/nested v0.1.0 \(.*\)\n\z'
30+
31+
32+
# The user should be able to fix the aforementioned failure by explicitly
33+
# upgrading the conflicting module.
34+
35+
go get -d example.net/[email protected] example.net/ambiguous/nested/[email protected]
36+
go list -m all
37+
stdout '^example.net/ambiguous/nested v0.1.0$'
38+
stdout '^example.net/ambiguous v0.2.0$'
39+
40+
41+
# ...or by explicitly NOT adding the conflicting module.
42+
#
43+
# BUG(#37438): Today, this does not work: explicit module version constraints do
44+
# not affect the package-to-module mapping during package upgrades, so the
45+
# arguments are interpreted as specifying conflicting versions of the longer
46+
# module path.
47+
48+
cp go.mod.orig go.mod
49+
go mod edit -require=example.net/[email protected]
50+
51+
! go get -d example.net/ambiguous/nested/[email protected] example.net/ambiguous/nested@none
52+
stderr '^go get: conflicting versions for module example.net/ambiguous/nested: v0.1.0 and none$'
53+
54+
# go list -m all
55+
# ! stdout '^example.net/ambiguous/nested '
56+
# stdout '^example.net/ambiguous v0.1.0$'
57+
58+
59+
# The user should also be able to fix it by *downgrading* the conflicting module
60+
# away.
61+
#
62+
# BUG(#37438): Today, this does not work: the "ambiguous import" error causes
63+
# 'go get' to fail before applying the requested downgrade.
64+
65+
cp go.mod.orig go.mod
66+
go mod edit -require=example.net/[email protected]
67+
68+
! go get -d example.net/ambiguous@none example.net/ambiguous/nested/[email protected]
69+
stderr '^go get example.net/ambiguous/nested/[email protected]: ambiguous import: found package example.net/ambiguous/nested/pkg in multiple modules:\n\texample.net/ambiguous v0.1.0 \(.*\)\n\texample.net/ambiguous/nested v0.1.0 \(.*\)\n\z'
70+
71+
# go list -m all
72+
# stdout '^example.net/ambiguous/nested v0.1.0$'
73+
# !stdout '^example.net/ambiguous '
74+
75+
76+
# In contrast, if we do the same thing tacking a wildcard pattern ('/...') on
77+
# the end of the package path, we get different behaviors depending on the
78+
# initial state, and no error. (This seems to contradict the “same meaning
79+
# regardless of the initial state” point above, but maybe that's ok?)
80+
81+
cp go.mod.orig go.mod
82+
83+
go get -d example.net/ambiguous/nested/pkg/[email protected]
84+
go list -m all
85+
stdout '^example.net/ambiguous/nested v0.1.0$'
86+
! stdout '^example.net/ambiguous '
87+
88+
89+
cp go.mod.orig go.mod
90+
go mod edit -require=example.net/[email protected]
91+
92+
go get -d example.net/ambiguous/nested/pkg/[email protected]
93+
go list -m all
94+
! stdout '^example.net/ambiguous/nested '
95+
stdout '^example.net/ambiguous v0.1.0$'
96+
97+
98+
-- go.mod --
99+
module test
100+
101+
go 1.16

0 commit comments

Comments
 (0)