...
1# This test matches list_bad_import, but in module mode.
2# Please keep them in sync.
3
4env GO111MODULE=on
5cd example.com
6
7# Without -e, listing an otherwise-valid package with an unsatisfied direct import should fail.
8# BUG: Today it succeeds.
9go list -f '{{if .Error}}error{{end}} {{if .Incomplete}}incomplete{{end}} {{range .DepsErrors}}bad dep: {{.Err}}{{end}}' example.com/direct
10! stdout ^error
11stdout 'incomplete'
12stdout 'bad dep: .*example.com/notfound'
13
14# Listing with -deps should also fail.
15! go list -deps example.com/direct
16stderr example.com/notfound
17
18# But -e -deps should succeed.
19go list -e -deps example.com/direct
20stdout example.com/notfound
21
22
23# Listing an otherwise-valid package that imports some *other* package with an
24# unsatisfied import should also fail.
25# BUG: Today, it succeeds.
26go list -f '{{if .Error}}error{{end}} {{if .Incomplete}}incomplete{{end}} {{range .DepsErrors}}bad dep: {{.Err}}{{end}}' example.com/indirect
27! stdout ^error
28stdout incomplete
29stdout 'bad dep: .*example.com/notfound'
30
31# Again, -deps should fail.
32! go list -deps example.com/indirect
33stderr example.com/notfound
34
35# But -e -deps should succeed.
36go list -e -deps example.com/indirect
37stdout example.com/notfound
38
39
40# Listing the missing dependency directly should fail outright...
41! go list -f '{{if .Error}}error{{end}} {{if .Incomplete}}incomplete{{end}}' example.com/notfound
42stderr 'no required module provides package example.com/notfound; to add it:\n\tgo get example.com/notfound'
43! stdout error
44! stdout incomplete
45
46# ...but listing with -e should succeed.
47go list -e -f '{{if .Error}}error{{end}} {{if .Incomplete}}incomplete{{end}}' example.com/notfound
48stdout error
49stdout incomplete
50
51
52# The pattern "all" should match only packages that actually exist,
53# ignoring those whose existence is merely implied by imports.
54go list -e -f '{{.ImportPath}} {{.Error}}' all
55stdout example.com/direct
56stdout example.com/indirect
57# TODO: go list creates a dummy package with the import-not-found
58# but really the Error belongs on example.com/direct, and this package
59# should not be printed.
60# ! stdout example.com/notfound
61
62
63-- example.com/go.mod --
64module example.com
65
66-- example.com/direct/direct.go --
67package direct
68import _ "example.com/notfound"
69
70-- example.com/indirect/indirect.go --
71package indirect
72import _ "example.com/direct"
73
74-- example.com/notfound/README --
75This directory intentionally left blank.
View as plain text