]> Cypherpunks repositories - gostls13.git/commitdiff
testing: warn against calling Log after a test completes
authorSean Liao <sean@liao.dev>
Mon, 10 Mar 2025 19:41:09 +0000 (19:41 +0000)
committerGopher Robot <gobot@golang.org>
Mon, 10 Mar 2025 22:02:26 +0000 (15:02 -0700)
Fixes #40343

Change-Id: Id266f4b57131e9e148e5aa2be86b67fe6d73b20a
Reviewed-on: https://go-review.googlesource.com/c/go/+/656415
Auto-Submit: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
src/testing/testing.go

index 8b0915a0ef79010b4c7ff4f8f9e8b8134110f4fc..471046e89d948e5f876fca95796399170c7c0051 100644 (file)
@@ -1083,6 +1083,7 @@ func (c *common) logDepth(s string, depth int) {
 // and records the text in the error log. For tests, the text will be printed only if
 // the test fails or the -test.v flag is set. For benchmarks, the text is always
 // printed to avoid having performance depend on the value of the -test.v flag.
+// It is an error to call Log after a test or benchmark returns.
 func (c *common) Log(args ...any) {
        c.checkFuzzFn("Log")
        c.log(fmt.Sprintln(args...))
@@ -1093,6 +1094,7 @@ func (c *common) Log(args ...any) {
 // tests, the text will be printed only if the test fails or the -test.v flag is
 // set. For benchmarks, the text is always printed to avoid having performance
 // depend on the value of the -test.v flag.
+// It is an error to call Logf after a test or benchmark returns.
 func (c *common) Logf(format string, args ...any) {
        c.checkFuzzFn("Logf")
        c.log(fmt.Sprintf(format, args...))