...
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.
13go list -f '{{.Path}} {{.Indirect}}' -m all
14stdout 'example.com/a false'
15stdout 'example.com/b false'
16stdout 'rsc.io/sampler false'
17stdout 'golang.org/x/text true'
18stdout '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.
21go list -f '{{.ImportPath}} {{with .Module}}{{.Indirect}}{{end}}' all
22stdout 'example.com/a false'
23stdout 'example.com/b false'
24stdout 'rsc.io/sampler false'
25stdout 'golang.org/x/text/language true'
26stdout 'example.com/c false'
27
28-- go.work --
29go 1.23
30
31use ./a
32use ./b
33-- a/go.mod --
34module example.com/a
35
36go 1.23
37
38require rsc.io/sampler v1.2.1
39
40require golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c // indirect
41-- a/a.go --
42package a
43
44import "rsc.io/sampler"
45
46func A() string {
47 return sampler.Hello()
48}
49-- b/go.mod --
50module example.com/b
51
52go 1.23
53
54// The indrect comment below is inaccurate. Its purpose
55// is to test that it is corrected when enough packages
56// are loaded to correct it.
57
58require example.com/c v1.0.0 // indirect
59
60replace example.com/c => ../c
61-- b/b.go --
62package b
63
64import "example.com/c"
65
66func B() {
67 c.C()
68}
69-- c/go.mod --
70module example.com/c
71
72go 1.23
73-- c/c.go --
74package c
75
76func C() {}
View as plain text