(t *testing.T)
| 57 | func (nilError) Error() string { return "nil error" } |
| 58 | |
| 59 | func TestCause(t *testing.T) { |
| 60 | x := New("error") |
| 61 | tests := []struct { |
| 62 | err error |
| 63 | want error |
| 64 | }{{ |
| 65 | // nil error is nil |
| 66 | err: nil, |
| 67 | want: nil, |
| 68 | }, { |
| 69 | // explicit nil error is nil |
| 70 | err: (error)(nil), |
| 71 | want: nil, |
| 72 | }, { |
| 73 | // typed nil is nil |
| 74 | err: (*nilError)(nil), |
| 75 | want: (*nilError)(nil), |
| 76 | }, { |
| 77 | // uncaused error is unaffected |
| 78 | err: io.EOF, |
| 79 | want: io.EOF, |
| 80 | }, { |
| 81 | // caused error returns cause |
| 82 | err: Wrap(io.EOF, "ignored"), |
| 83 | want: io.EOF, |
| 84 | }, { |
| 85 | err: x, // return from errors.New |
| 86 | want: x, |
| 87 | }, { |
| 88 | WithMessage(nil, "whoops"), |
| 89 | nil, |
| 90 | }, { |
| 91 | WithMessage(io.EOF, "whoops"), |
| 92 | io.EOF, |
| 93 | }, { |
| 94 | WithStack(nil), |
| 95 | nil, |
| 96 | }, { |
| 97 | WithStack(io.EOF), |
| 98 | io.EOF, |
| 99 | }} |
| 100 | |
| 101 | for i, tt := range tests { |
| 102 | got := Cause(tt.err) |
| 103 | if !reflect.DeepEqual(got, tt.want) { |
| 104 | t.Errorf("test %d: got %#v, want %#v", i+1, got, tt.want) |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | func TestWrapfNil(t *testing.T) { |
| 110 | got := Wrapf(nil, "no error") |
nothing calls this directly
no test coverage detected
searching dependent graphs…