| @@ -0,0 +1,73 @@ | ||
| # This test matches list_bad_import, but in module mode. | ||
| # Please keep them in sync. | ||
| env GO111MODULE=on | ||
| cd example.com | ||
| # Without -e, listing an otherwise-valid package with an unsatisfied direct import should fail. | ||
| # BUG: Today it succeeds. | ||
| go list -f '{{if .Error}}error{{end}} {{if .Incomplete}}incomplete{{end}} {{range .DepsErrors}}bad dep: {{.Err}}{{end}}' example.com/direct | ||
| ! stdout ^error | ||
| stdout 'incomplete' | ||
| stdout 'bad dep: .*example.com/notfound' | ||
| # Listing with -deps should also fail. | ||
| # BUG: Today, it does not. | ||
| # ! go list -deps example.com/direct | ||
| # stderr example.com/notfound | ||
| go list -deps example.com/direct | ||
| stdout example.com/notfound | ||
| # Listing an otherwise-valid package that imports some *other* package with an | ||
| # unsatisfied import should also fail. | ||
| # BUG: Today, it succeeds. | ||
| go list -f '{{if .Error}}error{{end}} {{if .Incomplete}}incomplete{{end}} {{range .DepsErrors}}bad dep: {{.Err}}{{end}}' example.com/indirect | ||
| ! stdout ^error | ||
| stdout incomplete | ||
| stdout 'bad dep: .*example.com/notfound' | ||
| # Again, -deps should fail. | ||
| # BUG: Again, it does not. | ||
| # ! go list -deps example.com/indirect | ||
| # stderr example.com/notfound | ||
| go list -deps example.com/indirect | ||
| stdout example.com/notfound | ||
| # Listing the missing dependency directly should fail outright... | ||
| ! go list -f '{{if .Error}}error{{end}} {{if .Incomplete}}incomplete{{end}}' example.com/notfound | ||
| stderr 'cannot find module providing package example.com/notfound' | ||
| ! stdout error | ||
| ! stdout incomplete | ||
| # ...but listing with -e should succeed. | ||
| go list -e -f '{{if .Error}}error{{end}} {{if .Incomplete}}incomplete{{end}}' example.com/notfound | ||
| stdout error | ||
| stdout incomplete | ||
| # The pattern "all" should match only packages that acutally exist, | ||
| # ignoring those whose existence is merely implied by imports. | ||
| go list -e -f '{{.ImportPath}} {{.Error}}' all | ||
| stdout example.com/direct | ||
| stdout example.com/indirect | ||
| # TODO: go list creates a dummy package with the import-not-found | ||
| # but really the Error belongs on example.com/direct, and this package | ||
| # should not be printed. | ||
| # ! stdout example.com/notfound | ||
| -- example.com/go.mod -- | ||
| module example.com | ||
| -- example.com/direct/direct.go -- | ||
| package direct | ||
| import _ "example.com/notfound" | ||
| -- example.com/indirect/indirect.go -- | ||
| package indirect | ||
| import _ "example.com/direct" | ||
| -- example.com/notfound/README -- | ||
| This directory intentionally left blank. |
| @@ -0,0 +1,75 @@ | ||
| 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" |
| @@ -1,18 +1,119 @@ | ||
| env GO111MODULE=on | ||
| # A test in the module's root package should work. | ||
| cd a/ | ||
| cp go.mod.empty go.mod | ||
| go test | ||
| stdout PASS | ||
| -- a/go.mod -- | ||
| module github.com/user/a | ||
| cp go.mod.empty go.mod | ||
| go list -deps | ||
| ! stdout ^testing$ | ||
| # list all should include test dependencies, like testing | ||
| cp go.mod.empty go.mod | ||
| go list all | ||
| stdout ^testing$ | ||
| stdout ^rsc.io/quote$ | ||
| stdout ^rsc.io/testonly$ | ||
| # list -deps -tests should also include testing | ||
| # but not deps of tests of deps (rsc.io/testonly). | ||
| go list -deps -test | ||
| stdout ^testing$ | ||
| stdout ^rsc.io/quote$ | ||
| ! stdout ^rsc.io/testonly$ | ||
| # list -test all should succeed | ||
| cp go.mod.empty go.mod | ||
| go list -test all | ||
| stdout '^testing' | ||
| cp go.mod.empty go.mod | ||
| go test | ||
| stdout PASS | ||
| # A test with the "_test" suffix in the module root should also work. | ||
| cd ../b/ | ||
| go test | ||
| stdout PASS | ||
| # A test with the "_test" suffix of a *package* with a "_test" suffix should | ||
| # even work (not that you should ever do that). | ||
| cd ../c_test | ||
| go test | ||
| stdout PASS | ||
| cd ../d_test | ||
| go test | ||
| stdout PASS | ||
| -- a/go.mod.empty -- | ||
| module example.com/user/a | ||
| -- a/a.go -- | ||
| package a | ||
| -- a/a_test.go -- | ||
| package a | ||
| import "testing" | ||
| import _ "rsc.io/quote" | ||
| func Test(t *testing.T) {} | ||
| -- b/go.mod -- | ||
| module example.com/user/b | ||
| -- b/b.go -- | ||
| package b | ||
| -- b/b_test.go -- | ||
| package b_test | ||
| import "testing" | ||
| func Test(t *testing.T) {} | ||
| -- c_test/go.mod -- | ||
| module example.com/c_test | ||
| -- c_test/umm.go -- | ||
| // Package c_test is the non-test package for its import path! | ||
| package c_test | ||
| -- c_test/c_test_test.go -- | ||
| package c_test_test | ||
| import "testing" | ||
| func Test(t *testing.T) {} | ||
| -- d_test/go.mod -- | ||
| // Package d is an ordinary package in a deceptively-named directory. | ||
| module example.com/d | ||
| -- d_test/d.go -- | ||
| package d | ||
| -- d_test/d_test.go -- | ||
| package d_test | ||
| import "testing" | ||
| func Test(t *testing.T) {} | ||
| -- e/go.mod -- | ||
| module example.com/e_test | ||
| -- e/wat.go -- | ||
| // Package e_test is the non-test package for its import path, | ||
| // in a deceptively-named directory! | ||
| package e_test | ||
| -- e/e_test.go -- | ||
| package e_test_test | ||
| import "testing" | ||
| func Test(t *testing.T) {} |
| @@ -0,0 +1,27 @@ | ||
| env GO111MODULE=on | ||
| # initial conditions: using sampler v1.3.0, not listed in go.mod. | ||
| go list -deps | ||
| stdout rsc.io/sampler | ||
| ! grep 'rsc.io/sampler v1.3.0' go.mod | ||
| # update to v1.3.1, now indirect in go.mod. | ||
| go get rsc.io/sampler@v1.3.1 | ||
| grep 'rsc.io/sampler v1.3.1 // indirect' go.mod | ||
| cp go.mod go.mod.good | ||
| # vendoring can but should not need to make changes. | ||
| go mod vendor | ||
| cmp go.mod go.mod.good | ||
| # go list -mod=vendor (or go build -mod=vendor) must not modify go.mod. | ||
| # golang.org/issue/26704 | ||
| go list -mod=vendor | ||
| cmp go.mod go.mod.good | ||
| -- go.mod -- | ||
| module m | ||
| -- x.go -- | ||
| package x | ||
| import _ "rsc.io/quote" |
| @@ -0,0 +1,114 @@ | ||
| env GO111MODULE=on | ||
| go list -test all | ||
| stdout rsc.io/quote | ||
| stdout golang.org/x/text/language | ||
| # why a package? | ||
| go mod why golang.org/x/text/language | ||
| cmp stdout why-language.txt | ||
| # why a module? | ||
| go mod why -m golang.org... | ||
| cmp stdout why-text-module.txt | ||
| # why a package used only in tests? | ||
| go mod why rsc.io/testonly | ||
| cmp stdout why-testonly.txt | ||
| # why a module used only in tests? | ||
| go mod why -m rsc.io/testonly | ||
| cmp stdout why-testonly.txt | ||
| # test package not needed | ||
| go mod why golang.org/x/text/unused | ||
| cmp stdout why-unused.txt | ||
| # vendor doesn't use packages used only in tests. | ||
| go mod why -vendor rsc.io/testonly | ||
| cmp stdout why-vendor.txt | ||
| # vendor doesn't use modules used only in tests. | ||
| go mod why -vendor -m rsc.io/testonly | ||
| cmp stdout why-vendor-module.txt | ||
| # test multiple packages | ||
| go mod why golang.org/x/text/language golang.org/x/text/unused | ||
| cmp stdout why-both.txt | ||
| # test multiple modules | ||
| go mod why -m rsc.io/quote rsc.io/sampler | ||
| cmp stdout why-both-module.txt | ||
| -- go.mod -- | ||
| module mymodule | ||
| require rsc.io/quote v1.5.2 | ||
| -- x/x.go -- | ||
| package x | ||
| import _ "mymodule/z" | ||
| -- y/y.go -- | ||
| package y | ||
| -- y/y_test.go -- | ||
| package y | ||
| import _ "rsc.io/quote" | ||
| -- z/z.go -- | ||
| package z | ||
| import _ "mymodule/y" | ||
| -- why-language.txt -- | ||
| # golang.org/x/text/language | ||
| mymodule/y | ||
| mymodule/y.test | ||
| rsc.io/quote | ||
| rsc.io/sampler | ||
| golang.org/x/text/language | ||
| -- why-unused.txt -- | ||
| # golang.org/x/text/unused | ||
| (main module does not need package golang.org/x/text/unused) | ||
| -- why-text-module.txt -- | ||
| # golang.org/x/text | ||
| mymodule/y | ||
| mymodule/y.test | ||
| rsc.io/quote | ||
| rsc.io/sampler | ||
| golang.org/x/text/language | ||
| -- why-testonly.txt -- | ||
| # rsc.io/testonly | ||
| mymodule/y | ||
| mymodule/y.test | ||
| rsc.io/quote | ||
| rsc.io/sampler | ||
| rsc.io/sampler.test | ||
| rsc.io/testonly | ||
| -- why-vendor.txt -- | ||
| # rsc.io/testonly | ||
| (main module does not need to vendor package rsc.io/testonly) | ||
| -- why-vendor-module.txt -- | ||
| # rsc.io/testonly | ||
| (main module does not need to vendor module rsc.io/testonly) | ||
| -- why-both.txt -- | ||
| # golang.org/x/text/language | ||
| mymodule/y | ||
| mymodule/y.test | ||
| rsc.io/quote | ||
| rsc.io/sampler | ||
| golang.org/x/text/language | ||
| # golang.org/x/text/unused | ||
| (main module does not need package golang.org/x/text/unused) | ||
| -- why-both-module.txt -- | ||
| # rsc.io/quote | ||
| mymodule/y | ||
| mymodule/y.test | ||
| rsc.io/quote | ||
| # rsc.io/sampler | ||
| mymodule/y | ||
| mymodule/y.test | ||
| rsc.io/quote | ||
| rsc.io/sampler |
| @@ -0,0 +1,11 @@ | ||
| // Copyright 2018 The Go Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style | ||
| // license that can be found in the LICENSE file. | ||
| package issue26390 | ||
| type A = T | ||
| func (t *T) m() *A { return t } | ||
| type T struct{} |