Skip to content

Commit b3104fe

Browse files
author
Bryan C. Mills
committed
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 <[email protected]> Reviewed-by: Alexander Rakoczy <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 4c7a8d6 commit b3104fe

File tree

7 files changed

+12
-200
lines changed

7 files changed

+12
-200
lines changed

src/cmd/go/internal/test/test.go

+2-35
Original file line numberDiff line numberDiff line change
@@ -1048,18 +1048,6 @@ func (lockedStdout) Write(b []byte) (int, error) {
10481048
return os.Stdout.Write(b)
10491049
}
10501050

1051-
type outputChecker struct {
1052-
w io.Writer
1053-
anyOutput bool
1054-
}
1055-
1056-
func (o *outputChecker) Write(p []byte) (int, error) {
1057-
if !o.anyOutput && len(bytes.TrimSpace(p)) > 0 {
1058-
o.anyOutput = true
1059-
}
1060-
return o.w.Write(p)
1061-
}
1062-
10631051
// builderRunTest is the action for running a test binary.
10641052
func (c *runCache) builderRunTest(b *work.Builder, a *work.Action) error {
10651053
if a.Failed {
@@ -1079,7 +1067,6 @@ func (c *runCache) builderRunTest(b *work.Builder, a *work.Action) error {
10791067
}
10801068

10811069
var buf bytes.Buffer
1082-
buffered := false
10831070
if len(pkgArgs) == 0 || testBench {
10841071
// Stream test output (no buffering) when no package has
10851072
// been given on the command line (implicit current directory)
@@ -1106,16 +1093,9 @@ func (c *runCache) builderRunTest(b *work.Builder, a *work.Action) error {
11061093
stdout = io.MultiWriter(stdout, &buf)
11071094
} else {
11081095
stdout = &buf
1109-
buffered = true
11101096
}
11111097
}
11121098

1113-
// Keep track of whether we've seen any output at all. This is useful
1114-
// later, to avoid succeeding if the test binary did nothing or didn't
1115-
// reach the end of testing.M.Run.
1116-
outCheck := outputChecker{w: stdout}
1117-
stdout = &outCheck
1118-
11191099
if c.buf == nil {
11201100
// We did not find a cached result using the link step action ID,
11211101
// 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 {
11291109
c.tryCacheWithID(b, a, a.Deps[0].BuildContentID())
11301110
}
11311111
if c.buf != nil {
1132-
if !buffered {
1112+
if stdout != &buf {
11331113
stdout.Write(c.buf.Bytes())
11341114
c.buf.Reset()
11351115
}
@@ -1227,19 +1207,6 @@ func (c *runCache) builderRunTest(b *work.Builder, a *work.Action) error {
12271207

12281208
mergeCoverProfile(cmd.Stdout, a.Objdir+"_cover_.out")
12291209

1230-
if err == nil && !testList && !outCheck.anyOutput {
1231-
// If a test does os.Exit(0) by accident, 'go test' may succeed
1232-
// and it can take a while for a human to notice the package's
1233-
// tests didn't actually pass.
1234-
//
1235-
// If a test binary ran without error, it should have at least
1236-
// printed something, such as a PASS line.
1237-
//
1238-
// The only exceptions are when no tests have run, and the
1239-
// -test.list flag, which just prints the names of tests
1240-
// matching a pattern.
1241-
err = fmt.Errorf("test binary succeeded but did not print anything")
1242-
}
12431210
if err == nil {
12441211
norun := ""
12451212
if !testShowPass && !testJSON {
@@ -1260,7 +1227,7 @@ func (c *runCache) builderRunTest(b *work.Builder, a *work.Action) error {
12601227
fmt.Fprintf(cmd.Stdout, "FAIL\t%s\t%s\n", a.Package.ImportPath, t)
12611228
}
12621229

1263-
if !buffered {
1230+
if cmd.Stdout != &buf {
12641231
buf.Reset() // cmd.Stdout was going to os.Stdout already
12651232
}
12661233
return nil

src/cmd/go/testdata/script/test_exit.txt

-152
This file was deleted.

src/cmd/internal/goobj/goobj_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ var (
2929
)
3030

3131
func TestMain(m *testing.M) {
32-
testenv.MainMust(testenv.HasGoBuild)
32+
if !testenv.HasGoBuild() {
33+
return
34+
}
3335

3436
if err := buildGoobj(); err != nil {
3537
fmt.Println(err)

src/cmd/nm/nm_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ func TestMain(m *testing.M) {
2626
}
2727

2828
func testMain(m *testing.M) int {
29-
testenv.MainMust(testenv.HasGoBuild)
29+
if !testenv.HasGoBuild() {
30+
return 0
31+
}
3032

3133
tmpDir, err := ioutil.TempDir("", "TestNM")
3234
if err != nil {

src/cmd/objdump/objdump_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ import (
2222
var tmp, exe string // populated by buildObjdump
2323

2424
func TestMain(m *testing.M) {
25-
testenv.MainMust(testenv.HasGoBuild)
25+
if !testenv.HasGoBuild() {
26+
return
27+
}
2628

2729
var exitcode int
2830
if err := buildObjdump(); err == nil {

src/go/build/deps_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ var pkgDeps = map[string][]string{
202202
"testing": {"L2", "flag", "fmt", "internal/race", "os", "runtime/debug", "runtime/pprof", "runtime/trace", "time"},
203203
"testing/iotest": {"L2", "log"},
204204
"testing/quick": {"L2", "flag", "fmt", "reflect", "time"},
205-
"internal/testenv": {"L2", "OS", "flag", "fmt", "testing", "syscall", "internal/cfg"},
205+
"internal/testenv": {"L2", "OS", "flag", "testing", "syscall", "internal/cfg"},
206206
"internal/lazyregexp": {"L2", "OS", "regexp"},
207207
"internal/lazytemplate": {"L2", "OS", "text/template"},
208208

src/internal/testenv/testenv.go

-9
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ package testenv
1313
import (
1414
"errors"
1515
"flag"
16-
"fmt"
1716
"internal/cfg"
1817
"os"
1918
"os/exec"
@@ -33,14 +32,6 @@ func Builder() string {
3332
return os.Getenv("GO_BUILDER_NAME")
3433
}
3534

36-
func MainMust(cond func() bool) {
37-
if !cond() {
38-
fmt.Println("testenv: warning: can't run any tests")
39-
fmt.Println("SKIP")
40-
os.Exit(0)
41-
}
42-
}
43-
4435
// HasGoBuild reports whether the current system can build programs with ``go build''
4536
// and then run them with os.StartProcess or exec.Command.
4637
func HasGoBuild() bool {

0 commit comments

Comments
 (0)