...
1cp go.mod go.mod.orig
2
3env oldGOPROXY=$GOPROXY
4
5# If a wildcard replacement exists for an otherwise-nonexistent module,
6# 'go get' should resolve it to the minimum valid pseudo-version.
7
8go mod edit -replace=example.com/x=./x
9go get example.com/x
10
11go list -m example.com/x
12stdout '^example.com/x v0.0.0-00010101000000-000000000000 '
13
14# If specific-version replacements exist, the highest matching version should be used.
15go mod edit -replace=example.com/x@v0.1.0=./x
16go mod edit -replace=example.com/x@v0.2.0=./x
17
18go get example.com/x
19go list -m example.com/x
20stdout '^example.com/x v0.2.0 '
21
22go get example.com/x@<v0.2.0
23go list -m example.com/x
24stdout '^example.com/x v0.1.0 '
25
26
27# The same should work with GOPROXY=off.
28
29env GOPROXY=off
30cp go.mod.orig go.mod
31
32go mod edit -replace=example.com/x=./x
33go get example.com/x
34
35go list -m example.com/x
36stdout '^example.com/x v0.0.0-00010101000000-000000000000 '
37
38# If specific-version replacements exist, the highest matching version should be used.
39go mod edit -replace=example.com/x@v0.1.0=./x
40go mod edit -replace=example.com/x@v0.2.0=./x
41
42go get example.com/x
43go list -m example.com/x
44stdout '^example.com/x v0.2.0 '
45
46go get example.com/x@<v0.2.0
47go list -m example.com/x
48stdout '^example.com/x v0.1.0 '
49
50
51# Replacements should also be listed as known versions, and 'go get' should sort
52# them in with ordinary versions.
53
54env GOPROXY=$oldGOPROXY
55
56cp go.mod.orig go.mod
57go list -versions -m rsc.io/quote
58stdout 'v1.3.0 v1.4.0'
59
60go get rsc.io/quote@v1.3
61go list -m rsc.io/quote
62stdout '^rsc.io/quote v1.3.0'
63
64go mod edit -replace rsc.io/quote@v1.3.1=rsc.io/quote@v1.4.0
65
66go list -versions -m rsc.io/quote
67stdout 'v1.3.0 v1.3.1 v1.4.0'
68
69go get rsc.io/quote@v1.3
70go list -m rsc.io/quote
71stdout '^rsc.io/quote v1.3.1 '
72
73go get rsc.io/quote@>v1.3.1
74go list -m rsc.io/quote
75stdout '^rsc.io/quote v1.4.0'
76
77
78# Replacements should allow 'go get' to work even with dotless module paths.
79
80cp go.mod.orig go.mod
81
82! go list example
83stderr '^package example is not in std \(.*\)$'
84! go get example
85stderr '^go: malformed module path "example": missing dot in first path element$'
86
87go mod edit -replace example@v0.1.0=./example
88
89! go list example
90stderr '^module example provides package example and is replaced but not required; to add it:\n\tgo get example@v0.1.0$'
91
92go get example
93go list -m example
94stdout '^example v0.1.0 '
95
96
97-- go.mod --
98module example.com
99
100go 1.16
101-- x/go.mod --
102module example.com/x
103
104go 1.16
105-- x/x.go --
106package x
107-- example/go.mod --
108module example
109go 1.16
110-- example/example.go --
111package example
View as plain text