MCPcopy Index your code
hub / github.com/go-errors/errors / TestWrapPrefixError

Function TestWrapPrefixError

error_test.go:179–211  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

177}
178
179func TestWrapPrefixError(t *testing.T) {
180
181 e := func() error {
182 return WrapPrefix("hi", "prefix", 1)
183 }()
184
185 if e.Error() != "prefix: hi" {
186 t.Errorf("Constructor with a string failed")
187 }
188
189 if WrapPrefix(fmt.Errorf("yo"), "prefix", 0).Error() != "prefix: yo" {
190 t.Errorf("Constructor with an error failed")
191 }
192
193 prefixed := WrapPrefix(e, "prefix", 0)
194 original := e.(*Error)
195
196 if prefixed.Err != original.Err || !reflect.DeepEqual(prefixed.stack, original.stack) || !reflect.DeepEqual(prefixed.frames, original.frames) || prefixed.Error() != "prefix: prefix: hi" {
197 t.Errorf("Constructor with an Error failed")
198 }
199
200 if original.Error() == prefixed.Error() {
201 t.Errorf("WrapPrefix changed the original error")
202 }
203
204 if WrapPrefix(nil, "prefix", 0) != nil {
205 t.Errorf("Constructor with nil failed")
206 }
207
208 if !strings.HasSuffix(original.StackFrames()[0].File, "error_test.go") || strings.HasSuffix(original.StackFrames()[1].File, "error_test.go") {
209 t.Errorf("Skip failed")
210 }
211}
212
213func ExampleErrorf(x int) (int, error) {
214 if x%2 == 1 {

Callers

nothing calls this directly

Calls 3

WrapPrefixFunction · 0.85
StackFramesMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…