$ cd $GOROOT/src/testing
$ go test
root
root
root
root
PASS
$
The root prints have been happening since Go 1.14.
There is a test in sub_test.go that calls b.Run directly
with a benchmark named "root", which triggers the print.
Silence them.
Change-Id: I2f0c186f04c6139bc24fab0e91975fcf0a8e80fc
Reviewed-on: https://go-review.googlesource.com/c/go/+/421437
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
}
}
+// If hideStdoutForTesting is true, Run does not print the benchName.
+// This avoids a spurious print during 'go test' on package testing itself,
+// which invokes b.Run in its own tests (see sub_test.go).
+var hideStdoutForTesting = false
+
// Run benchmarks f as a subbenchmark with the given name. It reports
// whether there were any failures.
//
}
})
- fmt.Println(benchName)
+ if !hideStdoutForTesting {
+ fmt.Println(benchName)
+ }
}
if sub.run1() {
}
},
}}
+ hideStdoutForTesting = true
+ defer func() {
+ hideStdoutForTesting = false
+ }()
for _, tc := range testCases {
t.Run(tc.desc, func(t *T) {
var ok bool