Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathstack-go19_test.go
More file actions
Latest commit
67 lines (56 loc) · 1.45 KB
/
Copy pathstack-go19_test.go
File metadata and controls
67 lines (56 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// +build go1.9
package stack_test
import (
"runtime"
"testing"
"github.com/go-stack/stack"
)
funcTestCallerInlinedPanic(t*testing.T) {
t.Parallel()
varlineint
deferfunc() {
ifrecover() !=nil {
varpcs [32]uintptr
n:=runtime.Callers(1, pcs[:])
frames:=runtime.CallersFrames(pcs[:n])
// count frames to runtime.sigpanic
panicIdx:=0
for {
f, more:=frames.Next()
iff.Function=="runtime.sigpanic" {
break
}
panicIdx++
if!more {
t.Fatal("no runtime.sigpanic entry on the stack")
}
}
c:=stack.Caller(panicIdx)
ifgot, want:=c.Frame().Function, "runtime.sigpanic"; got!=want {
t.Errorf("sigpanic frame: got name == %v, want name == %v", got, want)
}
c1:=stack.Caller(panicIdx+1)
ifgot, want:=c1.Frame().Function, "github.com/go-stack/stack_test.inlinablePanic"; got!=want {
t.Errorf("TestCallerInlinedPanic frame: got name == %v, want name == %v", got, want)
}
ifgot, want:=c1.Frame().Line, line; got!=want {
t.Errorf("TestCallerInlinedPanic frame: got line == %v, want line == %v", got, want)
}
}
}()
doPanic(t, &line)
t.Fatal("failed to panic")
}
funcdoPanic(t*testing.T, panicLine*int) {
_, _, line, ok:=runtime.Caller(0)
*panicLine=line+11// adjust to match line of panic below
if!ok {
t.Fatal("runtime.Caller(0) failed")
}
inlinablePanic()
}
funcinlinablePanic() {
// Initiate a sigpanic.
varx*uintptr
_=*x
}