-
Notifications
You must be signed in to change notification settings - Fork 17.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
testing: Calling t.Fatal in a subtest panics #17421
Comments
This appears to me to be a bug in the code in func TestParser(t *testing.T) {
cover := append(gorootTestFiles, ycover)
_ = t.Run("Yacc", func(*testing.T) { testParserYacc(t, cover) }) &&
t.Run("GOROOT", func(*testing.T) { testParser(t, cover) }) &&
t.Run("States", testParserStates)
} The func TestParser(t *testing.T) {
cover := append(gorootTestFiles, ycover)
_ = t.Run("Yacc", func(t *testing.T) { testParserYacc(t, cover) }) &&
t.Run("GOROOT", func(t *testing.T) { testParser(t, cover) }) &&
t.Run("States", testParserStates)
} |
@spenczar So simple ;-)
It's a trap. Thank you! |
Change https://golang.org/cl/52770 mentions this issue: |
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>
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go version go1.7.1 linux/amd64
What operating system and processor architecture are you using (
go env
)?What did you do?
What did you expect to see?
Something like
What did you see instead?
Additional information
Running with
-race
produces the same output.The text was updated successfully, but these errors were encountered: