1
0
mirror of https://github.com/golang/go synced 2024-11-18 01:34:44 -07:00
go/src/testing
Alberto Donizetti bd74fd3abb 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>
2017-08-09 11:47:38 +00:00
..
internal/testdeps
iotest
quick doc: mention testing/quick RNG seeding change in Go 1.9 notes 2017-06-27 22:41:49 +00:00
allocs_test.go
allocs.go
benchmark_test.go
benchmark.go testing: revert CL 36791's conditional ReadMemStats 2017-06-30 16:49:29 +00:00
cover.go
example.go
export_test.go
helper_test.go
helperfuncs_test.go
match_test.go testing: harmonize handling of prefix-matched benchmarks 2017-06-20 14:19:05 +00:00
match.go testing: harmonize handling of prefix-matched benchmarks 2017-06-20 14:19:05 +00:00
sub_test.go testing: always ReadMemStats before first benchmark run 2017-06-28 20:47:26 +00:00
testing_test.go
testing.go testing: explain how SkipNow and FailNow stop execution 2017-08-09 11:47:38 +00:00