...
1env GO111MODULE=on
2[short] skip
3
4cd m
5
6# 'go list all' should list all of the packages used (directly or indirectly) by
7# the packages in the main module, but no other packages from the standard
8# library or active modules.
9#
10# 'go list ...' should list packages in all active modules and the standard library.
11#
12# 'go list example.com/m/...' should list packages in all modules that begin with 'example.com/m/'.
13#
14# 'go list ./...' should list only packages in the current module, not other active modules.
15#
16# Warnings about unmatched patterns should only be printed once.
17#
18# And the go command should be able to keep track of all this!
19go list -f '{{.ImportPath}}: {{.Match}}' all ... example.com/m/... ./... ./xyz...
20stdout 'example.com/m/useunicode: \[all \.\.\. example.com/m/... ./...\]'
21stdout 'example.com/m/useunsafe: \[all \.\.\. example.com/m/... ./...\]'
22[cgo] stdout 'example.com/m/useC: \[all \.\.\. example.com/m/... ./...\]'
23[!cgo] ! stdout example.com/m/useC
24stdout 'example.com/unused/useerrors: \[\.\.\.\]' # but not "all"
25stdout 'example.com/m/nested/useencoding: \[\.\.\. example.com/m/...\]' # but NOT "all" or "./..."
26stdout '^unicode: \[all \.\.\.\]'
27stdout '^unsafe: \[all \.\.\.\]'
28stdout 'index/suffixarray: \[\.\.\.\]'
29stdout 'cmd/pprof: \[\.\.\.\]'
30
31stderr -count=1 '^go: warning: "./xyz..." matched no packages$'
32
33# 'go list ./...' should not try to resolve the main module.
34cd ../empty
35go list -deps ./...
36! stdout .
37! stderr 'finding'
38stderr -count=1 '^go: warning: "./..." matched no packages'
39
40# disabling cgo should drop useC
41[short] skip
42env CGO_ENABLED=0
43go list -f '{{.ImportPath}}: {{.Match}}' all ... example.com/m/... ./... ./xyz...
44! stdout example.com/m/useC
45
46-- m/go.mod --
47module example.com/m
48
49require example.com/unused v0.0.0 // indirect
50replace example.com/unused => ../unused
51
52require example.com/m/nested v0.0.0 // indirect
53replace example.com/m/nested => ../nested
54
55-- m/useC/useC.go --
56package useC
57import _ "C" // "C" is a pseudo-package, not an actual one
58-- m/useunicode/useunicode.go --
59package useunicode
60import _ "unicode"
61-- m/useunsafe/useunsafe.go --
62package useunsafe
63import _ "unsafe"
64
65-- unused/go.mod --
66module example.com/unused
67-- unused/useerrors/useerrors.go --
68package useerrors
69import _ "errors"
70
71-- nested/go.mod --
72module example.com/m/nested
73-- nested/useencoding/useencoding.go --
74package useencoding
75import _ "encoding"
76
77-- empty/go.mod --
78module example.com/empty
View as plain text