1 # This test illustrates the use of a deepening scan to resolve transitive
2 # imports of imports of new packages from within existing dependencies.
3
4 # The package import graph used in this test looks like:
5 #
6 # lazy ---- a/x ---- b
7 # \
8 # ---- a/y (new) ---- c
9 #
10 # Where a/x and a/y are disjoint packages, but both contained in module a.
11 #
12 # The module dependency graph initially looks like:
13 #
14 # lazy ---- a.1 ---- b.1
15 # \
16 # c.1
17
18
19 cp go.mod go.mod.old
20 cp lazy.go lazy.go.old
21 go mod tidy
22 cmp go.mod go.mod.old
23
24 # Before adding a new import, the go.mod file should
25 # enumerate modules for all packages already imported.
26 go list all
27 cmp go.mod go.mod.old
28
29 # When we add a new import of a package in an existing dependency,
30 # and that dependency is already tidy, its transitive dependencies
31 # should already be present.
32 cp lazy.go.new lazy.go
33 go list all
34 go list -m all
35 stdout '^example.com/c v0.1.0' # not v0.2.0 as would be resolved by 'latest'
36 cmp go.mod go.mod.old
37
38 # Now, we repeat the test with a lazy main module.
39 cp lazy.go.old lazy.go
40 cp go.mod.117 go.mod
41
42 # Before adding a new import, the go.mod file should
43 # enumerate modules for all packages already imported.
44 go list all
45 cmp go.mod go.mod.117
46
47 # When a new import is found, we should perform a deepening scan of the existing
48 # dependencies and add a requirement on the version required by those
49 # dependencies — not re-resolve 'latest'.
50 cp lazy.go.new lazy.go
51
52 ! go list all
53 stderr '^go: updates to go.mod needed; to update it:\n\tgo mod tidy$'
54
55 go mod tidy
56 go list all
57 go list -m all
58 stdout '^example.com/c v0.1.0' # not v0.2.0 as would be resolved by 'latest'
59
60 cmp go.mod go.mod.new
61
62
63 -- go.mod --
64 module example.com/lazy
65
66 go 1.15
67
68 require example.com/a v0.1.0
69
70 replace (
71 example.com/a v0.1.0 => ./a
72 example.com/b v0.1.0 => ./b
73 example.com/c v0.1.0 => ./c1
74 example.com/c v0.2.0 => ./c2
75 )
76 -- go.mod.117 --
77 module example.com/lazy
78
79 go 1.17
80
81 require example.com/a v0.1.0
82
83 require example.com/b v0.1.0 // indirect
84
85 replace (
86 example.com/a v0.1.0 => ./a
87 example.com/b v0.1.0 => ./b
88 example.com/c v0.1.0 => ./c1
89 example.com/c v0.2.0 => ./c2
90 )
91 -- go.mod.new --
92 module example.com/lazy
93
94 go 1.17
95
96 require example.com/a v0.1.0
97
98 require (
99 example.com/b v0.1.0 // indirect
100 example.com/c v0.1.0 // indirect
101 )
102
103 replace (
104 example.com/a v0.1.0 => ./a
105 example.com/b v0.1.0 => ./b
106 example.com/c v0.1.0 => ./c1
107 example.com/c v0.2.0 => ./c2
108 )
109 -- lazy.go --
110 package lazy
111
112 import (
113 _ "example.com/a/x"
114 )
115 -- lazy.go.new --
116 package lazy
117
118 import (
119 _ "example.com/a/x"
120 _ "example.com/a/y"
121 )
122 -- a/go.mod --
123 module example.com/a
124
125 go 1.15
126
127 require (
128 example.com/b v0.1.0
129 example.com/c v0.1.0
130 )
131 -- a/x/x.go --
132 package x
133 import _ "example.com/b"
134 -- a/y/y.go --
135 package y
136 import _ "example.com/c"
137 -- b/go.mod --
138 module example.com/b
139
140 go 1.15
141 -- b/b.go --
142 package b
143 -- c1/go.mod --
144 module example.com/c
145
146 go 1.15
147 -- c1/c.go --
148 package c
149 -- c2/go.mod --
150 module example.com/c
151
152 go 1.15
153 -- c2/c.go --
154 package c
155 This file should not be used, so this syntax error should be ignored.
156
View as plain text