diff options
author | Bryan C. Mills <bcmills@google.com> | 2021-11-03 10:39:54 -0400 |
---|---|---|
committer | Bryan C. Mills <bcmills@google.com> | 2021-11-04 21:33:23 +0000 |
commit | 71fc881cff79d0f3b352c20b947f4911892864fa (patch) | |
tree | 16365415e0eb53faf9aa7269773ce2c9ae188247 /src/cmd/go/internal/test | |
parent | 82481525280e4d0c74cb3f6341ce2f4653a165b8 (diff) | |
download | go-git-71fc881cff79d0f3b352c20b947f4911892864fa.tar.gz |
cmd/go: ensure that 'go test' prints the FAIL line for a package on a new line
Fixes #49317
Change-Id: I4038fd4c1d845d54ecbbf82bf73060db1b44c9bc
Reviewed-on: https://go-review.googlesource.com/c/go/+/361095
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/cmd/go/internal/test')
-rw-r--r-- | src/cmd/go/internal/test/test.go | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/cmd/go/internal/test/test.go b/src/cmd/go/internal/test/test.go index de6525d541..7361c11786 100644 --- a/src/cmd/go/internal/test/test.go +++ b/src/cmd/go/internal/test/test.go @@ -1405,15 +1405,25 @@ func (c *runCache) builderRunTest(b *work.Builder, ctx context.Context, a *work. if bytes.HasPrefix(out, tooManyTargetsToFuzz[1:]) || bytes.Contains(out, tooManyTargetsToFuzz) { norun = " [will not fuzz, -fuzz matches more than one target]" } + if len(out) > 0 && !bytes.HasSuffix(out, []byte("\n")) { + // Ensure that the output ends with a newline before the "ok" + // line we're about to print (https://golang.org/issue/49317). + cmd.Stdout.Write([]byte("\n")) + } fmt.Fprintf(cmd.Stdout, "ok \t%s\t%s%s%s\n", a.Package.ImportPath, t, coveragePercentage(out), norun) c.saveOutput(a) } else { base.SetExitStatus(1) - // If there was test output, assume we don't need to print the exit status. - // Buf there's no test output, do print the exit status. if len(out) == 0 { + // If there was no test output, print the exit status so that the reason + // for failure is clear. fmt.Fprintf(cmd.Stdout, "%s\n", err) + } else if !bytes.HasSuffix(out, []byte("\n")) { + // Otherwise, ensure that the output ends with a newline before the FAIL + // line we're about to print (https://golang.org/issue/49317). + cmd.Stdout.Write([]byte("\n")) } + // NOTE(golang.org/issue/37555): test2json reports that a test passes // unless "FAIL" is printed at the beginning of a line. The test may not // actually print that if it panics, exits, or terminates abnormally, |