(t *testing.T)
| 177 | } |
| 178 | |
| 179 | func 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 | |
| 213 | func ExampleErrorf(x int) (int, error) { |
| 214 | if x%2 == 1 { |
nothing calls this directly
no test coverage detected
searching dependent graphs…