|
@@ -107,8 +107,8 @@ func TestNew(t *testing.T) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// This test should work for any go version
|
|
|
func TestIs(t *testing.T) {
|
|
func TestIs(t *testing.T) {
|
|
|
-
|
|
|
|
|
if Is(nil, io.EOF) {
|
|
if Is(nil, io.EOF) {
|
|
|
t.Errorf("nil is an error")
|
|
t.Errorf("nil is an error")
|
|
|
}
|
|
}
|
|
@@ -128,51 +128,6 @@ func TestIs(t *testing.T) {
|
|
|
if Is(io.EOF, fmt.Errorf("io.EOF")) {
|
|
if Is(io.EOF, fmt.Errorf("io.EOF")) {
|
|
|
t.Errorf("io.EOF is fmt.Errorf")
|
|
t.Errorf("io.EOF is fmt.Errorf")
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- custErr := errorWithCustomIs{
|
|
|
|
|
- Key: "TestForFun",
|
|
|
|
|
- Err: io.EOF,
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- shouldMatch := errorWithCustomIs{
|
|
|
|
|
- Key: "TestForFun",
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- shouldNotMatch := errorWithCustomIs{Key: "notOk"}
|
|
|
|
|
-
|
|
|
|
|
- if !Is(custErr, shouldMatch) {
|
|
|
|
|
- t.Errorf("custErr is not a TestForFun customError")
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if Is(custErr, shouldNotMatch) {
|
|
|
|
|
- t.Errorf("custErr is a notOk customError")
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if !Is(custErr, New(shouldMatch)) {
|
|
|
|
|
- t.Errorf("custErr is not a New(TestForFun customError)")
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if Is(custErr, New(shouldNotMatch)) {
|
|
|
|
|
- t.Errorf("custErr is a New(notOk customError)")
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if !Is(New(custErr), shouldMatch) {
|
|
|
|
|
- t.Errorf("New(custErr) is not a TestForFun customError")
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if Is(New(custErr), shouldNotMatch) {
|
|
|
|
|
- t.Errorf("New(custErr) is a notOk customError")
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if !Is(New(custErr), New(shouldMatch)) {
|
|
|
|
|
- t.Errorf("New(custErr) is not a New(TestForFun customError)")
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if Is(New(custErr), New(shouldNotMatch)) {
|
|
|
|
|
- t.Errorf("New(custErr) is a New(notOk customError)")
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func TestWrapError(t *testing.T) {
|
|
func TestWrapError(t *testing.T) {
|
|
@@ -361,17 +316,3 @@ func callersToFrames(callers []uintptr) []runtime.Frame {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-type errorWithCustomIs struct {
|
|
|
|
|
- Key string
|
|
|
|
|
- Err error
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-func (ewci errorWithCustomIs) Error() string {
|
|
|
|
|
- return "["+ewci.Key+"]: " + ewci.Err.Error()
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-func (ewci errorWithCustomIs) Is(target error) bool {
|
|
|
|
|
- matched, ok := target.(errorWithCustomIs)
|
|
|
|
|
- return ok && matched.Key == ewci.Key
|
|
|
|
|
-}
|
|
|