OSDN Git Service

new repo
[bytom/vapor.git] / vendor / github.com / go-stack / stack / stackinternal_test.go
1 package stack
2
3 import (
4         "runtime"
5         "testing"
6 )
7
8 func TestCaller(t *testing.T) {
9         t.Parallel()
10
11         c := Caller(0)
12         _, file, line, ok := runtime.Caller(0)
13         line--
14         if !ok {
15                 t.Fatal("runtime.Caller(0) failed")
16         }
17
18         if got, want := c.file(), file; got != want {
19                 t.Errorf("got file == %v, want file == %v", got, want)
20         }
21
22         if got, want := c.line(), line; got != want {
23                 t.Errorf("got line == %v, want line == %v", got, want)
24         }
25 }
26
27 type fholder struct {
28         f func() CallStack
29 }
30
31 func (fh *fholder) labyrinth() CallStack {
32         for {
33                 return fh.f()
34         }
35         panic("this line only needed for go 1.0")
36 }
37
38 func TestTrace(t *testing.T) {
39         t.Parallel()
40
41         fh := fholder{
42                 f: func() CallStack {
43                         cs := Trace()
44                         return cs
45                 },
46         }
47
48         cs := fh.labyrinth()
49
50         lines := []int{43, 33, 48}
51
52         for i, line := range lines {
53                 if got, want := cs[i].line(), line; got != want {
54                         t.Errorf("got line[%d] == %v, want line[%d] == %v", i, got, i, want)
55                 }
56         }
57 }