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