1 // Copyright 2016 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
13 func f1(pan
bool) []uintptr {
14 return f2(pan
) // line 14
17 func f2(pan
bool) []uintptr {
18 return f3(pan
) // line 18
21 func f3(pan
bool) []uintptr {
23 panic("f3") // line 23
25 ret
:= make([]uintptr, 20)
26 return ret
[:runtime
.Callers(0, ret
)] // line 26
29 func testCallers(t
*testing
.T
, pcs
[]uintptr, pan
bool) {
30 m
:= make(map[string]int, len(pcs
))
31 frames
:= runtime
.CallersFrames(pcs
)
33 frame
, more
:= frames
.Next()
34 if frame
.Function
!= "" {
35 m
[frame
.Function
] = frame
.Line
44 seen
= append(seen
, k
)
46 t
.Logf("functions seen: %s", strings
.Join(seen
, " "))
62 for _
, w
:= range want
{
63 if got
:= m
["runtime_test."+w
.name
]; got
!= w
.line
{
64 t
.Errorf("%s is line %d, want %d", w
.name
, got
, w
.line
)
69 func TestCallers(t
*testing
.T
) {
70 testCallers(t
, f1(false), false)
73 func TestCallersPanic(t
*testing
.T
) {
75 if r
:= recover(); r
== nil {
76 t
.Fatal("did not panic")
78 pcs
:= make([]uintptr, 20)
79 pcs
= pcs
[:runtime
.Callers(0, pcs
)]
80 testCallers(t
, pcs
, true)