...
1# This file demonstrates the effect of lazy loading on the selected
2# versions of test dependencies.
3
4# The package import graph used in this test looks like:
5#
6# m ---- a
7# \ |
8# \ a_test ---- b
9# \ |
10# x b_test
11# | \
12# x_test -------------- c
13#
14# And the module dependency graph looks like:
15#
16# m -- a.1 -- b.1 -- c.2
17# \
18# x.1 ------------ c.1
19
20# Control case: in Go 1.15, the version of c imported by 'go test x' is the
21# version required by module b, even though b_test is not relevant to the main
22# module. (The main module imports a, and a_test imports b, but all of the
23# packages and tests in the main module can be built without b.)
24
25go list -m c
26stdout '^c v0.2.0 '
27
28[!short] go test -v x
29[!short] stdout ' c v0.2.0$'
30
31# With lazy loading, the go.mod requirements are the same,
32# but the irrelevant dependency on c v0.2.0 should be pruned out,
33# leaving only the relevant dependency on c v0.1.0.
34
35go mod edit -go=1.17
36go list -m c
37stdout '^c v0.1.0'
38
39[!short] go test -v x
40[!short] stdout ' c v0.1.0$'
41
42-- m.go --
43package m
44
45import (
46 _ "a"
47 _ "x"
48)
49-- go.mod --
50module m
51
52go 1.15
53
54require (
55 a v0.1.0
56 x v0.1.0
57)
58
59replace (
60 a v0.1.0 => ./a1
61 b v0.1.0 => ./b1
62 c v0.1.0 => ./c1
63 c v0.2.0 => ./c2
64 x v0.1.0 => ./x1
65)
66-- a1/go.mod --
67module a
68
69go 1.17
70
71require b v0.1.0
72-- a1/a.go --
73package a
74-- a1/a_test.go --
75package a_test
76
77import _ "b"
78-- b1/go.mod --
79module b
80
81go 1.17
82
83require c v0.2.0
84-- b1/b.go --
85package b
86-- b1/b_test.go --
87package b_test
88
89import (
90 "c"
91 "testing"
92)
93
94func TestCVersion(t *testing.T) {
95 t.Log(c.Version)
96}
97-- c1/go.mod --
98module c
99
100go 1.17
101-- c1/c.go --
102package c
103
104const Version = "v0.1.0"
105-- c2/go.mod --
106module c
107
108go 1.17
109-- c2/c.go --
110package c
111
112const Version = "v0.2.0"
113-- x1/go.mod --
114module x
115
116go 1.17
117
118require c v0.1.0
119-- x1/x.go --
120package x
121-- x1/x_test.go --
122package x_test
123
124import (
125 "c"
126 "testing"
127)
128
129func TestCVersion(t *testing.T) {
130 t.Log("c", c.Version)
131}
View as plain text