mirror of
https://github.com/bluekeyes/go-gitdiff
synced 2026-06-08 13:18:30 +00:00
08f3e635d6
This only updates to Go 1.21 baseline, which is what the module still specifies as the minimum version. I'll need to run this again when moving to Go 1.25 or 1.26 as minimum.
31 lines
702 B
Go
31 lines
702 B
Go
package gitdiff
|
|
|
|
import (
|
|
"errors"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func assertError(t *testing.T, expected any, actual error, action string) {
|
|
if actual == nil {
|
|
t.Fatalf("expected error %s, but got nil", action)
|
|
}
|
|
|
|
switch exp := expected.(type) {
|
|
case bool:
|
|
if !exp {
|
|
t.Fatalf("unexpected error %s: %v", action, actual)
|
|
}
|
|
case string:
|
|
if !strings.Contains(actual.Error(), exp) {
|
|
t.Fatalf("incorrect error %s: %q does not contain %q", action, actual.Error(), exp)
|
|
}
|
|
case error:
|
|
if !errors.Is(actual, exp) {
|
|
t.Fatalf("incorrect error %s: expected %T (%v), actual: %T (%v)", action, exp, exp, actual, actual)
|
|
}
|
|
default:
|
|
t.Fatalf("unsupported expected error type: %T", exp)
|
|
}
|
|
}
|