aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/testdata/script/mod_lazy_test_horizon.txt
blob: 9cdfad79f6a926d0d743668e44dc5322fe758b29 (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
# This file demonstrates the effect of lazy loading on the selected
# versions of test dependencies.

# The package import graph used in this test looks like:
#
# m ---- a
#  \     |
#   \    a_test ---- b
#    \               |
#     x              b_test
#     |                    \
#     x_test -------------- c
#
# And the module dependency graph looks like:
#
# m -- a.1 -- b.1 -- c.2
#  \
#   x.1 ------------ c.1

# Control case: in Go 1.15, the version of c imported by 'go test x' is the
# version required by module b, even though b_test is not relevant to the main
# module. (The main module imports a, and a_test imports b, but all of the
# packages and tests in the main module can be built without b.)

go list -m c
stdout '^c v0.2.0 '

[!short] go test -v x
[!short] stdout ' c v0.2.0$'

# With lazy loading, the go.mod requirements are the same,
# but the irrelevant dependency on c v0.2.0 should be pruned out,
# leaving only the relevant dependency on c v0.1.0.

go mod edit -go=1.16
go list -m c
stdout '^c v0.2.0'  # TODO(#36460): v0.1.0

[!short] go test -v x
[!short] stdout ' c v0.2.0$'  # TODO(#36460): v0.1.0

-- m.go --
package m

import (
	_ "a"
	_ "x"
)
-- go.mod --
module m

go 1.15

require (
	a v0.1.0
	x v0.1.0
)

replace (
	a v0.1.0 => ./a1
	b v0.1.0 => ./b1
	c v0.1.0 => ./c1
	c v0.2.0 => ./c2
	x v0.1.0 => ./x1
)
-- 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"
-- b1/go.mod --
module b

go 1.16

require c v0.2.0
-- b1/b.go --
package b
-- b1/b_test.go --
package b_test

import (
	"c"
	"testing"
)

func TestCVersion(t *testing.T) {
	t.Log(c.Version)
}
-- c1/go.mod --
module c

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

const Version = "v0.1.0"
-- c2/go.mod --
module c

go 1.16
-- c2/c.go --
package c

const Version = "v0.2.0"
-- x1/go.mod --
module x

go 1.16

require c v0.1.0
-- x1/x.go --
package x
-- x1/x_test.go --
package x_test

import (
	"c"
	"testing"
)

func TestCVersion(t *testing.T) {
	t.Log("c", c.Version)
}