]> Cypherpunks repositories - gostls13.git/commitdiff
testing: diagnose buggy tests that panic(nil)
authorRuss Cox <rsc@golang.org>
Wed, 22 Jan 2014 21:04:50 +0000 (16:04 -0500)
committerRuss Cox <rsc@golang.org>
Wed, 22 Jan 2014 21:04:50 +0000 (16:04 -0500)
Fixes #6546.

LGTM=dave, bradfitz, r
R=r, dave, bradfitz
CC=golang-codereviews
https://golang.org/cl/55780043

doc/go1.3.txt
src/pkg/testing/testing.go

index dfb21f4fd9d781249214dbe67c9d6a21c95a948f..4c25375d09ce2bda41b11a59dbfaa51cb8212fd9 100644 (file)
@@ -3,3 +3,4 @@ liblink: pull linker i/o into separate liblink C library (CL 35790044)
 misc/dist: renamed misc/makerelease (CL 39920043)
 runtime: output how long goroutines are blocked (CL 50420043)
 syscall: add NewCallbackCDecl to use for windows callbacks (CL 36180044)
+testing: diagnose buggy tests that panic(nil) (CL 55780043)
index 52dc166dd93c2417da92322fe3e47482e95fcc09..a0b55f4a57e88b92db4ce6fed0be799504ab1f29 100644 (file)
@@ -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