(t *testing.T)
| 59 | } |
| 60 | |
| 61 | func TestFormat(t *testing.T) { |
| 62 | tt := testutils.T{t} |
| 63 | |
| 64 | baseErr := goErr.New("woo") |
| 65 | const woo = `woo` |
| 66 | const waawoo = `waa: woo` |
| 67 | testCases := []struct { |
| 68 | name string |
| 69 | err error |
| 70 | expFmtSimple string |
| 71 | expFmtVerbose string |
| 72 | }{ |
| 73 | {"assert", |
| 74 | assert.WithAssertionFailure(baseErr), |
| 75 | woo, ` |
| 76 | woo |
| 77 | (1) assertion failure |
| 78 | Wraps: (2) woo |
| 79 | Error types: (1) *assert.withAssertionFailure (2) *errors.errorString`}, |
| 80 | |
| 81 | {"assert + wrapper", |
| 82 | assert.WithAssertionFailure(&werrFmt{baseErr, "waa"}), |
| 83 | waawoo, ` |
| 84 | waa: woo |
| 85 | (1) assertion failure |
| 86 | Wraps: (2) waa |
| 87 | | -- this is waa's |
| 88 | | multi-line payload |
| 89 | Wraps: (3) woo |
| 90 | Error types: (1) *assert.withAssertionFailure (2) *assert_test.werrFmt (3) *errors.errorString`}, |
| 91 | |
| 92 | {"wrapper + assert", |
| 93 | &werrFmt{assert.WithAssertionFailure(baseErr), "waa"}, |
| 94 | waawoo, ` |
| 95 | waa: woo |
| 96 | (1) waa |
| 97 | | -- this is waa's |
| 98 | | multi-line payload |
| 99 | Wraps: (2) assertion failure |
| 100 | Wraps: (3) woo |
| 101 | Error types: (1) *assert_test.werrFmt (2) *assert.withAssertionFailure (3) *errors.errorString`}, |
| 102 | } |
| 103 | |
| 104 | for _, test := range testCases { |
| 105 | tt.Run(test.name, func(tt testutils.T) { |
| 106 | err := test.err |
| 107 | |
| 108 | // %s is simple formatting |
| 109 | tt.CheckStringEqual(fmt.Sprintf("%s", err), test.expFmtSimple) |
| 110 | |
| 111 | // %v is simple formatting too, for compatibility with the past. |
| 112 | tt.CheckStringEqual(fmt.Sprintf("%v", err), test.expFmtSimple) |
| 113 | |
| 114 | // %q is always like %s but quotes the result. |
| 115 | ref := fmt.Sprintf("%q", test.expFmtSimple) |
| 116 | tt.CheckStringEqual(fmt.Sprintf("%q", err), ref) |
| 117 | |
| 118 | // %+v is the verbose mode. |
nothing calls this directly
no test coverage detected
searching dependent graphs…