@@ -3,6 +3,9 @@ package stack
3
3
import (
4
4
"runtime"
5
5
"testing"
6
+ "github.com/dkushner/stack"
7
+ "strings"
8
+ "strconv"
6
9
)
7
10
8
11
func TestCaller (t * testing.T ) {
@@ -47,11 +50,53 @@ func TestTrace(t *testing.T) {
47
50
48
51
cs := fh .labyrinth ()
49
52
50
- lines := []int {43 , 33 , 48 }
53
+ lines := []int {46 , 36 , 51 }
51
54
52
55
for i , line := range lines {
53
56
if got , want := cs [i ].line (), line ; got != want {
54
57
t .Errorf ("got line[%d] == %v, want line[%d] == %v" , i , got , i , want )
55
58
}
56
59
}
57
60
}
61
+
62
+ // Test stack handling originating from a sigpanic.
63
+ func TestTracePanic (t * testing.T ) {
64
+ t .Parallel ()
65
+
66
+ defer func () {
67
+ if recover () != nil {
68
+ trace := stack .Trace ().TrimRuntime ()
69
+
70
+ if len (trace ) != 6 {
71
+ t .Errorf ("got len(trace) == %v, want %v" , len (trace ), 6 )
72
+ }
73
+
74
+ // Check frames in this file, the interceding frames are somewhat
75
+ // platform-dependent.
76
+ lines := []int64 {68 , 101 }
77
+
78
+ var local []int64
79
+ for _ , call := range trace {
80
+ parts := strings .Split (call .String (), ":" )
81
+ if parts [0 ] == "stackinternal_test.go" {
82
+ line , _ := strconv .ParseInt (parts [1 ], 10 , 32 )
83
+ local = append (local , line )
84
+ }
85
+ }
86
+
87
+ if len (local ) != 2 {
88
+ t .Errorf ("expected %v local frames but got %v" , 2 , len (local ))
89
+ }
90
+
91
+ for i , line := range lines {
92
+ if got , want := local [i ], line ; got != want {
93
+ t .Errorf ("got line[%d] == %v, want line[%d] == %v" , i , got , i , want )
94
+ }
95
+ }
96
+ }
97
+ }()
98
+
99
+ // Initiate a sigpanic.
100
+ var x * uintptr
101
+ _ = * x
102
+ }
0 commit comments