From e213c72fb9492a409bd0ed9620ca9aaaa96ddebe Mon Sep 17 00:00:00 2001 From: Katie Hockman Date: Tue, 28 Sep 2021 15:59:34 -0400 Subject: [PATCH] internal/fuzz: disconnect stdout and stderr from the worker This was useful for debugging while we were developing the feature, but is now causing extraneous prints that make the command output difficult to read. This change also prevents the go command from printing an extraneous "FAIL" when fuzzing is enabled. Fixes #48633 Fixes #46631 Change-Id: I636e65f305a20f6dcd843e62090ae228741a3725 Reviewed-on: https://go-review.googlesource.com/c/go/+/352892 Trust: Katie Hockman Run-TryBot: Katie Hockman Reviewed-by: Jay Conrod Reviewed-by: Bryan C. Mills TryBot-Result: Go Bot --- src/cmd/go/internal/test/test.go | 18 ++++++++++++++++-- src/internal/fuzz/worker.go | 2 -- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/cmd/go/internal/test/test.go b/src/cmd/go/internal/test/test.go index a6c8631a375..dc1bea505bd 100644 --- a/src/cmd/go/internal/test/test.go +++ b/src/cmd/go/internal/test/test.go @@ -1790,9 +1790,23 @@ func builderNoTest(b *work.Builder, ctx context.Context, a *work.Action) error { return nil } -// printExitStatus is the action for printing the exit status +// printExitStatus is the action for printing the final exit status. +// If we are running multiple test targets, print a final "FAIL" +// in case a failure in an early package has already scrolled +// off of the user's terminal. +// (See https://golang.org/issue/30507#issuecomment-470593235.) +// +// In JSON mode, we need to maintain valid JSON output and +// we assume that the test output is being parsed by a tool +// anyway, so the failure will not be missed and would be +// awkward to try to wedge into the JSON stream. +// +// In fuzz mode, we only allow a single package for now +// (see CL 350156 and https://golang.org/issue/46312), +// so there is no possibility of scrolling off and no need +// to print the final status. func printExitStatus(b *work.Builder, ctx context.Context, a *work.Action) error { - if !testJSON && len(pkgArgs) != 0 { + if !testJSON && testFuzz == "" && len(pkgArgs) != 0 { if base.GetExitStatus() != 0 { fmt.Println("FAIL") return nil diff --git a/src/internal/fuzz/worker.go b/src/internal/fuzz/worker.go index 5b24e575c03..1429decba83 100644 --- a/src/internal/fuzz/worker.go +++ b/src/internal/fuzz/worker.go @@ -331,8 +331,6 @@ func (w *worker) start() (err error) { cmd := exec.Command(w.binPath, w.args...) cmd.Dir = w.dir cmd.Env = w.env[:len(w.env):len(w.env)] // copy on append to ensure workers don't overwrite each other. - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr // Create the "fuzz_in" and "fuzz_out" pipes so we can communicate with // the worker. We don't use stdin and stdout, since the test binary may