(t *testing.T)
| 177 | } |
| 178 | |
| 179 | func TestFormat(t *testing.T) { |
| 180 | tt := testutils.T{t} |
| 181 | |
| 182 | baseErr := goErr.New("woo") |
| 183 | const woo = `woo` |
| 184 | const waawoo = `waa: woo` |
| 185 | testCases := []struct { |
| 186 | name string |
| 187 | err error |
| 188 | expFmtSimple string |
| 189 | expFmtVerbose string |
| 190 | }{ |
| 191 | {"keys", |
| 192 | domains.WithDomain(baseErr, domains.NoDomain), |
| 193 | woo, ` |
| 194 | woo |
| 195 | (1) error domain: <none> |
| 196 | Wraps: (2) woo |
| 197 | Error types: (1) *domains.withDomain (2) *errors.errorString`}, |
| 198 | |
| 199 | {"keys + wrapper", |
| 200 | domains.WithDomain(&werrFmt{baseErr, "waa"}, domains.NoDomain), |
| 201 | waawoo, ` |
| 202 | waa: woo |
| 203 | (1) error domain: <none> |
| 204 | Wraps: (2) waa |
| 205 | | -- this is waa's |
| 206 | | multi-line payload |
| 207 | Wraps: (3) woo |
| 208 | Error types: (1) *domains.withDomain (2) *domains_test.werrFmt (3) *errors.errorString`}, |
| 209 | |
| 210 | {"wrapper + keys", |
| 211 | &werrFmt{domains.WithDomain(baseErr, domains.NoDomain), "waa"}, |
| 212 | waawoo, ` |
| 213 | waa: woo |
| 214 | (1) waa |
| 215 | | -- this is waa's |
| 216 | | multi-line payload |
| 217 | Wraps: (2) error domain: <none> |
| 218 | Wraps: (3) woo |
| 219 | Error types: (1) *domains_test.werrFmt (2) *domains.withDomain (3) *errors.errorString`}, |
| 220 | } |
| 221 | |
| 222 | for _, test := range testCases { |
| 223 | tt.Run(test.name, func(tt testutils.T) { |
| 224 | err := test.err |
| 225 | |
| 226 | // %s is simple formatting |
| 227 | tt.CheckStringEqual(fmt.Sprintf("%s", err), test.expFmtSimple) |
| 228 | |
| 229 | // %v is simple formatting too, for compatibility with the past. |
| 230 | tt.CheckStringEqual(fmt.Sprintf("%v", err), test.expFmtSimple) |
| 231 | |
| 232 | // %q is always like %s but quotes the result. |
| 233 | ref := fmt.Sprintf("%q", test.expFmtSimple) |
| 234 | tt.CheckStringEqual(fmt.Sprintf("%q", err), ref) |
| 235 | |
| 236 | // %+v is the verbose mode. |
nothing calls this directly
no test coverage detected
searching dependent graphs…