mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
testing: diagnose buggy tests that panic(nil)
Fixes #6546. LGTM=dave, bradfitz, r R=r, dave, bradfitz CC=golang-codereviews https://golang.org/cl/55780043
This commit is contained in:
parent
1351638314
commit
ae56210708
2 changed files with 8 additions and 1 deletions
|
|
@ -376,10 +376,15 @@ func tRunner(t *T, test *InternalTest) {
|
|||
// returned normally or because a test failure triggered
|
||||
// a call to runtime.Goexit, record the duration and send
|
||||
// a signal saying that the test is done.
|
||||
var finished bool
|
||||
defer func() {
|
||||
t.duration = time.Now().Sub(t.start)
|
||||
// If the test panicked, print any test output before dying.
|
||||
if err := recover(); err != nil {
|
||||
err := recover()
|
||||
if !finished && err == nil {
|
||||
err = fmt.Errorf("test executed panic(nil)")
|
||||
}
|
||||
if err != nil {
|
||||
t.Fail()
|
||||
t.report()
|
||||
panic(err)
|
||||
|
|
@ -389,6 +394,7 @@ func tRunner(t *T, test *InternalTest) {
|
|||
|
||||
t.start = time.Now()
|
||||
test.F(t)
|
||||
finished = true
|
||||
}
|
||||
|
||||
// An internal function but exported because it is cross-package; part of the implementation
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue