cmd/go: ignore wildcard-matched test-only packages in go build

It makes sense to be able to cd into the top of a directory tree
and run commands like:

	go list ./...
	go test ./...
	go build ./...
	go install ./...

Some packages have no tests. Some packages have only tests (no code).
While go list applies to both kinds of packages, and go test correctly
handles packages without tests, go build and go install reject packages
with only tests.

If you run

	go install testonlypkg

then it does seem reasonable to fail with an error, since testonlypkg
cannot actually be installed. But if testonlypkg was only picked up
by wildcard expansion, then to keep the examples above working,
we should just silently skip over it during go build and go install.

CL 23314 fixed this same problem for "go get"
but special-cased "go get", leaving "go build" and "go install" failing.

This CL fixes the general case and removes the "go get" special case.

Picked this up in module work because I'm using "go build ./..." as part
of evaluating whether repos are compatible with Go modules.

Fixes golang/go#20760.
Fixes golang/go#22409.

Change-Id: I5caaa6a346a5d07a7ad9e2669e89da76b397dc42
Reviewed-by: Bryan C. Mills <>
7 files changed
tree: cf6e1795b52256a1da9aede8cb7e2ef03f02389e
  1. vendor/
  3. codereview.cfg
  7. main.go

Versioned Go Prototype (vgo)

This repository holds a prototype of what the go command might look like with integrated support for package versioning.

See for documents about the design.


Use go get -u

You can also manually git clone the repository to $GOPATH/src/

Report Issues / Send Patches


This is still a very early prototype. You are likely to run into bugs. Please file bugs in the main Go issue tracker,, and put the prefix x/vgo: in the issue title.

Thank you.