@@ -130,6 +130,9 @@ func TestFprint(t *testing.T) {
130130 }, {
131131 err : Wrap (Wrap (x , "message" ), "another message" ),
132132 want : "github.com/pkg/errors/errors_test.go:131: another message\n github.com/pkg/errors/errors_test.go:131: message\n github.com/pkg/errors/errors_test.go:106: error\n " ,
133+ }, {
134+ err : Wrapf (x , "message" ),
135+ want : "github.com/pkg/errors/errors_test.go:134: message\n github.com/pkg/errors/errors_test.go:106: error\n " ,
133136 }}
134137
135138 for i , tt := range tests {
@@ -141,3 +144,29 @@ func TestFprint(t *testing.T) {
141144 }
142145 }
143146}
147+
148+ func TestWrapfNil (t * testing.T ) {
149+ got := Wrapf (nil , "no error" )
150+ if got != nil {
151+ t .Errorf ("Wrapf(nil, \" no error\" ): got %#v, expected nil" , got )
152+ }
153+ }
154+
155+ func TestWrapf (t * testing.T ) {
156+ tests := []struct {
157+ err error
158+ message string
159+ want string
160+ }{
161+ {io .EOF , "read error" , "read error: EOF" },
162+ {Wrapf (io .EOF , "read error without format specifiers" ), "client error" , "client error: read error without format specifiers: EOF" },
163+ {Wrapf (io .EOF , "read error with %d format specifier" , 1 ), "client error" , "client error: read error with 1 format specifier: EOF" },
164+ }
165+
166+ for _ , tt := range tests {
167+ got := Wrapf (tt .err , tt .message ).Error ()
168+ if got != tt .want {
169+ t .Errorf ("Wrapf(%v, %q): got: %v, want %v" , tt .err , tt .message , got , tt .want )
170+ }
171+ }
172+ }
0 commit comments