-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
313 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,13 @@ | ||
language: go | ||
sudo: false | ||
go: | ||
- 1.2 | ||
- 1.3 | ||
- 1.4 | ||
- 1.5 | ||
- 1.6 | ||
- 1.7 | ||
- 1.8 | ||
- 1.9 | ||
- tip | ||
|
||
before_install: | ||
- go get github.com/mattn/goveralls | ||
- go get golang.org/x/tools/cmd/cover | ||
|
||
script: | ||
- goveralls -service=travis-ci |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// +build go1.9 | ||
|
||
package stack_test | ||
|
||
import ( | ||
"runtime" | ||
"testing" | ||
|
||
"github.com/go-stack/stack" | ||
) | ||
|
||
func TestCallerInlinedPanic(t *testing.T) { | ||
t.Parallel() | ||
|
||
var line int | ||
|
||
defer func() { | ||
if recover() != nil { | ||
var pcs [32]uintptr | ||
n := runtime.Callers(1, pcs[:]) | ||
frames := runtime.CallersFrames(pcs[:n]) | ||
// count frames to runtime.sigpanic | ||
panicIdx := 0 | ||
for { | ||
f, more := frames.Next() | ||
if f.Function == "runtime.sigpanic" { | ||
break | ||
} | ||
panicIdx++ | ||
if !more { | ||
t.Fatal("no runtime.sigpanic entry on the stack") | ||
} | ||
} | ||
|
||
c := stack.Caller(panicIdx) | ||
if got, want := c.Frame().Function, "runtime.sigpanic"; got != want { | ||
t.Errorf("sigpanic frame: got name == %v, want name == %v", got, want) | ||
} | ||
|
||
c1 := stack.Caller(panicIdx + 1) | ||
if got, want := c1.Frame().Function, "github.com/go-stack/stack_test.inlinablePanic"; got != want { | ||
t.Errorf("TestCallerInlinedPanic frame: got name == %v, want name == %v", got, want) | ||
} | ||
if got, want := c1.Frame().Line, line; got != want { | ||
t.Errorf("TestCallerInlinedPanic frame: got line == %v, want line == %v", got, want) | ||
} | ||
} | ||
}() | ||
|
||
doPanic(t, &line) | ||
t.Fatal("failed to panic") | ||
} | ||
|
||
func doPanic(t *testing.T, panicLine *int) { | ||
_, _, line, ok := runtime.Caller(0) | ||
*panicLine = line + 11 // adjust to match line of panic below | ||
if !ok { | ||
t.Fatal("runtime.Caller(0) failed") | ||
} | ||
inlinablePanic() | ||
} | ||
|
||
func inlinablePanic() { | ||
// Initiate a sigpanic. | ||
var x *uintptr | ||
_ = *x | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.