aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/nm
diff options
context:
space:
mode:
authorDaniel Martí <mvdan@mvdan.cc>2019-07-01 18:30:01 +0200
committerDaniel Martí <mvdan@mvdan.cc>2019-10-09 15:07:29 +0000
commit1fba10c999613e8c04cef7f1331ff0051bfa7057 (patch)
tree38bf78304637dbaec32bceeec585623809a93e83 /src/cmd/nm
parent38c4a7370670e6b73cbae192c7d3079c90203832 (diff)
downloadgo-1fba10c999613e8c04cef7f1331ff0051bfa7057.tar.gz
go-1fba10c999613e8c04cef7f1331ff0051bfa7057.zip
cmd/go: fail if a test binary exits with no output
For example, if a test calls os.Exit(0), that could trick a 'go test' run into not running some of the other tests, and thinking that they all succeeded. This can easily go unnoticed and cause developers headaches. Add a simple sanity check as part of 'go test': if the test binary succeeds and doesn't print anything, we should error, as something clearly went very wrong. This is done by inspecting each of the stdout writes from the spawned process, since we don't want to read the entirety of the output into a buffer. We need to introduce a "buffered" bool var, as there's now an io.Writer layer between cmd.Stdout and &buf. A few TestMain funcs in the standard library needed fixing, as they returned without printing anything as a means to skip testing the entire package. For that purpose add testenv.MainMust, which prints a warning and prints SKIP, similar to when -run matches no tests. Finally, add tests for both os.Exit(0) and os.Exit(1), both as part of TestMain and as part of a single test, and test that the various stdout modes still do the right thing. Fixes #29062. Change-Id: Ic6f8ef3387dfc64e4cd3e8f903d7ca5f5f38d397 Reviewed-on: https://go-review.googlesource.com/c/go/+/184457 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
Diffstat (limited to 'src/cmd/nm')
-rw-r--r--src/cmd/nm/nm_test.go4
1 files changed, 1 insertions, 3 deletions
diff --git a/src/cmd/nm/nm_test.go b/src/cmd/nm/nm_test.go
index dcd9f36005..018252793e 100644
--- a/src/cmd/nm/nm_test.go
+++ b/src/cmd/nm/nm_test.go
@@ -26,9 +26,7 @@ func TestMain(m *testing.M) {
}
func testMain(m *testing.M) int {
- if !testenv.HasGoBuild() {
- return 0
- }
+ testenv.MainMust(testenv.HasGoBuild)
tmpDir, err := ioutil.TempDir("", "TestNM")
if err != nil {