From 2abe5ceb1968edb882c8318af674c4133dd0bb75 Mon Sep 17 00:00:00 2001 From: Sean Liao Date: Mon, 10 Mar 2025 19:41:09 +0000 Subject: [PATCH] testing: warn against calling Log after a test completes Fixes #40343 Change-Id: Id266f4b57131e9e148e5aa2be86b67fe6d73b20a Reviewed-on: https://go-review.googlesource.com/c/go/+/656415 Auto-Submit: Ian Lance Taylor LUCI-TryBot-Result: Go LUCI Reviewed-by: Alan Donovan Reviewed-by: Ian Lance Taylor --- src/testing/testing.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/testing/testing.go b/src/testing/testing.go index 8b0915a0ef..471046e89d 100644 --- a/src/testing/testing.go +++ b/src/testing/testing.go @@ -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...)) -- 2.50.0