MCPcopy Index your code
hub / github.com/bracesdev/errtrace / TestUnwrapFrame

Function TestUnwrapFrame

unwrap_test.go:11–64  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

9)
10
11func TestUnwrapFrame(t *testing.T) {
12 giveErr := errors.New("great sadness")
13
14 t.Run("not wrapped", func(t *testing.T) {
15 _, inner, ok := UnwrapFrame(giveErr)
16 if got, want := ok, false; got != want {
17 t.Errorf("ok: got %v, want %v", got, want)
18 }
19
20 if got, want := inner, giveErr; got != want {
21 t.Errorf("inner: got %v, want %v", inner, giveErr)
22 }
23 })
24
25 t.Run("wrapped", func(t *testing.T) {
26 wrapped := Wrap(giveErr)
27 frame, inner, ok := UnwrapFrame(wrapped)
28 if got, want := ok, true; got != want {
29 t.Errorf("ok: got %v, want %v", got, want)
30 }
31
32 if got, want := inner, giveErr; got != want {
33 t.Errorf("inner: got %v, want %v", inner, giveErr)
34 }
35
36 if got, want := frame.Function, ".TestUnwrapFrame.func2"; !strings.HasSuffix(got, want) {
37 t.Errorf("frame.Func: got %q, does not contain %q", got, want)
38 }
39
40 if got, want := filepath.Base(frame.File), "unwrap_test.go"; got != want {
41 t.Errorf("frame.File: got %v, want %v", got, want)
42 }
43 })
44
45 t.Run("custom error", func(t *testing.T) {
46 wrapped := wrapCustomTrace(giveErr)
47 frame, inner, ok := UnwrapFrame(wrapped)
48 if got, want := ok, true; got != want {
49 t.Errorf("ok: got %v, want %v", got, want)
50 }
51
52 if got, want := inner, giveErr; got != want {
53 t.Errorf("inner: got %v, want %v", inner, giveErr)
54 }
55
56 if got, want := frame.Function, ".wrapCustomTrace"; !strings.HasSuffix(got, want) {
57 t.Errorf("frame.Func: got %q, does not contain %q", got, want)
58 }
59
60 if got, want := filepath.Base(frame.File), "unwrap_test.go"; got != want {
61 t.Errorf("frame.File: got %v, want %v", got, want)
62 }
63 })
64}
65
66func TestUnwrapFrame_badPC(t *testing.T) {
67 giveErr := errors.New("great sadness")

Callers

nothing calls this directly

Calls 4

UnwrapFrameFunction · 0.85
WrapFunction · 0.85
wrapCustomTraceFunction · 0.85
RunMethod · 0.80

Tested by

no test coverage detected