aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/testdata/script/mod_lazy_new_import.txt
blob: 86b14b64b6f132cc6701554d3923b905506abba1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# This test illustrates the use of a deepening scan to resolve transitive
# imports of imports of new packages from within existing dependencies.

# The package import graph used in this test looks like:
#
# lazy ---- a/x ---- b
#     \
#      ---- a/y (new) ---- c
#
# Where a/x and x/y are disjoint packages, but both contained in module a.
#
# The module dependency graph initially looks like:
#
# lazy ---- a.1 ---- b.1
#              \
#               c.1


cp go.mod go.mod.old
cp lazy.go lazy.go.old
go mod tidy
cmp go.mod go.mod.old

# Before adding a new import, the go.mod file should
# enumerate modules for all packages already imported.
go list all
cmp go.mod go.mod.old

# When we add a new import of a package in an existing dependency,
# and that dependency is already tidy, its transitive dependencies
# should already be present.
cp lazy.go.new lazy.go
go list all
go list -m all
stdout '^example.com/c v0.1.0' # not v0.2.0 as would be resolved by 'latest'
cmp go.mod go.mod.old

# Now, we repeat the test with a lazy main module.
cp lazy.go.old lazy.go
cp go.mod.117 go.mod

# Before adding a new import, the go.mod file should
# enumerate modules for all packages already imported.
go list all
cmp go.mod go.mod.117

# When a new import is found, we should perform a deepening scan of the existing
# dependencies and add a requirement on the version required by those
# dependencies — not re-resolve 'latest'.
cp lazy.go.new lazy.go

! go list all
stderr '^go: updates to go.mod needed; to update it:\n\tgo mod tidy$'

go mod tidy
go list all
go list -m all
stdout '^example.com/c v0.1.0' # not v0.2.0 as would be resolved by 'latest'

cmp go.mod go.mod.new


-- go.mod --
module example.com/lazy

go 1.15

require example.com/a v0.1.0

replace (
	example.com/a v0.1.0 => ./a
	example.com/b v0.1.0 => ./b
	example.com/c v0.1.0 => ./c1
	example.com/c v0.2.0 => ./c2
)
-- go.mod.117 --
module example.com/lazy

go 1.17

require (
	example.com/a v0.1.0
	example.com/b v0.1.0 // indirect
)

replace (
	example.com/a v0.1.0 => ./a
	example.com/b v0.1.0 => ./b
	example.com/c v0.1.0 => ./c1
	example.com/c v0.2.0 => ./c2
)
-- go.mod.new --
module example.com/lazy

go 1.17

require (
	example.com/a v0.1.0
	example.com/b v0.1.0 // indirect
	example.com/c v0.1.0 // indirect
)

replace (
	example.com/a v0.1.0 => ./a
	example.com/b v0.1.0 => ./b
	example.com/c v0.1.0 => ./c1
	example.com/c v0.2.0 => ./c2
)
-- lazy.go --
package lazy

import (
	_ "example.com/a/x"
)
-- lazy.go.new --
package lazy

import (
	_ "example.com/a/x"
	_ "example.com/a/y"
)
-- a/go.mod --
module example.com/a

go 1.15

require (
	example.com/b v0.1.0
	example.com/c v0.1.0
)
-- a/x/x.go --
package x
import _ "example.com/b"
-- a/y/y.go --
package y
import _ "example.com/c"
-- b/go.mod --
module example.com/b

go 1.15
-- b/b.go --
package b
-- c1/go.mod --
module example.com/c

go 1.15
-- c1/c.go --
package c
-- c2/go.mod --
module example.com/c

go 1.15
-- c2/c.go --
package c
This file should not be used, so this syntax error should be ignored.