]> Cypherpunks repositories - gostls13.git/commitdiff
testing: use runtime/debug to format panics
authorRuss Cox <rsc@golang.org>
Mon, 13 Feb 2012 04:39:40 +0000 (23:39 -0500)
committerRuss Cox <rsc@golang.org>
Mon, 13 Feb 2012 04:39:40 +0000 (23:39 -0500)
Among other things, this avoids putting a testing.go:nnn:
prefix on every line of the stack trace.

R=golang-dev, r, dsymonds, r
CC=golang-dev
https://golang.org/cl/5651081

src/pkg/runtime/debug/stack_test.go
src/pkg/testing/testing.go

index 94293bb934b512591c5711d26458bf1faab5b72e..f1a307579cff7b6334130d0dab6ef5d48328608e 100644 (file)
@@ -2,9 +2,10 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-package debug
+package debug_test
 
 import (
+       . "runtime/debug"
        "strings"
        "testing"
 )
index d907843c9131fc71608536e342c628ad4eb4ac59..5e43f0f8e47c8c93ac8e6ad05684f76de57291ca 100644 (file)
@@ -71,6 +71,7 @@ import (
        "fmt"
        "os"
        "runtime"
+       "runtime/debug"
        "runtime/pprof"
        "strconv"
        "strings"
@@ -225,19 +226,6 @@ func (c *common) Fatalf(format string, args ...interface{}) {
        c.FailNow()
 }
 
-// TODO(dsymonds): Consider hooking into runtime·traceback instead.
-func (c *common) stack() {
-       for i := 2; ; i++ { // Caller we care about is the user, 2 frames up
-               pc, file, line, ok := runtime.Caller(i)
-               f := runtime.FuncForPC(pc)
-               if !ok || f == nil {
-                       break
-               }
-               c.Logf("%s:%d (0x%x)", file, line, pc)
-               c.Logf("\t%s", f.Name())
-       }
-}
-
 // Parallel signals that this test is to be run in parallel with (and only with) 
 // other parallel tests in this CPU group.
 func (t *T) Parallel() {
@@ -260,11 +248,12 @@ func tRunner(t *T, test *InternalTest) {
        // a call to runtime.Goexit, record the duration and send
        // a signal saying that the test is done.
        defer func() {
-               // Consider any uncaught panic a failure.
-               if err := recover(); err != nil {
-                       t.failed = true
-                       t.Log(err)
-                       t.stack()
+               if false {
+                       // Log and recover from panic instead of aborting binary.
+                       if err := recover(); err != nil {
+                               t.failed = true
+                               t.Logf("%s\n%s", err, debug.Stack())
+                       }
                }
 
                t.duration = time.Now().Sub(t.start)