var nl = []byte{'\n'}
func runList(cmd *base.Command, args []string) {
+ modload.LoadTests = *listTest
work.BuildInit()
out := newTrackingWriter(os.Stdout)
defer out.w.Flush()
}
case pkg == "all":
- if loaded.testRoots {
- loaded.testAll = true
- }
+ loaded.testAll = true
// TODO: Don't print warnings multiple times.
roots = append(roots, warnPattern("all", matchPackages("...", loaded.tags, []module.Version{Target}))...)
paths = append(paths, "all") // will expand after load completes
goVersion map[string]string // go version recorded in each module
}
+// LoadTests controls whether the loaders load tests of the root packages.
+var LoadTests bool
+
func newLoader() *loader {
ld := new(loader)
ld.tags = imports.Tags()
-
- switch cfg.CmdName {
- case "test", "vet":
- ld.testRoots = true
- }
+ ld.testRoots = LoadTests
return ld
}
"cmd/go/internal/cache"
"cmd/go/internal/cfg"
"cmd/go/internal/load"
+ "cmd/go/internal/modload"
"cmd/go/internal/str"
"cmd/go/internal/work"
"cmd/internal/test2json"
}
func runTest(cmd *base.Command, args []string) {
+ modload.LoadTests = true
+
pkgArgs, testArgs = testFlags(args)
work.FindExecCmd() // initialize cached result
import (
"cmd/go/internal/base"
"cmd/go/internal/load"
+ "cmd/go/internal/modload"
"cmd/go/internal/work"
"path/filepath"
)
}
func runVet(cmd *base.Command, args []string) {
+ modload.LoadTests = true
+
vetFlags, pkgArgs := vetFlags(args)
work.BuildInit()
"testing"
"golang.org/x/text/language"
+ _ "rsc.io/testonly"
)
var glassTests = []struct {
--- /dev/null
+rsc.io/testonly v1.0.0
+written by hand
+
+-- .mod --
+module rsc.io/testonly
+-- .info --
+{"Version":"v1.0.0"}
+-- testonly.go --
+package testonly
! go build ./fromstdvendor
stderr 'use of vendored package golang_org/x/net/http/httpguts not allowed'
+env GO111MODULE=off
+! go build ./fromstdvendor
+stderr 'cannot find package "golang_org/x/net/http/httpguts" in any of:'
+env GO111MODULE=on
# Dependencies should be able to use their own internal modules...
rm go.mod
# The pattern "all" should match only packages that acutally exist,
# ignoring those whose existence is merely implied by imports.
-go list -e -f '{{.ImportPath}}' all
+go list -e -f '{{.ImportPath}} {{.Error}}' all
stdout example.com/direct
stdout example.com/indirect
-! stdout example.com/notfound
+# 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 --
-# Broken on nocgo builders: https://golang.org/issue/26906
-[!cgo] skip
-
env GO111MODULE=on
cd m
# the packages in the main module, but no other packages from the standard
# library or active modules.
go list all
-cmp stdout all.txt
+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.
# BUG: It currently omits the standard library (https://golang.org/issue/26905).
go list ...
-cmp stdout dots.txt
+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
# 'go list example.com/m/...' should list packages in all modules that begin with
# "example.com/m/".
go list example.com/m/...
-cmp stdout prefix.txt
+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 ./...
-cmp stdout in-mod.txt
-
+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
-- nested/useencoding/useencoding.go --
package useencoding
import _ "encoding"
-
--- m/all.txt --
-example.com/m/useC
-example.com/m/useunicode
-example.com/m/useunsafe
-unicode
-unsafe
--- m/dots.txt --
-example.com/m/useC
-example.com/m/useunicode
-example.com/m/useunsafe
-example.com/m/nested/useencoding
-example.com/unused/useerrors
--- m/prefix.txt --
-example.com/m/useC
-example.com/m/useunicode
-example.com/m/useunsafe
-example.com/m/nested/useencoding
--- m/in-mod.txt --
-example.com/m/useC
-example.com/m/useunicode
-example.com/m/useunsafe
# A test in the module's root package should work.
cd a/
+cp go.mod.empty go.mod
+go test
+stdout PASS
+
+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
go test
stdout PASS
--- a/go.mod --
+-- a/go.mod.empty --
module example.com/user/a
-- a/a.go --
package a
import "testing"
+import _ "rsc.io/quote"
func Test(t *testing.T) {}