aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/testdata/script/mod_lazy_import_allmod.txt
blob: 4ad8cbf8ee2de35a915c707f325708560f7241ff (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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# This test demonstrates dependency resolution when the main module imports a
# new package from a previously-test-only dependency.
#
# When lazy loading is active, the loader will not load dependencies of any
# module whose packages are *only* imported by tests outside the main module. If
# the main module is changed to import a package from such a module, the
# dependencies of that module will need to be reloaded.

# The import graph used in this test looks like:
#
# m ---- a
#  \     |
#   \    a_test ---- b/x
#    \
#      --------------b/y (new) ---- c
#
# Where b/x and b/y are disjoint packages, but both contained in module b.
#
# The module dependency graph initially looks like:
#
# m ---- a.1 ---- b.1 ---- c.1
#
# This configuration is similar to that used in mod_lazy_new_import,
# but the new import is from what is initially a test-only dependency.

# Control case: in Go 1.14, the original go.mod is tidy,
# and the dependency on c is eagerly loaded.

cp go.mod go.mod.orig
go mod tidy
cmp go.mod.orig go.mod

go list -m all
stdout '^a v0.1.0 '
stdout '^b v0.1.0 '
stdout '^c v0.1.0 '

# After adding a new import of b/y,
# the import of c from b/y should resolve to the version required by b.

cp m.go m.go.orig
cp m.go.new m.go
go mod tidy
cmp go.mod.new go.mod

go list -m all
stdout '^a v0.1.0 '
stdout '^b v0.1.0 '
stdout '^c v0.1.0 '

# With lazy loading, the go.mod requirements are the same,
# but the dependency on c is initially pruned out.

cp m.go.orig m.go
cp go.mod.orig go.mod
go mod edit -go=1.16
go mod edit -go=1.16 go.mod.new

cp go.mod go.mod.orig
go mod tidy
cmp go.mod.orig go.mod

go list -m all
stdout '^a v0.1.0 '
stdout '^b v0.1.0 '
stdout '^c v0.1.0 '  # TODO(#36460): This should be pruned out.

# After adding a new import of b/y,
# the import of c from b/y should again resolve to the version required by b.

cp m.go.new m.go
go mod tidy
cmp go.mod.new go.mod

go list -m all
stdout '^a v0.1.0 '
stdout '^b v0.1.0 '
stdout '^c v0.1.0 '

-- m.go --
package main

import (
	"fmt"

	_ "a"  // a_test imports b/x.
)

func main() {
}
-- m.go.new --
package main

import (
	"fmt"

	_ "a"  // a_test imports b/x.
	"b/y"  // This is a new import, not yet reflected in the go.mod file.
)

func main() {
	fmt.Println(b.CVersion())
}
-- go.mod --
module m

go 1.14

require a v0.1.0

replace (
	a v0.1.0 => ./a1
	b v0.1.0 => ./b1
	c v0.1.0 => ./c1
	c v0.2.0 => ./c2
)
-- go.mod.new --
module m

go 1.14

require (
	a v0.1.0
	b v0.1.0
)

replace (
	a v0.1.0 => ./a1
	b v0.1.0 => ./b1
	c v0.1.0 => ./c1
	c v0.2.0 => ./c2
)
-- a1/go.mod --
module a

go 1.16

require b v0.1.0
-- a1/a.go --
package a
-- a1/a_test.go --
package a_test

import _ "b/x"
-- b1/go.mod --
module b

go 1.16

require c v0.1.0
-- b1/x/x.go --
package x
-- b1/y/y.go --
package y

import "c"

func CVersion() string {
	return c.Version
}
-- c1/go.mod --
module c

go 1.16
-- c1/c.go --
package c

const Version = "v0.1.0"
-- c2/go.mod --
This file should be unused.
-- c2/c.go --
This file should be unused.