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 "fmt" | 8 "fmt" |
9 "testing" | 9 "testing" |
10 | 10 |
(...skipping 17 matching lines...) Expand all Loading... |
28 So(err.(*MarkedError).Orig, ShouldEqual, c) | 28 So(err.(*MarkedError).Orig, ShouldEqual, c) |
29 | 29 |
30 So(f(nil), ShouldBeNil) | 30 So(f(nil), ShouldBeNil) |
31 }) | 31 }) |
32 } | 32 } |
33 | 33 |
34 func TestMultiError(t *testing.T) { | 34 func TestMultiError(t *testing.T) { |
35 Convey("MultiError works", t, func() { | 35 Convey("MultiError works", t, func() { |
36 var me error = MultiError{fmt.Errorf("hello"), fmt.Errorf("bob")
} | 36 var me error = MultiError{fmt.Errorf("hello"), fmt.Errorf("bob")
} |
37 | 37 |
38 » » So(me.Error(), ShouldEqual, `["hello" "bob"]`) | 38 » » So(me.Error(), ShouldEqual, `hello (and 1 other error)`) |
39 | 39 |
40 Convey("MultiErrorFromErrors with errors works", func() { | 40 Convey("MultiErrorFromErrors with errors works", func() { |
41 mec := make(chan error, 5) | 41 mec := make(chan error, 5) |
| 42 mec <- MakeMarkFn("multiErr")("one-off") |
| 43 mec <- nil |
42 mec <- fmt.Errorf("what") | 44 mec <- fmt.Errorf("what") |
43 mec <- nil | |
44 mec <- MakeMarkFn("multiErr")("one-off") | |
45 close(mec) | 45 close(mec) |
46 | 46 |
47 err := MultiErrorFromErrors(mec) | 47 err := MultiErrorFromErrors(mec) |
48 » » » So(err.Error(), ShouldEqual, `["what" "multiErr - errors
_test.go:44 - one-off"]`) | 48 » » » So(err.Error(), ShouldEqual, `multiErr - errors_test.go:
42 - one-off (and 1 other error)`) |
49 }) | 49 }) |
50 | 50 |
51 Convey("MultiErrorFromErrors with nil works", func() { | 51 Convey("MultiErrorFromErrors with nil works", func() { |
52 So(MultiErrorFromErrors(nil), ShouldBeNil) | 52 So(MultiErrorFromErrors(nil), ShouldBeNil) |
53 | 53 |
54 c := make(chan error) | 54 c := make(chan error) |
55 close(c) | 55 close(c) |
56 So(MultiErrorFromErrors(c), ShouldBeNil) | 56 So(MultiErrorFromErrors(c), ShouldBeNil) |
57 | 57 |
58 c = make(chan error, 4) | 58 c = make(chan error, 4) |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 fmt.Printf("got: %s len=%d\n", err, len(err.(MultiError))) | 90 fmt.Printf("got: %s len=%d\n", err, len(err.(MultiError))) |
91 | 91 |
92 errCh = make(chan error, 10) | 92 errCh = make(chan error, 10) |
93 errCh <- nil // and if the channel only has nils | 93 errCh <- nil // and if the channel only has nils |
94 close(errCh) | 94 close(errCh) |
95 | 95 |
96 err = MultiErrorFromErrors(errCh) // then it returns nil | 96 err = MultiErrorFromErrors(errCh) // then it returns nil |
97 fmt.Printf("got: %v\n", err) | 97 fmt.Printf("got: %v\n", err) |
98 | 98 |
99 // Output: | 99 // Output: |
100 » // got: ["what"] len=1 | 100 » // got: what len=1 |
101 // got: <nil> | 101 // got: <nil> |
102 } | 102 } |
OLD | NEW |