| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package errors | 5 package errors |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "errors" | 8 "errors" |
| 9 "sync" | 9 "sync" |
| 10 "testing" | 10 "testing" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 Convey("Fix passes through", t, func() { | 58 Convey("Fix passes through", t, func() { |
| 59 e := errors.New("unique") | 59 e := errors.New("unique") |
| 60 So(Fix(e), ShouldEqual, e) | 60 So(Fix(e), ShouldEqual, e) |
| 61 }) | 61 }) |
| 62 } | 62 } |
| 63 | 63 |
| 64 func TestLazyMultiError(t *testing.T) { | 64 func TestLazyMultiError(t *testing.T) { |
| 65 t.Parallel() | 65 t.Parallel() |
| 66 | 66 |
| 67 Convey("Test LazyMultiError", t, func() { | 67 Convey("Test LazyMultiError", t, func() { |
| 68 » » lme := LazyMultiError{Size: 10} | 68 » » lme := NewLazyMultiError(10) |
| 69 So(lme.Get(), ShouldEqual, nil) | 69 So(lme.Get(), ShouldEqual, nil) |
| 70 | 70 |
| 71 e := errors.New("sup") | 71 e := errors.New("sup") |
| 72 lme.Assign(6, e) | 72 lme.Assign(6, e) |
| 73 So(lme.Get(), ShouldResemble, | 73 So(lme.Get(), ShouldResemble, |
| 74 MultiError{nil, nil, nil, nil, nil, nil, e, nil, nil, ni
l}) | 74 MultiError{nil, nil, nil, nil, nil, nil, e, nil, nil, ni
l}) |
| 75 | 75 |
| 76 lme.Assign(2, e) | 76 lme.Assign(2, e) |
| 77 So(lme.Get(), ShouldResemble, | 77 So(lme.Get(), ShouldResemble, |
| 78 MultiError{nil, nil, e, nil, nil, nil, e, nil, nil, nil}
) | 78 MultiError{nil, nil, e, nil, nil, nil, e, nil, nil, nil}
) |
| 79 | 79 |
| 80 So(func() { lme.Assign(20, e) }, ShouldPanic) | 80 So(func() { lme.Assign(20, e) }, ShouldPanic) |
| 81 | 81 |
| 82 Convey("Try to freak out the race detector", func() { | 82 Convey("Try to freak out the race detector", func() { |
| 83 » » » lme := LazyMultiError{Size: 64} | 83 » » » lme := NewLazyMultiError(64) |
| 84 Convey("all nils", func() { | 84 Convey("all nils", func() { |
| 85 wg := sync.WaitGroup{} | 85 wg := sync.WaitGroup{} |
| 86 for i := 0; i < 64; i++ { | 86 for i := 0; i < 64; i++ { |
| 87 wg.Add(1) | 87 wg.Add(1) |
| 88 go func(i int) { | 88 go func(i int) { |
| 89 lme.Assign(i, nil) | 89 lme.Assign(i, nil) |
| 90 wg.Done() | 90 wg.Done() |
| 91 }(i) | 91 }(i) |
| 92 } | 92 } |
| 93 wg.Wait() | 93 wg.Wait() |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 wg.Wait() | 129 wg.Wait() |
| 130 me := make(MultiError, 64) | 130 me := make(MultiError, 64) |
| 131 for i := range me { | 131 for i := range me { |
| 132 me[i] = wow | 132 me[i] = wow |
| 133 } | 133 } |
| 134 So(lme.Get(), ShouldResemble, me) | 134 So(lme.Get(), ShouldResemble, me) |
| 135 }) | 135 }) |
| 136 }) | 136 }) |
| 137 }) | 137 }) |
| 138 } | 138 } |
| OLD | NEW |