]> Cypherpunks repositories - gostls13.git/commit
testing: explain how SkipNow and FailNow stop execution
authorAlberto Donizetti <alb.donizetti@gmail.com>
Wed, 2 Aug 2017 16:22:21 +0000 (18:22 +0200)
committerAlberto Donizetti <alb.donizetti@gmail.com>
Wed, 9 Aug 2017 11:47:38 +0000 (11:47 +0000)
commitbd74fd3abb27b9b857ca77c9ee648299045ce963
treef8fbe6bc718f3383a90e4cea298f51d19a994114
parent6b6b9f69fd38ca285b33917d6201dbcb11ca0324
testing: explain how SkipNow and FailNow stop execution

SkipNow and FailNow must be called from the goroutine running the
test. This is already documented, but it's easy to call them by
mistake when writing subtests. In the following:

  func TestPanic(t *testing.T) {
    t.Run("", func(t2 *testing.T) {
  t.FailNow()    // BAD: should be t2.FailNow()
})
  }

the FailNow call on the outer t *testing.T correctly triggers a panic

  panic: test executed panic(nil) or runtime.Goexit

The error message confuses users (see issues #17421, #21175) because
there is no way to trace back the relevant part of the message ("test
executed ... runtime.Goexit") to a bad FailNow call without checking
the testing package source code and finding out that FailNow calls
runtime.Goexit.

To help users debug the panic message, mention in the SkipNow and
FailNow documentation that they stop execution by calling
runtime.Goexit.

Fixes #21175

Change-Id: I0a3e5f768e72b464474380cfffbf2b67396ac1b5
Reviewed-on: https://go-review.googlesource.com/52770
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/testing/testing.go