...
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
19cp go.mod go.mod.old
20cp lazy.go lazy.go.old
21go mod tidy
22cmp 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.
26go list all
27cmp 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.
32cp lazy.go.new lazy.go
33go list all
34go list -m all
35stdout '^example.com/c v0.1.0' # not v0.2.0 as would be resolved by 'latest'
36cmp go.mod go.mod.old
37
38# Now, we repeat the test with a lazy main module.
39cp lazy.go.old lazy.go
40cp 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.
44go list all
45cmp 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'.
50cp lazy.go.new lazy.go
51
52! go list all
53stderr '^go: updates to go.mod needed; to update it:\n\tgo mod tidy$'
54
55go mod tidy
56go list all
57go list -m all
58stdout '^example.com/c v0.1.0' # not v0.2.0 as would be resolved by 'latest'
59
60cmp go.mod go.mod.new
61
62
63-- go.mod --
64module example.com/lazy
65
66go 1.15
67
68require example.com/a v0.1.0
69
70replace (
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 --
77module example.com/lazy
78
79go 1.17
80
81require example.com/a v0.1.0
82
83require example.com/b v0.1.0 // indirect
84
85replace (
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 --
92module example.com/lazy
93
94go 1.17
95
96require example.com/a v0.1.0
97
98require (
99 example.com/b v0.1.0 // indirect
100 example.com/c v0.1.0 // indirect
101)
102
103replace (
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 --
110package lazy
111
112import (
113 _ "example.com/a/x"
114)
115-- lazy.go.new --
116package lazy
117
118import (
119 _ "example.com/a/x"
120 _ "example.com/a/y"
121)
122-- a/go.mod --
123module example.com/a
124
125go 1.15
126
127require (
128 example.com/b v0.1.0
129 example.com/c v0.1.0
130)
131-- a/x/x.go --
132package x
133import _ "example.com/b"
134-- a/y/y.go --
135package y
136import _ "example.com/c"
137-- b/go.mod --
138module example.com/b
139
140go 1.15
141-- b/b.go --
142package b
143-- c1/go.mod --
144module example.com/c
145
146go 1.15
147-- c1/c.go --
148package c
149-- c2/go.mod --
150module example.com/c
151
152go 1.15
153-- c2/c.go --
154package c
155This file should not be used, so this syntax error should be ignored.
View as plain text