func TestErrorMethodList(t *testing.T) { err := errors.Append(errors.New("ab"), errors.New("cd")) if err.Error() != "ab"+"\n"+"cd" { t.Errorf(`Append(New("ab"), New("cd")) = %q, want %q`, err.Error(), "ab\ncd") } }
func TestNewEqualList(t *testing.T) { // Different allocations should not be equal. if errors.Append(errors.New("ab"), errors.New("cd")) == errors.Append(errors.New("ab"), errors.New("cd")) { t.Errorf(`Append(New("ab"), New("cd")) == Append(New("ab"), New("cd"))`) } // Same allocation should be equal to itself (not crash). err := errors.Append(errors.New("jk"), errors.New("lm")) if err != err { t.Errorf(`err != err`) } }
func TestNewEqual(t *testing.T) { // Different allocations should not be equal. if errors.New("abc") == errors.New("abc") { t.Errorf(`New("abc") == New("abc")`) } if errors.New("abc") == errors.New("xyz") { t.Errorf(`New("abc") == New("xyz")`) } // Same allocation should be equal to itself (not crash). err := errors.New("jkl") if err != err { t.Errorf(`err != err`) } }
func ExampleNew() { err := errors.New("emit macho dwarf: elf header corrupted") if err != nil { fmt.Print(err) } // Output: emit macho dwarf: elf header corrupted }
"io" "sethwklein.net/go/errors" "testing" ) var mockOS = struct { Create func(string) (io.WriteCloser, error) }{ func(_ string) (io.WriteCloser, error) { return mockFile{}, nil }, } type mockFile struct{} var mockError = errors.New("mock error") func (_ mockFile) Close() error { return mockError } func (_ mockFile) Write(data []byte) (n int, err error) { return len(data), nil } func brokenAppendWriteFile(filename string, data []byte) error { f, err := mockOS.Create(filename) if err != nil { return err } defer func() {
func TestErrorMethod(t *testing.T) { err := errors.New("abc") if err.Error() != "abc" { t.Errorf(`New("abc").Error() = %q, want %q`, err.Error(), "abc") } }