@@ -3,6 +3,9 @@ package stack
33import (
44 "runtime"
55 "testing"
6+ "github.com/dkushner/stack"
7+ "strings"
8+ "strconv"
69)
710
811func TestCaller (t * testing.T ) {
@@ -47,11 +50,53 @@ func TestTrace(t *testing.T) {
4750
4851 cs := fh .labyrinth ()
4952
50- lines := []int {43 , 33 , 48 }
53+ lines := []int {46 , 36 , 51 }
5154
5255 for i , line := range lines {
5356 if got , want := cs [i ].line (), line ; got != want {
5457 t .Errorf ("got line[%d] == %v, want line[%d] == %v" , i , got , i , want )
5558 }
5659 }
5760}
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