fork of go-gitdiff with jj support
1package gitdiff
2
3import (
4 "errors"
5 "strings"
6 "testing"
7)
8
9func assertError(t *testing.T, expected interface{}, actual error, action string) {
10 if actual == nil {
11 t.Fatalf("expected error %s, but got nil", action)
12 }
13
14 switch exp := expected.(type) {
15 case bool:
16 if !exp {
17 t.Fatalf("unexpected error %s: %v", action, actual)
18 }
19 case string:
20 if !strings.Contains(actual.Error(), exp) {
21 t.Fatalf("incorrect error %s: %q does not contain %q", action, actual.Error(), exp)
22 }
23 case error:
24 if !errors.Is(actual, exp) {
25 t.Fatalf("incorrect error %s: expected %T (%v), actual: %T (%v)", action, exp, exp, actual, actual)
26 }
27 default:
28 t.Fatalf("unsupported expected error type: %T", exp)
29 }
30}