summaryrefslogtreecommitdiff
path: root/vendor/github.com/go-stack/stack/stack-go19_test.go
diff options
context:
space:
mode:
authorKali Kaneko (leap communications) <kali@leap.se>2019-01-12 18:39:45 +0100
committerRuben Pollan <meskio@sindominio.net>2019-01-17 12:30:32 +0100
commitb1247d2d0d51108c910a73891ff3116e5f032ab1 (patch)
treee9948964f0bfb1ad2df3bc7bad02aa1f41ccfbd8 /vendor/github.com/go-stack/stack/stack-go19_test.go
parentefcb8312e31b5c2261b1a1e95ace55b322cfcc27 (diff)
[pkg] all your deps are vendored to us
Diffstat (limited to 'vendor/github.com/go-stack/stack/stack-go19_test.go')
-rw-r--r--vendor/github.com/go-stack/stack/stack-go19_test.go67
1 files changed, 67 insertions, 0 deletions
diff --git a/vendor/github.com/go-stack/stack/stack-go19_test.go b/vendor/github.com/go-stack/stack/stack-go19_test.go
new file mode 100644
index 0000000..d7aeea2
--- /dev/null
+++ b/vendor/github.com/go-stack/stack/stack-go19_test.go
@@ -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
+}