1 # Test that ModuleDirect.Public is correctly set on go list output.
2 # This is a regression test for issue #66789.
3
4 # In this test, the workspace contains modules example.com/a and
5 # example.com/b. Module example.com/a has a direct requirement
6 # on rsc.io/sampler, and an indirect requirement on golang.org/x/text
7 # through rsc.io/isampler. Module example.com/b has a direct
8 # requirement on example.com/c which is incorrectly marked as indirect
9 # in module example.com/b's go.mod file.
10
11 # Check that go list -m processes the indirect annotations in the
12 # go.mod file.
13 go list -f '{{.Path}} {{.Indirect}}' -m all
14 stdout 'example.com/a false'
15 stdout 'example.com/b false'
16 stdout 'rsc.io/sampler false'
17 stdout 'golang.org/x/text true'
18 stdout 'example.com/c true' # Uses the information in go.mod without checking imports.
19
20 # Check that 'go list all' correctly populates "indirect" module annotation.
21 go list -f '{{.ImportPath}} {{with .Module}}{{.Indirect}}{{end}}' all
22 stdout 'example.com/a false'
23 stdout 'example.com/b false'
24 stdout 'rsc.io/sampler false'
25 stdout 'golang.org/x/text/language true'
26 stdout 'example.com/c false'
27
28 -- go.work --
29 go 1.23
30
31 use ./a
32 use ./b
33 -- a/go.mod --
34 module example.com/a
35
36 go 1.23
37
38 require rsc.io/sampler v1.2.1
39
40 require golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c // indirect
41 -- a/a.go --
42 package a
43
44 import "rsc.io/sampler"
45
46 func A() string {
47 return sampler.Hello()
48 }
49 -- b/go.mod --
50 module example.com/b
51
52 go 1.23
53
54 // The indirect comment below is inaccurate. Its purpose
55 // is to test that it is corrected when enough packages
56 // are loaded to correct it.
57
58 require example.com/c v1.0.0 // indirect
59
60 replace example.com/c => ../c
61 -- b/b.go --
62 package b
63
64 import "example.com/c"
65
66 func B() {
67 c.C()
68 }
69 -- c/go.mod --
70 module example.com/c
71
72 go 1.23
73 -- c/c.go --
74 package c
75
76 func C() {}
View as plain text