forked from cucumber/godog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stacktrace_test.go
50 lines (42 loc) · 942 Bytes
/
stacktrace_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package godog
import (
"fmt"
"runtime"
"strings"
"testing"
)
func trimLineSpaces(s string) string {
var res []string
for _, ln := range strings.Split(s, "\n") {
res = append(res, strings.TrimSpace(ln))
}
return strings.Join(res, "\n")
}
func callstack1() *stack {
return callstack2()
}
func callstack2() *stack {
return callstack3()
}
func callstack3() *stack {
const depth = 4
var pcs [depth]uintptr
n := runtime.Callers(1, pcs[:])
var st stack = pcs[0:n]
return &st
}
func TestStacktrace(t *testing.T) {
err := &traceError{
msg: "err msg",
stack: callstack1(),
}
expect := "err msg"
actual := fmt.Sprintf("%s", err)
if expect != actual {
t.Fatalf("expected formatted trace error message to be: %s, but got %s", expect, actual)
}
actual = trimLineSpaces(fmt.Sprintf("%+v", err))
if strings.Index(actual, "stacktrace_test.go") == -1 {
t.Fatalf("does not have stacktrace in actual: %s", actual)
}
}