Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library futures_test; | 5 library futures_test; |
| 6 import 'package:async_helper/async_helper.dart'; | 6 import 'package:async_helper/async_helper.dart'; |
| 7 import "package:expect/expect.dart"; | 7 import "package:expect/expect.dart"; |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 | 9 |
| 10 Future testWaitEmpty() { | 10 Future testWaitEmpty() { |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 112 c2.completeError('incorrect error 1'); | 112 c2.completeError('incorrect error 1'); |
| 113 | 113 |
| 114 return Future.wait(futures).then((_) { | 114 return Future.wait(futures).then((_) { |
| 115 throw 'incorrect error 2'; | 115 throw 'incorrect error 2'; |
| 116 }).catchError((error, stackTrace) { | 116 }).catchError((error, stackTrace) { |
| 117 Expect.equals('correct error', error); | 117 Expect.equals('correct error', error); |
| 118 Expect.isNotNull(stackTrace); | 118 Expect.isNotNull(stackTrace); |
| 119 }); | 119 }); |
| 120 } | 120 } |
| 121 | 121 |
| 122 Future testEagerWait() { | |
|
floitsch
2013/11/19 10:50:34
test not called.
Lasse Reichstein Nielsen
2013/11/20 09:29:28
Whoops. Fixed.
| |
| 123 Completer c1 = new Completer(); | |
| 124 Completer c2 = new Completer(); | |
| 125 List<Future> futures = <Future>[c1.future, c2.future]; | |
| 126 Future waited = Future.wait(futures, eagerError: true); | |
| 127 var result = waited.then((v) { throw "should not be called"; }, | |
| 128 onError: (e, s) { | |
|
floitsch
2013/11/19 10:50:34
also test that stack trace is passed through.
Lasse Reichstein Nielsen
2013/11/20 09:29:28
Will do.
| |
| 129 Expect.equals(e, 42); | |
| 130 returntrue; | |
|
floitsch
2013/11/19 10:50:34
return true
Lasse Reichstein Nielsen
2013/11/20 09:29:28
Quite obvious that it isn't called too. :(
| |
| 131 }); | |
| 132 c1.completeError(42); | |
| 133 return result; | |
| 134 } | |
| 135 | |
| 122 Future testForEachEmpty() { | 136 Future testForEachEmpty() { |
| 123 return Future.forEach([], (_) { | 137 return Future.forEach([], (_) { |
| 124 throw 'should not be called'; | 138 throw 'should not be called'; |
| 125 }); | 139 }); |
| 126 } | 140 } |
| 127 | 141 |
| 128 Future testForEach() { | 142 Future testForEach() { |
| 129 var seen = <int>[]; | 143 var seen = <int>[]; |
| 130 return Future.forEach([1, 2, 3, 4, 5], (n) { | 144 return Future.forEach([1, 2, 3, 4, 5], (n) { |
| 131 seen.add(n); | 145 seen.add(n); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 160 futures.add(testForEachEmpty()); | 174 futures.add(testForEachEmpty()); |
| 161 futures.add(testForEach()); | 175 futures.add(testForEach()); |
| 162 futures.add(testForEachWithException()); | 176 futures.add(testForEachWithException()); |
| 163 | 177 |
| 164 asyncStart(); | 178 asyncStart(); |
| 165 Future.wait(futures).then((List list) { | 179 Future.wait(futures).then((List list) { |
| 166 Expect.equals(11, list.length); | 180 Expect.equals(11, list.length); |
| 167 asyncEnd(); | 181 asyncEnd(); |
| 168 }); | 182 }); |
| 169 } | 183 } |
| OLD | NEW |