MCPcopy Create free account
hub / github.com/chain/txvm / TestWrap

Function TestWrap

errors/errors_test.go:10–48  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

8)
9
10func TestWrap(t *testing.T) {
11 err := errors.New("0")
12 err1 := Wrap(err, "1")
13 err2 := Wrap(err1, "2")
14 err3 := Wrap(err2)
15
16 if got := Root(err1); got != err {
17 t.Fatalf("Root(%v)=%v want %v", err1, got, err)
18 }
19
20 if got := Root(err2); got != err {
21 t.Fatalf("Root(%v)=%v want %v", err2, got, err)
22 }
23
24 if err2.Error() != "2: 1: 0" {
25 t.Fatalf("err msg = %s want '2: 1: 0'", err2.Error())
26 }
27
28 if err3.Error() != "2: 1: 0" {
29 t.Fatalf("err msg = %s want '2: 1: 0'", err3.Error())
30 }
31
32 stack := Stack(err1)
33 frame, ok := stack.Next()
34 if !ok {
35 t.Fatalf("len(stack) = 0 want > 0")
36 }
37 if !strings.Contains(frame.Function, "TestWrap") {
38 t.Fatalf("first stack frame should contain \"TestWrap\": %v", frame.Function)
39 }
40
41 if !reflect.DeepEqual(Stack(err2), Stack(err1)) {
42 t.Errorf("err2 stack got %v want %v", Stack(err2), Stack(err1))
43 }
44
45 if !reflect.DeepEqual(Stack(err3), Stack(err1)) {
46 t.Errorf("err3 stack got %v want %v", Stack(err3), Stack(err1))
47 }
48}
49
50func TestWrapNil(t *testing.T) {
51 var err error

Callers

nothing calls this directly

Calls 5

WrapFunction · 0.85
StackFunction · 0.85
ErrorMethod · 0.80
ContainsMethod · 0.80
RootFunction · 0.70

Tested by

no test coverage detected