1 package emperror
2
3 import (
4 "fmt"
5 "io"
6 "testing"
7
8 "github.com/pkg/errors"
9 )
10
11 func TestWrap_Format(t *testing.T) {
12 testError := Wrap(io.EOF, "error1")
13
14 tests := []struct {
15 error
16 format string
17 want string
18 }{{
19 Wrap(errors.New("error"), "error2"),
20 "%s",
21 "error2: error",
22 }, {
23 Wrap(errors.New("error"), "error2"),
24 "%v",
25 "error2: error",
26 }, {
27 Wrap(errors.New("error"), "error2"),
28 "%+v",
29 "error\n" +
30 "github.com/goph/emperror.TestWrap_Format\n" +
31 "\t.+/wrap_test.go:27",
32 }, {
33 Wrap(io.EOF, "error"),
34 "%s",
35 "error: EOF",
36 }, {
37 Wrap(io.EOF, "error"),
38 "%v",
39 "error: EOF",
40 }, {
41 Wrap(io.EOF, "error"),
42 "%+v",
43 "EOF\n" +
44 "error\n" +
45 "github.com/goph/emperror.TestWrap_Format\n" +
46 "\t.+/wrap_test.go:41",
47 }, {
48 Wrap(Wrap(io.EOF, "error1"), "error2"),
49 "%+v",
50 "EOF\n" +
51 "error1\n" +
52 "github.com/goph/emperror.TestWrap_Format\n" +
53 "\t.+/wrap_test.go:48\n",
54 }, {
55 Wrap(fmt.Errorf("error with space"), "context"),
56 "%q",
57 `"context: error with space"`,
58 }, {
59 Wrap(testError, "error2"),
60 "%+v",
61 "EOF\n" +
62 "error1\n" +
63 "github.com/goph/emperror.TestWrap_Format\n" +
64 "\t.+/wrap_test.go:12\n",
65 }}
66
67 for i, tt := range tests {
68 testFormatRegexp(t, i, tt.error, tt.format, tt.want)
69 }
70 }
71
View as plain text