env GO111MODULE=on

cd m

# 'go list all' should list all of the packages used (directly or indirectly) by
# the packages in the main module, but no other packages from the standard
# library or active modules.
go list all
stdout example.com/m/useunicode
stdout example.com/m/useunsafe
[cgo] stdout example.com/m/useC
[!cgo] ! stdout example.com/m/useC
stdout '^unicode$'
stdout '^unsafe$'
! stdout index/suffixarray

# 'go list ...' should list packages in all active modules and the standard library.
# But not cmd/* - see golang.org/issue/26924.
go list ...
stdout example.com/unused/useerrors
stdout example.com/m/useunsafe
[cgo] stdout example.com/m/useC
[!cgo] ! stdout example.com/m/useC
stdout '^unicode$'
stdout '^unsafe$'
stdout index/suffixarray
! stdout cmd/pprof

# 'go list example.com/m/...' should list packages in all modules that begin with
# "example.com/m/".
go list example.com/m/...
stdout example.com/m/useunicode
stdout example.com/m/useunsafe
! stdout example.com/[^m]
! stdout ^[^e]
[cgo] stdout example.com/m/useC
[!cgo] ! stdout example.com/m/useC

# 'go list ./...' should list only packages in the current module, not other active modules.
go list ./...
stdout example.com/m/useunicode
stdout example.com/m/useunsafe
[cgo] stdout example.com/m/useC
[!cgo] ! stdout example.com/m/useC

-- m/go.mod --
module example.com/m

require example.com/unused v0.0.0 // indirect
replace example.com/unused => ../unused

require example.com/m/nested v0.0.0 // indirect
replace example.com/m/nested => ../nested

-- m/useC/useC.go --
package useC
import _ "C" // "C" is a pseudo-package, not an actual one
-- m/useunicode/useunicode.go --
package useunicode
import _ "unicode"
-- m/useunsafe/useunsafe.go --
package useunsafe
import _ "unsafe"

-- unused/go.mod --
module example.com/unused
-- unused/useerrors/useerrors.go --
package useerrors
import _ "errors"

-- nested/go.mod --
module example.com/m/nested
-- nested/useencoding/useencoding.go --
package useencoding
import _ "encoding"
