Note: The following tests verify the line, and assume that the test names are unique, and that they are the only tests in this file.
(t *testing.T)
| 19 | // Note: The following tests verify the line, and assume that the |
| 20 | // test names are unique, and that they are the only tests in this file. |
| 21 | func TestWrap_Line(t *testing.T) { |
| 22 | failed := errors.New("failed") |
| 23 | |
| 24 | tests := []struct { |
| 25 | name string |
| 26 | f func() error |
| 27 | }{ |
| 28 | { |
| 29 | name: "return Wrap", // @group |
| 30 | f: func() error { |
| 31 | return errtrace.Wrap(failed) // @trace |
| 32 | }, |
| 33 | }, |
| 34 | { |
| 35 | name: "Wrap to intermediate and return", // @group |
| 36 | f: func() (retErr error) { |
| 37 | wrapped := errtrace.Wrap(failed) // @trace |
| 38 | return wrapped |
| 39 | }, |
| 40 | }, |
| 41 | { |
| 42 | name: "Decorate error after Wrap", // @group |
| 43 | f: func() (retErr error) { |
| 44 | wrapped := errtrace.Wrap(failed) // @trace |
| 45 | return fmt.Errorf("got err: %w", wrapped) |
| 46 | }, |
| 47 | }, |
| 48 | { |
| 49 | name: "defer updates errTrace", // @group |
| 50 | f: func() (retErr error) { |
| 51 | defer func() { |
| 52 | retErr = errtrace.Wrap(retErr) // @trace |
| 53 | }() |
| 54 | |
| 55 | return failed |
| 56 | }, |
| 57 | }, |
| 58 | |
| 59 | // Test error creation helpers. |
| 60 | { |
| 61 | name: "New", // @group |
| 62 | f: func() (retErr error) { |
| 63 | return errtrace.New("test") // @trace |
| 64 | }, |
| 65 | }, |
| 66 | { |
| 67 | name: "Errorf with no error args", // @group |
| 68 | f: func() (retErr error) { |
| 69 | return errtrace.Errorf("test %v", 1) // @trace |
| 70 | }, |
| 71 | }, |
| 72 | { |
| 73 | name: "Errorf with wrapped error arg", // @group |
| 74 | f: func() (retErr error) { |
| 75 | err := errtrace.New("test1") // @trace |
| 76 | return errtrace.Errorf("test2: %w", err) // @trace |
| 77 | }, |
| 78 | }, |
nothing calls this directly
no test coverage detected