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 BenchmarkWalkPanic(b *testing.B) { var list error for i := 1; i <= listLen; i++ { list = errors.Append(list, fmt.Errorf("number %v", i)) } b.ResetTimer() for i := 0; i < b.N; i++ { func() { defer func() { if e := recover(); e != nil { panic(e) } }() n := attentionSpan i := 0 errors.Walk(list, func(e error) { _ = e i++ if i >= n { panic(nil) } }) }() } }
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 BenchmarkWalkN(b *testing.B) { var list error for i := 1; i <= listLen; i++ { list = errors.Append(list, fmt.Errorf("number %v", i)) } b.ResetTimer() for i := 0; i < b.N; i++ { errors.WalkN(list, attentionSpan, func(e error) { _ = e }) } }
func brokenAppendWriteFile(filename string, data []byte) error { f, err := mockOS.Create(filename) if err != nil { return err } defer func() { err = errors.Append(err, f.Close()) }() n, err := f.Write(data) if err == nil && n < len(data) { err = io.ErrShortWrite } return err }
func ExampleWalkN() { var list error for i := 1; i <= 1000; i++ { list = errors.Append(list, fmt.Errorf("number %v", i)) } errors.WalkN(list, 3, func(e error) { // In real code, this should generally use os.Stderr, but // https://code.google.com/p/go/issues/detail?id=4550 // broke that for examples. fmt.Fprintln(os.Stdout, e) }) // Output: // number 1 // number 2 // number 3 }
func BenchmarkWalkIgnore(b *testing.B) { var list error for i := 1; i <= listLen; i++ { list = errors.Append(list, fmt.Errorf("number %v", i)) } b.ResetTimer() for i := 0; i < b.N; i++ { n := attentionSpan i := 0 errors.Walk(list, func(e error) { i++ if i > n { return } _ = e }) } }
func BenchmarkNil(b *testing.B) { var list error for i := 0; i < b.N; i++ { list = errors.Append(list, nil) } }
func BenchmarkAppend(b *testing.B) { var list error for i := 0; i < b.N; i++ { list = errors.Append(list, fmt.Errorf("number %v", i)) } }