Files
bluekeyes-go-gitdiff/gitdiff/assert_test.go
T
Billy Keyes f0da09b10f Add ParsePatchHeader and related types (#6)
This function parses patch headers (the preamble returned by the
existing Parse function) to extract information about the commit that
generated the patch. This is useful when patches are an interchange
format and this library is applying commits generated elsewhere.

Because of the variety of header formats, parsing is fairly lenient and
best-effort, although certain invalid input does cause errors.

This also extracts some test utilities from the apply tests for reuse.
2020-04-18 22:21:55 -07:00

31 lines
710 B
Go

package gitdiff
import (
"errors"
"strings"
"testing"
)
func assertError(t *testing.T, expected interface{}, 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)
}
}