aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/test/test.go
diff options
context:
space:
mode:
authorBryan C. Mills <bcmills@google.com>2019-10-09 20:13:40 +0000
committerBryan C. Mills <bcmills@google.com>2019-10-09 20:30:46 +0000
commitb3104fe3af99c965b5e9a954264dfc384f21bb37 (patch)
tree0b402f6b6e819b69ed55406232b090ab74bf36dc /src/cmd/go/internal/test/test.go
parent4c7a8d63e4042d16f87bf63720e3814683b0cb4b (diff)
downloadgo-b3104fe3af99c965b5e9a954264dfc384f21bb37.tar.gz
go-b3104fe3af99c965b5e9a954264dfc384f21bb37.zip
Revert "cmd/go: fail if a test binary exits with no output"
This reverts CL 184457. Reason for revert: introduced failures in the regression test for #18153. Fixes #34791 Updates #29062 Change-Id: I4040965163f809083c023be055e69b1149d6214e Reviewed-on: https://go-review.googlesource.com/c/go/+/200106 Run-TryBot: Bryan C. Mills <bcmills@google.com> Reviewed-by: Alexander Rakoczy <alex@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/cmd/go/internal/test/test.go')
-rw-r--r--src/cmd/go/internal/test/test.go37
1 files changed, 2 insertions, 35 deletions
diff --git a/src/cmd/go/internal/test/test.go b/src/cmd/go/internal/test/test.go
index f4ce355189..fb011d4c03 100644
--- a/src/cmd/go/internal/test/test.go
+++ b/src/cmd/go/internal/test/test.go
@@ -1048,18 +1048,6 @@ func (lockedStdout) Write(b []byte) (int, error) {
return os.Stdout.Write(b)
}
-type outputChecker struct {
- w io.Writer
- anyOutput bool
-}
-
-func (o *outputChecker) Write(p []byte) (int, error) {
- if !o.anyOutput && len(bytes.TrimSpace(p)) > 0 {
- o.anyOutput = true
- }
- return o.w.Write(p)
-}
-
// builderRunTest is the action for running a test binary.
func (c *runCache) builderRunTest(b *work.Builder, a *work.Action) error {
if a.Failed {
@@ -1079,7 +1067,6 @@ func (c *runCache) builderRunTest(b *work.Builder, a *work.Action) error {
}
var buf bytes.Buffer
- buffered := false
if len(pkgArgs) == 0 || testBench {
// Stream test output (no buffering) when no package has
// been given on the command line (implicit current directory)
@@ -1106,16 +1093,9 @@ func (c *runCache) builderRunTest(b *work.Builder, a *work.Action) error {
stdout = io.MultiWriter(stdout, &buf)
} else {
stdout = &buf
- buffered = true
}
}
- // Keep track of whether we've seen any output at all. This is useful
- // later, to avoid succeeding if the test binary did nothing or didn't
- // reach the end of testing.M.Run.
- outCheck := outputChecker{w: stdout}
- stdout = &outCheck
-
if c.buf == nil {
// We did not find a cached result using the link step action ID,
// so we ran the link step. Try again now with the link output
@@ -1129,7 +1109,7 @@ func (c *runCache) builderRunTest(b *work.Builder, a *work.Action) error {
c.tryCacheWithID(b, a, a.Deps[0].BuildContentID())
}
if c.buf != nil {
- if !buffered {
+ if stdout != &buf {
stdout.Write(c.buf.Bytes())
c.buf.Reset()
}
@@ -1227,19 +1207,6 @@ func (c *runCache) builderRunTest(b *work.Builder, a *work.Action) error {
mergeCoverProfile(cmd.Stdout, a.Objdir+"_cover_.out")
- if err == nil && !testList && !outCheck.anyOutput {
- // If a test does os.Exit(0) by accident, 'go test' may succeed
- // and it can take a while for a human to notice the package's
- // tests didn't actually pass.
- //
- // If a test binary ran without error, it should have at least
- // printed something, such as a PASS line.
- //
- // The only exceptions are when no tests have run, and the
- // -test.list flag, which just prints the names of tests
- // matching a pattern.
- err = fmt.Errorf("test binary succeeded but did not print anything")
- }
if err == nil {
norun := ""
if !testShowPass && !testJSON {
@@ -1260,7 +1227,7 @@ func (c *runCache) builderRunTest(b *work.Builder, a *work.Action) error {
fmt.Fprintf(cmd.Stdout, "FAIL\t%s\t%s\n", a.Package.ImportPath, t)
}
- if !buffered {
+ if cmd.Stdout != &buf {
buf.Reset() // cmd.Stdout was going to os.Stdout already
}
return nil