mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
testing: capture panics, present them, and mark the test as a failure.
R=r CC=golang-dev https://golang.org/cl/5633044
This commit is contained in:
parent
e066db3acb
commit
cee920225d
1 changed files with 20 additions and 0 deletions
|
|
@ -225,6 +225,19 @@ func (c *common) Fatalf(format string, args ...interface{}) {
|
||||||
c.FailNow()
|
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)
|
// Parallel signals that this test is to be run in parallel with (and only with)
|
||||||
// other parallel tests in this CPU group.
|
// other parallel tests in this CPU group.
|
||||||
func (t *T) Parallel() {
|
func (t *T) Parallel() {
|
||||||
|
|
@ -247,6 +260,13 @@ func tRunner(t *T, test *InternalTest) {
|
||||||
// a call to runtime.Goexit, record the duration and send
|
// a call to runtime.Goexit, record the duration and send
|
||||||
// a signal saying that the test is done.
|
// a signal saying that the test is done.
|
||||||
defer func() {
|
defer func() {
|
||||||
|
// Consider any uncaught panic a failure.
|
||||||
|
if err := recover(); err != nil {
|
||||||
|
t.failed = true
|
||||||
|
t.Log(err)
|
||||||
|
t.stack()
|
||||||
|
}
|
||||||
|
|
||||||
t.duration = time.Now().Sub(t.start)
|
t.duration = time.Now().Sub(t.start)
|
||||||
t.signal <- t
|
t.signal <- t
|
||||||
}()
|
}()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue