| 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_test; | 5 library future_test; |
| 6 | 6 |
| 7 import 'package:async_helper/async_helper.dart'; | 7 import 'package:async_helper/async_helper.dart'; |
| 8 import "package:expect/expect.dart"; | 8 import "package:expect/expect.dart"; |
| 9 import 'dart:async'; | 9 import 'dart:async'; |
| 10 | 10 |
| (...skipping 861 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 872 Expect.isTrue(index == 0 || index == 2, "$index"); | 872 Expect.isTrue(index == 0 || index == 2, "$index"); |
| 873 Expect.isFalse(uncaughts[index]); | 873 Expect.isFalse(uncaughts[index]); |
| 874 uncaughts[index] = true; | 874 uncaughts[index] = true; |
| 875 asyncEnd(); | 875 asyncEnd(); |
| 876 }); | 876 }); |
| 877 } | 877 } |
| 878 | 878 |
| 879 void testWaitSyncError() { | 879 void testWaitSyncError() { |
| 880 var cms = const Duration(milliseconds: 100); | 880 var cms = const Duration(milliseconds: 100); |
| 881 var cleanups = new List.filled(3, false); | 881 var cleanups = new List.filled(3, false); |
| 882 var uncaughts = new List.filled(3, false); | |
| 883 asyncStart(); | 882 asyncStart(); |
| 884 asyncStart(); | 883 asyncStart(); |
| 885 runZoned(() { | 884 runZoned(() { |
| 886 Future.wait(new Iterable.generate(5, (i) { | 885 Future.wait(new Iterable.generate(5, (i) { |
| 887 if (i != 3) return new Future.delayed(cms * (i + 1), () => i); | 886 if (i != 3) return new Future.delayed(cms * (i + 1), () => i); |
| 888 throw "throwing synchronously in iterable"; | 887 throw "throwing synchronously in iterable"; |
| 889 }), cleanUp: (index) { | 888 }), cleanUp: (index) { |
| 890 Expect.isFalse(cleanups[index]); | 889 Expect.isFalse(cleanups[index]); |
| 891 cleanups[index] = true; | 890 cleanups[index] = true; |
| 892 if (cleanups.every((x) => x)) asyncEnd(); | 891 if (cleanups.every((x) => x)) asyncEnd(); |
| 893 }); | 892 }); |
| 894 }, onError: (e, s) { | 893 }, onError: (e, s) { |
| 895 asyncEnd(); | 894 asyncEnd(); |
| 896 }); | 895 }); |
| 897 } | 896 } |
| 898 | 897 |
| 898 void testWaitSyncError2() { |
| 899 asyncStart(); |
| 900 Future.wait([null]).catchError((e, st) { |
| 901 // Makes sure that the `catchError` is invoked. |
| 902 // Regression test: an earlier version of `Future.wait` would propagate |
| 903 // the error too soon for the code to install an error handler. |
| 904 // `testWaitSyncError` didn't show this problem, because the `runZoned` |
| 905 // was already installed. |
| 906 asyncEnd(); |
| 907 }); |
| 908 } |
| 909 |
| 899 void testBadFuture() { | 910 void testBadFuture() { |
| 900 var bad = new BadFuture(); | 911 var bad = new BadFuture(); |
| 901 // Completing with bad future (then call throws) puts error in result. | 912 // Completing with bad future (then call throws) puts error in result. |
| 902 asyncStart(); | 913 asyncStart(); |
| 903 Completer completer = new Completer(); | 914 Completer completer = new Completer(); |
| 904 completer.complete(bad); | 915 completer.complete(bad); |
| 905 completer.future.then((_) { Expect.fail("unreachable"); }, | 916 completer.future.then((_) { Expect.fail("unreachable"); }, |
| 906 onError: (e, s) { | 917 onError: (e, s) { |
| 907 Expect.isTrue(completer.isCompleted); | 918 Expect.isTrue(completer.isCompleted); |
| 908 asyncEnd(); | 919 asyncEnd(); |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1089 | 1100 |
| 1090 testChainedFutureValue(); | 1101 testChainedFutureValue(); |
| 1091 testChainedFutureValueDelay(); | 1102 testChainedFutureValueDelay(); |
| 1092 testChainedFutureError(); | 1103 testChainedFutureError(); |
| 1093 | 1104 |
| 1094 testSyncFuture_i13368(); | 1105 testSyncFuture_i13368(); |
| 1095 | 1106 |
| 1096 testWaitCleanUp(); | 1107 testWaitCleanUp(); |
| 1097 testWaitCleanUpError(); | 1108 testWaitCleanUpError(); |
| 1098 testWaitSyncError(); | 1109 testWaitSyncError(); |
| 1110 testWaitSyncError2(); |
| 1099 | 1111 |
| 1100 testBadFuture(); | 1112 testBadFuture(); |
| 1101 | 1113 |
| 1102 testTypes(); | 1114 testTypes(); |
| 1103 | 1115 |
| 1104 testAnyValue(); | 1116 testAnyValue(); |
| 1105 testAnyError(); | 1117 testAnyError(); |
| 1106 testAnyIgnoreIncomplete(); | 1118 testAnyIgnoreIncomplete(); |
| 1107 testAnyIgnoreError(); | 1119 testAnyIgnoreError(); |
| 1108 | 1120 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1160 Future whenComplete(action()) { | 1172 Future whenComplete(action()) { |
| 1161 return new Future.microtask(action).then((_) => this); | 1173 return new Future.microtask(action).then((_) => this); |
| 1162 } | 1174 } |
| 1163 Stream asStream() { | 1175 Stream asStream() { |
| 1164 return (new StreamController()..add(_result)..close()).stream; | 1176 return (new StreamController()..add(_result)..close()).stream; |
| 1165 } | 1177 } |
| 1166 Future timeout(Duration duration, {onTimeout()}) { | 1178 Future timeout(Duration duration, {onTimeout()}) { |
| 1167 return this; | 1179 return this; |
| 1168 } | 1180 } |
| 1169 } | 1181 } |
| OLD | NEW |