Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1404)

Unified Diff: tests/lib_strong/async/futures_test.dart

Issue 2999943002: Migrated test block 168 to Dart 2.0. (Closed)
Patch Set: Fixed package:test crash related issues, addressed Bob's comments. Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tests/lib_strong/async/future_value_chain_test.dart ('k') | tests/lib_strong/lib_strong.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/lib_strong/async/futures_test.dart
diff --git a/tests/lib_strong/async/futures_test.dart b/tests/lib_strong/async/futures_test.dart
deleted file mode 100644
index a9a37e0df3246392a75b586ae123f54ba9fc8f3f..0000000000000000000000000000000000000000
--- a/tests/lib_strong/async/futures_test.dart
+++ /dev/null
@@ -1,268 +0,0 @@
-// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-library futures_test;
-
-import 'package:async_helper/async_helper.dart';
-import "package:expect/expect.dart";
-import 'dart:async';
-
-Future testWaitEmpty() {
- List<Future> futures = new List<Future>();
- return Future.wait(futures);
-}
-
-Future testCompleteAfterWait() {
- List<Future> futures = new List<Future>();
- Completer<Object> c = new Completer<Object>();
- futures.add(c.future);
- Future future = Future.wait(futures);
- c.complete(null);
- return future;
-}
-
-Future testCompleteBeforeWait() {
- List<Future> futures = new List<Future>();
- Completer c = new Completer();
- futures.add(c.future);
- c.complete(null);
- return Future.wait(futures);
-}
-
-Future testWaitWithMultipleValues() {
- List<Future> futures = new List<Future>();
- Completer c1 = new Completer();
- Completer c2 = new Completer();
- futures.add(c1.future);
- futures.add(c2.future);
- c1.complete(1);
- c2.complete(2);
- return Future.wait(futures).then((values) {
- Expect.listEquals([1, 2], values);
- });
-}
-
-Future testWaitWithSingleError() {
- List<Future> futures = new List<Future>();
- Completer c1 = new Completer();
- Completer c2 = new Completer();
- futures.add(c1.future);
- futures.add(c2.future);
- c1.complete();
- c2.completeError('correct error');
-
- return Future.wait(futures).then((_) {
- throw 'incorrect error';
- }).catchError((error, stackTrace) {
- Expect.equals('correct error', error);
- Expect.isNull(stackTrace);
- });
-}
-
-Future testWaitWithMultipleErrors() {
- List<Future> futures = new List<Future>();
- Completer c1 = new Completer();
- Completer c2 = new Completer();
- futures.add(c1.future);
- futures.add(c2.future);
- c1.completeError('correct error');
- c2.completeError('incorrect error 1');
-
- return Future.wait(futures).then((_) {
- throw 'incorrect error 2';
- }).catchError((error, stackTrace) {
- Expect.equals('correct error', error);
- Expect.isNull(stackTrace);
- });
-}
-
-Future testWaitWithMultipleErrorsEager() {
- List<Future> futures = new List<Future>();
- Completer c1 = new Completer();
- Completer c2 = new Completer();
- futures.add(c1.future);
- futures.add(c2.future);
- c1.completeError('correct error');
- c2.completeError('incorrect error 1');
-
- return Future.wait(futures, eagerError: true).then((_) {
- throw 'incorrect error 2';
- }).catchError((error, stackTrace) {
- Expect.equals('correct error', error);
- Expect.isNull(stackTrace);
- });
-}
-
-StackTrace get currentStackTrace {
- try {
- throw 0;
- } catch (e, st) {
- return st;
- }
- return null;
-}
-
-Future testWaitWithSingleErrorWithStackTrace() {
- List<Future> futures = new List<Future>();
- Completer c1 = new Completer();
- Completer c2 = new Completer();
- futures.add(c1.future);
- futures.add(c2.future);
- c1.complete();
- c2.completeError('correct error', currentStackTrace);
-
- return Future.wait(futures).then((_) {
- throw 'incorrect error';
- }).catchError((error, stackTrace) {
- Expect.equals('correct error', error);
- Expect.isNotNull(stackTrace);
- });
-}
-
-Future testWaitWithMultipleErrorsWithStackTrace() {
- List<Future> futures = new List<Future>();
- Completer c1 = new Completer();
- Completer c2 = new Completer();
- futures.add(c1.future);
- futures.add(c2.future);
- c1.completeError('correct error', currentStackTrace);
- c2.completeError('incorrect error 1');
-
- return Future.wait(futures).then((_) {
- throw 'incorrect error 2';
- }).catchError((error, stackTrace) {
- Expect.equals('correct error', error);
- Expect.isNotNull(stackTrace);
- });
-}
-
-Future testWaitWithMultipleErrorsWithStackTraceEager() {
- List<Future> futures = new List<Future>();
- Completer c1 = new Completer();
- Completer c2 = new Completer();
- futures.add(c1.future);
- futures.add(c2.future);
- c1.completeError('correct error', currentStackTrace);
- c2.completeError('incorrect error 1');
-
- return Future.wait(futures, eagerError: true).then((_) {
- throw 'incorrect error 2';
- }).catchError((error, stackTrace) {
- Expect.equals('correct error', error);
- Expect.isNotNull(stackTrace);
- });
-}
-
-Future testEagerWait() {
- var st;
- try {
- throw 0;
- } catch (e, s) {
- st = s;
- }
- Completer c1 = new Completer();
- Completer c2 = new Completer();
- List<Future> futures = <Future>[c1.future, c2.future];
- Future waited = Future.wait(futures, eagerError: true);
- var result = waited.then((v) {
- throw "should not be called";
- }, onError: (e, s) {
- Expect.equals(e, 42);
- Expect.identical(st, s);
- return true;
- });
- c1.completeError(42, st);
- return result;
-}
-
-Future testForEachEmpty() {
- return Future.forEach([], (_) {
- throw 'should not be called';
- });
-}
-
-Future testForEach() {
- var seen = <int>[];
- return Future.forEach([1, 2, 3, 4, 5], (n) {
- seen.add(n);
- return new Future.value();
- }).then((_) => Expect.listEquals([1, 2, 3, 4, 5], seen));
-}
-
-Future testForEachSync() {
- var seen = <int>[];
- return Future.forEach([1, 2, 3, 4, 5], seen.add).then(
- (_) => Expect.listEquals([1, 2, 3, 4, 5], seen));
-}
-
-Future testForEachWithException() {
- var seen = <int>[];
- return Future.forEach([1, 2, 3, 4, 5], (n) {
- if (n == 4) throw 'correct exception';
- seen.add(n);
- return new Future.value();
- }).then((_) {
- throw 'incorrect exception';
- }).catchError((error) {
- Expect.equals('correct exception', error);
- });
-}
-
-Future testDoWhile() {
- var count = 0;
- return Future.doWhile(() {
- count++;
- return new Future(() => count < 10);
- }).then((_) => Expect.equals(10, count));
-}
-
-Future testDoWhileSync() {
- var count = 0;
- return Future.doWhile(() {
- count++;
- return count < 10;
- }).then((_) => Expect.equals(10, count));
-}
-
-Future testDoWhileWithException() {
- var count = 0;
- return Future.doWhile(() {
- count++;
- if (count == 4) throw 'correct exception';
- return new Future(() => true);
- }).then((_) {
- throw 'incorrect exception';
- }).catchError((error) {
- Expect.equals('correct exception', error);
- });
-}
-
-main() {
- List<Future> futures = new List<Future>();
-
- futures.add(testWaitEmpty());
- futures.add(testCompleteAfterWait());
- futures.add(testCompleteBeforeWait());
- futures.add(testWaitWithMultipleValues());
- futures.add(testWaitWithSingleError());
- futures.add(testWaitWithMultipleErrors());
- futures.add(testWaitWithMultipleErrorsEager());
- futures.add(testWaitWithSingleErrorWithStackTrace());
- futures.add(testWaitWithMultipleErrorsWithStackTrace());
- futures.add(testWaitWithMultipleErrorsWithStackTraceEager());
- futures.add(testEagerWait());
- futures.add(testForEachEmpty());
- futures.add(testForEach());
- futures.add(testForEachSync());
- futures.add(testForEachWithException());
- futures.add(testDoWhile());
- futures.add(testDoWhileSync());
- futures.add(testDoWhileWithException());
-
- asyncStart();
- Future.wait(futures).then((List list) {
- Expect.equals(18, list.length);
- asyncEnd();
- });
-}
« no previous file with comments | « tests/lib_strong/async/future_value_chain_test.dart ('k') | tests/lib_strong/lib_strong.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698