func TestEquality(t *testing.T) { if ErrFmt.Error() != "stringer out" { t.Error("wrong output for FmtErr") return } if !errors.Equal(ErrStd, ErrStd) { t.Error("ErrStd equality error") return } if !errors.Equal(ErrFoo, ErrFoo) { t.Error("ErrFoo equality error") return } if errors.Equal(ErrStd, ErrStd2) { t.Error("ErrStd and ErrStd2 found to be equal") return } if errors.Equal(ErrStd, ErrFmt) { t.Error("ErrStd and ErrFmt found to be equal") return } if errors.IsA(ErrStd, ErrFmt) { t.Error("ErrStd and ErrFmt returned true for IsA") return } }
func TestFooWrappingBar(t *testing.T) { err := FooWrappingBar() if !errors.Equal(err, ErrFoo) || !errors.Equal(ErrFoo, err) { t.Error("Foo not determined to be equal to an errors.Error based on itself") return } if !errors.IsA(err, ErrFoo) { t.Error("Error that wraps Bar not determined to contain it") return } if err.Error() != "Fooey. Barf" { t.Error("String genertation not correct for FooWrappingBar") return } }
func TestFooWrappingStdError(t *testing.T) { err := FooWrappingStdError() if !errors.Equal(err, ErrFoo) || !errors.Equal(ErrFoo, err) { t.Error("Foo not determined to be equal to an errors.Error based on itself") return } if !errors.IsA(err, ErrStd) { t.Error("Error that wraps standard library not determined to contain the standard") return } if err.Error() != "Fooey. This is a stanard error from the standard library." { t.Error("String genertation not correct for FooWrappingStdError") return } }