1 env GO111MODULE=on
2
3 # 'go list' should not add requirements even if they can be resolved locally.
4 cp go.mod go.mod.orig
5 ! go list all
6 cmp go.mod go.mod.orig
7
8 # 'go list' should resolve imports using replacements.
9 go get
10 go list all
11 stdout 'example.com/a/b$'
12 stdout 'example.com/x/v3$'
13 stdout 'example.com/y/z/w$'
14 stdout 'example.com/v'
15
16 # The selected modules should prefer longer paths,
17 # but should try shorter paths if needed.
18 # Modules with a major-version suffix should have a corresponding pseudo-version.
19 # Replacements that specify a version should use the latest such version.
20 go list -m all
21 stdout 'example.com/a/b v0.0.0-00010101000000-000000000000 => ./b'
22 stdout 'example.com/y v0.0.0-00010101000000-000000000000 => ./y'
23 stdout 'example.com/x/v3 v3.0.0-00010101000000-000000000000 => ./v3'
24 stdout 'example.com/v v1.12.0 => ./v12'
25
26 # The go command should print an informative error when the matched
27 # module does not contain a package.
28 # TODO(#26909): Ideally these errors should include line numbers for the imports within the main module.
29 cd fail
30 ! go mod tidy
31 stderr '^localhost.fail imports\n\tw: module w@latest found \(v0.0.0-00010101000000-000000000000, replaced by ../w\), but does not contain package w$'
32 stderr '^localhost.fail imports\n\tnonexist: nonexist@v0.1.0: replacement directory ../nonexist does not exist$'
33
34 -- go.mod --
35 module example.com/m
36
37 replace (
38 example.com/a => ./a
39 example.com/a/b => ./b
40 )
41
42 replace (
43 example.com/x => ./x
44 example.com/x/v3 => ./v3
45 )
46
47 replace (
48 example.com/y/z/w => ./w
49 example.com/y => ./y
50 )
51
52 replace (
53 example.com/v v1.11.0 => ./v11
54 example.com/v v1.12.0 => ./v12
55 example.com/v => ./v
56 )
57
58 replace (
59 example.com/i v2.0.0+incompatible => ./i2
60 )
61
62 -- m.go --
63 package main
64 import (
65 _ "example.com/a/b"
66 _ "example.com/x/v3"
67 _ "example.com/y/z/w"
68 _ "example.com/v"
69 _ "example.com/i"
70 )
71 func main() {}
72
73 -- a/go.mod --
74 module a.localhost
75 -- a/a.go --
76 package a
77 -- a/b/b.go--
78 package b
79
80 -- b/go.mod --
81 module a.localhost/b
82 -- b/b.go --
83 package b
84
85 -- x/go.mod --
86 module x.localhost
87 -- x/x.go --
88 package x
89 -- x/v3.go --
90 package v3
91 import _ "x.localhost/v3"
92
93 -- v3/go.mod --
94 module x.localhost/v3
95 -- v3/x.go --
96 package x
97
98 -- w/go.mod --
99 module w.localhost
100 -- w/skip/skip.go --
101 // Package skip is nested below nonexistent package w.
102 package skip
103
104 -- y/go.mod --
105 module y.localhost
106 -- y/z/w/w.go --
107 package w
108
109 -- v12/go.mod --
110 module v.localhost
111 -- v12/v.go --
112 package v
113
114 -- v11/go.mod --
115 module v.localhost
116 -- v11/v.go --
117 package v
118
119 -- v/go.mod --
120 module v.localhost
121 -- v/v.go --
122 package v
123
124 -- i2/go.mod --
125 module example.com/i
126 -- i2/i.go --
127 package i
128
129 -- fail/m.go --
130 package main
131
132 import (
133 _ "w"
134 _ "nonexist"
135 )
136
137 func main() {}
138
139 -- fail/go.mod --
140 module localhost.fail
141
142 replace w => ../w
143
144 replace nonexist v0.1.0 => ../nonexist
145
View as plain text