...
1# If the root requirements in a lazy module are inconsistent
2# (for example, due to a bad hand-edit or git merge),
3# they can go unnoticed as long as the module with the violated
4# requirement is not used.
5# When we load a package from that module, we should spot-check its
6# requirements and either emit an error or update the go.mod file.
7
8cp go.mod go.mod.orig
9
10
11# If we load package x from x.1, we only check the requirements of x,
12# which are fine: loading succeeds.
13
14go list -deps ./usex
15stdout '^example.net/x$'
16cmp go.mod go.mod.orig
17
18
19# However, if we load needx2, we should load the requirements of needx2.
20# Those requirements indicate x.2, not x.1, so the module graph is
21# inconsistent and needs to be fixed.
22
23! go list -deps ./useneedx2
24stderr '^go: updates to go.mod needed; to update it:\n\tgo mod tidy$'
25
26! go list -deps example.net/needx2
27stderr '^go: updates to go.mod needed; to update it:\n\tgo mod tidy$'
28
29
30# The command printed in the error message should fix the problem.
31
32go mod tidy
33go list -deps ./useneedx2
34stdout '^example.net/m/useneedx2$'
35stdout '^example.net/needx2$'
36stdout '^example.net/x$'
37
38go list -m all
39stdout '^example.net/needx2 v0\.1\.0 '
40stdout '^example.net/x v0\.2\.0 '
41
42
43-- go.mod --
44module example.net/m
45
46go 1.17
47
48require (
49 example.net/needx2 v0.1.0
50 example.net/x v0.1.0
51)
52
53replace (
54 example.net/needx2 v0.1.0 => ./needx2.1
55 example.net/x v0.1.0 => ./x.1
56 example.net/x v0.2.0 => ./x.2
57)
58-- useneedx2/useneedx2.go --
59package useneedx2
60
61import _ "example.net/needx2"
62-- usex/usex.go --
63package usex
64
65import _ "example.net/x"
66
67-- x.1/go.mod --
68module example.com/x
69
70go 1.17
71-- x.1/x.go --
72package x
73
74-- x.2/go.mod --
75module example.com/x
76
77go 1.17
78-- x.2/x.go --
79package x
80
81const AddedInV2 = true
82
83-- needx2.1/go.mod --
84module example.com/x
85
86go 1.17
87
88require example.net/x v0.2.0
89-- needx2.1/needx2.go --
90// Package needx2 needs x v0.2.0 or higher.
91package needx2
92
93import "example.net/x"
94
95var _ = x.AddedInV2
View as plain text