| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 future_delayed_error_test; | 5 library future_delayed_error_test; |
| 6 | 6 |
| 7 import "package:expect/expect.dart"; | 7 import "package:expect/expect.dart"; |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 import 'dart:isolate'; | 9 import 'dart:isolate'; |
| 10 | 10 |
| 11 testImmediateError() { | 11 testImmediateError() { |
| 12 // An open ReceivePort keeps the VM running. If the error-handler below is not | 12 // An open ReceivePort keeps the VM running. If the error-handler below is not |
| 13 // executed then the test will fail with a timeout. | 13 // executed then the test will fail with a timeout. |
| 14 var port = new ReceivePort(); | 14 var port = new ReceivePort(); |
| 15 var future = new Future.immediateError("error"); | 15 var future = new Future.error("error"); |
| 16 future.catchError((error) { | 16 future.catchError((error) { |
| 17 port.close(); | 17 port.close(); |
| 18 Expect.equals(error, "error"); | 18 Expect.equals(error, "error"); |
| 19 }); | 19 }); |
| 20 } | 20 } |
| 21 | 21 |
| 22 Future get completedFuture { | 22 Future get completedFuture { |
| 23 var completer = new Completer(); | 23 var completer = new Completer(); |
| 24 completer.completeError("foobar"); | 24 completer.completeError("foobar"); |
| 25 return completer.future; | 25 return completer.future; |
| 26 } | 26 } |
| 27 | 27 |
| 28 testDelayedError() { | 28 testDelayedError() { |
| 29 var port = new ReceivePort(); | 29 var port = new ReceivePort(); |
| 30 completedFuture.catchError((error) { | 30 completedFuture.catchError((error) { |
| 31 port.close(); | 31 port.close(); |
| 32 Expect.equals(error, "foobar"); | 32 Expect.equals(error, "foobar"); |
| 33 }); | 33 }); |
| 34 } | 34 } |
| 35 | 35 |
| 36 main() { | 36 main() { |
| 37 testImmediateError(); | 37 testImmediateError(); |
| 38 testDelayedError(); | 38 testDelayedError(); |
| 39 } | 39 } |
| 40 | 40 |
| OLD | NEW |