1 cp go.mod.orig go.mod
2
3 # If we list a package in an implicit dependency imported from the main module,
4 # we should get an error because the dependency should have an explicit
5 # requirement.
6 go list -m indirect-with-pkg
7 stdout '^indirect-with-pkg v1.0.0 => ./indirect-with-pkg$'
8 ! go list ./use-indirect
9 stderr '^package m/use-indirect imports indirect-with-pkg from implicitly required module; to add missing requirements, run:\n\tgo get indirect-with-pkg@v1.0.0$'
10
11 # We can promote the implicit requirement by getting the importing package.
12 # NOTE: the hint recommends getting the imported package (tested below) since
13 # it's more obvious and doesn't require -d. However, that adds an '// indirect'
14 # comment on the requirement.
15 go get m/use-indirect
16 cmp go.mod go.mod.use
17 cp go.mod.orig go.mod
18
19 # We can also promote implicit requirements using 'go get' on them, or their
20 # packages. This gives us "// indirect" requirements, since 'go get' doesn't
21 # know they're needed by the main module. See #43131 for the rationale.
22 # The hint above recommends this because it's more obvious usage and doesn't
23 # require the -d flag.
24 go get indirect-with-pkg indirect-without-pkg
25 cmp go.mod go.mod.indirect
26
27 -- go.mod.orig --
28 module m
29
30 go 1.16
31
32 require direct v1.0.0
33
34 replace (
35 direct v1.0.0 => ./direct
36 indirect-with-pkg v1.0.0 => ./indirect-with-pkg
37 indirect-without-pkg v1.0.0 => ./indirect-without-pkg
38 )
39 -- go.mod.use --
40 module m
41
42 go 1.16
43
44 require (
45 direct v1.0.0
46 indirect-with-pkg v1.0.0
47 )
48
49 replace (
50 direct v1.0.0 => ./direct
51 indirect-with-pkg v1.0.0 => ./indirect-with-pkg
52 indirect-without-pkg v1.0.0 => ./indirect-without-pkg
53 )
54 -- go.mod.indirect --
55 module m
56
57 go 1.16
58
59 require (
60 direct v1.0.0
61 indirect-with-pkg v1.0.0 // indirect
62 indirect-without-pkg v1.0.0 // indirect
63 )
64
65 replace (
66 direct v1.0.0 => ./direct
67 indirect-with-pkg v1.0.0 => ./indirect-with-pkg
68 indirect-without-pkg v1.0.0 => ./indirect-without-pkg
69 )
70 -- use-indirect/use-indirect.go --
71 package use
72
73 import _ "indirect-with-pkg"
74 -- direct/go.mod --
75 module direct
76
77 go 1.16
78
79 require (
80 indirect-with-pkg v1.0.0
81 indirect-without-pkg v1.0.0
82 )
83 -- indirect-with-pkg/go.mod --
84 module indirect-with-pkg
85
86 go 1.16
87 -- indirect-with-pkg/p.go --
88 package p
89 -- indirect-without-pkg/go.mod --
90 module indirect-without-pkg
91
92 go 1.16
93
View as plain text