MCPcopy Index your code
hub / github.com/cockroachdb/errors / TestFormat

Function TestFormat

assert/assert_test.go:61–124  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

59}
60
61func 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, `
76woo
77(1) assertion failure
78Wraps: (2) woo
79Error types: (1) *assert.withAssertionFailure (2) *errors.errorString`},
80
81 {"assert + wrapper",
82 assert.WithAssertionFailure(&werrFmt{baseErr, "waa"}),
83 waawoo, `
84waa: woo
85(1) assertion failure
86Wraps: (2) waa
87 | -- this is waa's
88 | multi-line payload
89Wraps: (3) woo
90Error types: (1) *assert.withAssertionFailure (2) *assert_test.werrFmt (3) *errors.errorString`},
91
92 {"wrapper + assert",
93 &werrFmt{assert.WithAssertionFailure(baseErr), "waa"},
94 waawoo, `
95waa: woo
96(1) waa
97 | -- this is waa's
98 | multi-line payload
99Wraps: (2) assertion failure
100Wraps: (3) woo
101Error 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.

Callers

nothing calls this directly

Calls 3

RunMethod · 0.95
CheckStringEqualMethod · 0.95
WithAssertionFailureFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…