Commit c6e0c49b authored by Jess Frazelle's avatar Jess Frazelle Committed by Ian Lance Taylor

cmd/go: updates go get to return exit status 0 for test file only pkgs

Updates the behavior of `go get` to return exit status 0 when a
requested package only contains test files.

Fixes #15093

Change-Id: I76b80517d58748090f5e8c6f41178361e2d7ca54
Reviewed-on: https://go-review.googlesource.com/23314Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 3e270ab8
......@@ -579,6 +579,10 @@ func libname(args []string, pkgs []*Package) (string, error) {
}
func runInstall(cmd *Command, args []string) {
installPackages(args, false)
}
func installPackages(args []string, forGet bool) {
if gobin != "" && !filepath.IsAbs(gobin) {
fatalf("cannot install, GOBIN must be an absolute path")
}
......@@ -606,6 +610,8 @@ func runInstall(cmd *Command, args []string) {
var b builder
b.init()
// Set the behavior for `go get` to not error on packages with test files only.
b.testFilesOnlyOK = forGet
var a *action
if buildBuildmode == "shared" {
if libName, err := libname(args, pkgs); err != nil {
......@@ -696,6 +702,8 @@ type builder struct {
flagCache map[string]bool // a cache of supported compiler flags
print func(args ...interface{}) (int, error)
testFilesOnlyOK bool // do not error if the packages only have test files
output sync.Mutex
scriptDir string // current directory in printed script
......@@ -1279,6 +1287,8 @@ func (b *builder) do(root *action) {
if err != nil {
if err == errPrintedOutput {
setExitStatus(2)
} else if _, ok := err.(*build.NoGoError); ok && len(a.p.TestGoFiles) > 0 && b.testFilesOnlyOK {
// Ignore the "no buildable Go source files" error for a package with only test files.
} else {
errorf("%s", err)
}
......@@ -1365,7 +1375,7 @@ func (b *builder) build(a *action) (err error) {
}
defer func() {
if err != nil && err != errPrintedOutput {
if _, ok := err.(*build.NoGoError); err != nil && err != errPrintedOutput && !(ok && b.testFilesOnlyOK && len(a.p.TestGoFiles) > 0) {
err = fmt.Errorf("go build %s: %v", a.p.ImportPath, err)
}
}()
......
......@@ -139,7 +139,7 @@ func runGet(cmd *Command, args []string) {
return
}
runInstall(cmd, args)
installPackages(args, true)
}
// downloadPaths prepares the list of paths to pass to download.
......
......@@ -1430,6 +1430,17 @@ func TestGoGetNonPkg(t *testing.T) {
tg.grepStderr("golang.org/x/tools: no buildable Go source files", "missing error")
}
func TestGoGetTestOnlyPkg(t *testing.T) {
testenv.MustHaveExternalNetwork(t)
tg := testgo(t)
defer tg.cleanup()
tg.tempDir("gopath")
tg.setenv("GOPATH", tg.path("gopath"))
tg.run("get", "golang.org/x/tour/content")
tg.run("get", "-t", "golang.org/x/tour/content")
}
func TestInstalls(t *testing.T) {
if testing.Short() {
t.Skip("don't install into GOROOT in short mode")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment