]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: avoid crashing on 'go test -n'
authorThan McIntosh <thanm@google.com>
Thu, 9 Nov 2017 20:41:45 +0000 (15:41 -0500)
committerThan McIntosh <thanm@google.com>
Thu, 9 Nov 2017 21:55:42 +0000 (21:55 +0000)
Fix a buglet in the go command support for 'go test -n': check for
nil output buffer in action routine.

Fixes #22644

Change-Id: I2566e3bb3d53d0324c4ddd6fec5d30224bf290df
Reviewed-on: https://go-review.googlesource.com/76710
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
src/cmd/go/go_test.go
src/cmd/go/internal/test/test.go

index b49c558f4a0ce4bc26439ad6d1a54fb659e5849d..ecaa3afeae7b7cfd99b36df358db0a25ae154496 100644 (file)
@@ -5060,3 +5060,12 @@ func TestGcflagsPatterns(t *testing.T) {
        tg.grepStderr("compile.* -N .*-p reflect", "did not build reflect with -N flag")
        tg.grepStderrNot("compile.* -N .*-p fmt", "incorrectly built fmt with -N flag")
 }
+
+// Issue 22644
+func TestGoTestMinusN(t *testing.T) {
+       // Intent here is to verify that 'go test -n' works without crashing.
+       // This reuses flag_test.go, but really any test would do.
+       tg := testgo(t)
+       defer tg.cleanup()
+       tg.run("test", "testdata/flag_test.go", "-n", "-args", "-v=7")
+}
index c8e843cef27c41cf9f8ebab3b2554929e25da205..529c7e93f636620a271deb174edd0569f503ba37 100644 (file)
@@ -1472,8 +1472,10 @@ func builderCleanTest(b *work.Builder, a *work.Action) error {
 func builderPrintTest(b *work.Builder, a *work.Action) error {
        clean := a.Deps[0]
        run := clean.Deps[0]
-       os.Stdout.Write(run.TestOutput.Bytes())
-       run.TestOutput = nil
+       if run.TestOutput != nil {
+               os.Stdout.Write(run.TestOutput.Bytes())
+               run.TestOutput = nil
+       }
        return nil
 }