...
1
2
3
4
5 package debug_test
6
7 import (
8 . "runtime/debug"
9 "strings"
10 "testing"
11 )
12
13 type T int
14
15 func (t *T) ptrmethod() []byte {
16 return Stack()
17 }
18 func (t T) method() []byte {
19 return t.ptrmethod()
20 }
21
22
40 func TestStack(t *testing.T) {
41 b := T(0).method()
42 lines := strings.Split(string(b), "\n")
43 if len(lines) < 6 {
44 t.Fatal("too few lines")
45 }
46 n := 0
47 frame := func(line, code string) {
48 check(t, lines[n], code)
49 n++
50 check(t, lines[n], line)
51 n++
52 }
53 n++
54 frame("src/runtime/debug/stack.go", "runtime/debug.Stack")
55 frame("src/runtime/debug/stack_test.go", "runtime/debug_test.(*T).ptrmethod")
56 frame("src/runtime/debug/stack_test.go", "runtime/debug_test.T.method")
57 frame("src/runtime/debug/stack_test.go", "runtime/debug_test.TestStack")
58 frame("src/testing/testing.go", "")
59 }
60
61 func check(t *testing.T, line, has string) {
62 if !strings.Contains(line, has) {
63 t.Errorf("expected %q in %q", has, line)
64 }
65 }
66
View as plain text