aboutsummaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorTim King <taking@google.com>2020-12-01 17:55:35 -0800
committerTim King <taking@google.com>2020-12-10 23:11:25 +0000
commit1fe891a937eae62ce396f3d7c7c6c472701acf0a (patch)
treee7d10accc570d5332d60963cbe91336e495177b3 /doc
parent6d3d3fb37fc51473f04ffb304cfab41c96a361a4 (diff)
downloadgo-1fe891a937eae62ce396f3d7c7c6c472701acf0a.tar.gz
go-1fe891a937eae62ce396f3d7c7c6c472701acf0a.zip
doc/go1.16: add vet release note for CL 235677
For #40700 Fixes #42895 Change-Id: I05b60f0d000512d5dddb3d61e0e695aa01943d6a Reviewed-on: https://go-review.googlesource.com/c/go/+/274617 Trust: Tim King <taking@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Diffstat (limited to 'doc')
-rw-r--r--doc/go1.16.html49
1 files changed, 46 insertions, 3 deletions
diff --git a/doc/go1.16.html b/doc/go1.16.html
index 44d9707c16..e0187effd7 100644
--- a/doc/go1.16.html
+++ b/doc/go1.16.html
@@ -283,12 +283,55 @@ Do not send CLs removing the interior tags from such phrases.
<h3 id="vet">Vet</h3>
-<p>
- TODO
+<h4 id="vet-string-int">New warning for invalid testing.T use in
+goroutines</h4>
- <!-- CL 235677: https://golang.org/cl/235677: cmd/vet: bring in pass to catch invalid uses of testing.T in goroutines -->
+<p><!-- CL 235677 -->
+ The vet tool now warns about invalid calls to the <code>testing.T</code>
+ method <code>Fatal</code> from within a goroutine created during the test.
+ This also warns on calls to <code>Fatalf</code>, <code>FailNow</code>, and
+ <code>Skip{,f,Now}</code> methods on <code>testing.T</code> tests or
+ <code>testing.B</code> benchmarks.
</p>
+<p>
+ Calls to these methods stop the execution of the created goroutine and not
+ the <code>Test*</code> or <code>Benchmark*</code> function. So these are
+ <a href="/pkg/testing/#T.FailNow">required</a> to be called by the goroutine
+ running the test or benchmark function. For example:
+</p>
+
+<pre>
+func TestFoo(t *testing.T) {
+ go func() {
+ if condition() {
+ t.Fatal("oops") // This exits the inner func instead of TestFoo.
+ }
+ ...
+ }()
+}
+</pre>
+
+<p>
+ Code calling <code>t.Fatal</code> (or a similar method) from a created
+ goroutine should be rewritten to signal the test failure using
+ <code>t.Error</code> and exit the goroutine early using an alternative
+ method, such as using a <code>return</code> statement. The previous example
+ could be rewritten as:
+</p>
+
+<pre>
+func TestFoo(t *testing.T) {
+ go func() {
+ if condition() {
+ t.Error("oops")
+ return
+ }
+ ...
+ }()
+}
+</pre>
+
<p><!-- CL 248686, CL 276372 -->
The vet tool now warns about amd64 assembly that clobbers the BP
register (the frame pointer) without saving and restoring it,