Factor failing tests out of language/async_star_test.dart

Make async_star_test no longer a multitest, and stop using package:test in
the factored tests.

BUG=dartbug.com/2238, dartbug.com/22853
R=lrn@google.com

Review URL: https://codereview.chromium.org//1270413002 .
diff --git a/tests/language/async_star_await_pauses_test.dart b/tests/language/async_star_await_pauses_test.dart
new file mode 100644
index 0000000..c16fbdd
--- /dev/null
+++ b/tests/language/async_star_await_pauses_test.dart
@@ -0,0 +1,34 @@
+// Copyright (c) 2015, 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.
+
+import "dart:async";
+import "package:expect/expect.dart";
+import "package:async_helper/async_helper.dart";
+
+main() {
+  var sc;
+  var i = 0;
+  void send() {
+    if (i == 5) {
+      sc.close();
+    } else {
+      sc.add(i++);
+    }
+  }
+  sc = new StreamController(onListen: send, onResume: send);
+
+  f(s) async {
+    var r = 0;
+    await for (var i in s) {
+      r += await new Future.delayed(new Duration(milliseconds: 10), () => i);
+    }
+    return r;
+  }
+
+  asyncStart();
+  f(sc.stream).then((v) {
+    Expect.equals(10, v);
+    asyncEnd();
+  });
+}
diff --git a/tests/language/async_star_cancel_while_paused_test.dart b/tests/language/async_star_cancel_while_paused_test.dart
new file mode 100644
index 0000000..633769f
--- /dev/null
+++ b/tests/language/async_star_cancel_while_paused_test.dart
@@ -0,0 +1,66 @@
+// Copyright (c) 2015, 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.
+
+// This is a regression test for issue 22853.
+
+import "dart:async";
+import "package:expect/expect.dart";
+import "package:async_helper/async_helper.dart";
+
+main() {
+  var list = [];
+  var sync = new Sync();
+  f() async* {
+    list.add("*1");
+    yield 1;
+    await sync.wait();
+    sync.release();
+    list.add("*2");
+    yield 2;
+    list.add("*3");
+  };
+  var stream = f();
+  var sub = stream.listen(list.add);
+
+  asyncStart();
+  return sync.wait().whenComplete(() {
+    Expect.listEquals(list, ["*1", 1]);
+    sub.pause();
+    return sync.wait();
+  }).whenComplete(() {
+    Expect.listEquals(list, ["*1", 1, "*2"]);
+    sub.cancel();
+    new Future.delayed(new Duration(milliseconds: 200), () {
+      // Should not have yielded 2 or added *3 while paused.
+      Expect.listEquals(list, ["*1", 1, "*2"]);
+      asyncEnd();
+    });
+  });
+}
+
+/**
+ * Allows two asynchronous executions to synchronize.
+ *
+ * Calling [wait] and waiting for the returned future to complete will
+ * wait for the other executions to call [wait] again. At that point,
+ * the waiting execution is allowed to continue (the returned future completes),
+ * and the more recent call to [wait] is now the waiting execution.
+ */
+class Sync {
+  Completer _completer = null;
+  // Release whoever is currently waiting and start waiting yourself.
+  Future wait([v]) {
+    if (_completer != null) _completer.complete(v);
+    _completer = new Completer();
+    return _completer.future;
+  }
+
+  // Release whoever is currently waiting.
+  void release([v]) {
+    if (_completer != null) {
+      _completer.complete(v);
+      _completer = null;
+    }
+  }
+}
diff --git a/tests/language/async_star_regression_2238_test.dart b/tests/language/async_star_regression_2238_test.dart
new file mode 100644
index 0000000..b73a61a
--- /dev/null
+++ b/tests/language/async_star_regression_2238_test.dart
@@ -0,0 +1,20 @@
+// Copyright (c) 2015, 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.
+
+// This is a regression test for issue 2238
+import "dart:async";
+import "package:expect/expect.dart";
+import "package:async_helper/async_helper.dart";
+
+main() {
+  f() async* {
+    label1: label2: yield 0;
+  }
+
+  asyncStart();
+  f().toList().then((list) {
+    Expect.listEquals([0], list);
+    asyncEnd();
+  });
+}
diff --git a/tests/language/async_star_regression_fisk_test.dart b/tests/language/async_star_regression_fisk_test.dart
new file mode 100644
index 0000000..b05356a9
--- /dev/null
+++ b/tests/language/async_star_regression_fisk_test.dart
@@ -0,0 +1,43 @@
+// Copyright (c) 2015, 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.
+
+// This test may crash dart2js.
+
+import "dart:async";
+import "package:expect/expect.dart";
+import "package:async_helper/async_helper.dart";
+
+main() {
+  var res = [];
+  fisk() async* {
+    res.add("+fisk");
+    try {
+      for (int i = 0; i < 2; i++) {
+        yield await new Future.microtask(() => i);
+      }
+    } finally {
+      res.add("-fisk");
+    }
+  }
+
+  fugl(int count) async {
+    res.add("fisk $count");
+    try {
+      await for(int i in fisk().take(count)) res.add(i);
+    } finally {
+      res.add("done");
+    }
+  }
+
+  asyncStart();
+  fugl(3).whenComplete(() => fugl(2))
+      .whenComplete(() => fugl(1))
+      .whenComplete(() {
+    Expect.listEquals(res,
+        ["fisk 3", "+fisk", 0, 1, "-fisk", "done",
+         "fisk 2", "+fisk", 0, 1, "-fisk", "done",
+         "fisk 1", "+fisk", 0, "done", "-fisk", ]);
+    asyncEnd();
+  });
+}
diff --git a/tests/language/async_star_stream_take_test.dart b/tests/language/async_star_stream_take_test.dart
new file mode 100644
index 0000000..095082b
--- /dev/null
+++ b/tests/language/async_star_stream_take_test.dart
@@ -0,0 +1,26 @@
+// Copyright (c) 2015, 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.
+
+import "dart:async";
+import "package:expect/expect.dart";
+import "package:async_helper/async_helper.dart";
+
+Stream makeStream(int n) async* {
+  for (int i = 0; i < n; i++) yield i;
+}
+
+main() {
+  f(Stream s) async {
+    var r = 0;
+    await for(var v in s.take(5)) r += v;
+    return r;
+  }
+
+  asyncStart();
+  f(makeStream(10)).then((v) {
+    Expect.equals(10, v);
+    asyncEnd();
+  });
+}
+
diff --git a/tests/language/async_star_take_reyield_test.dart b/tests/language/async_star_take_reyield_test.dart
new file mode 100644
index 0000000..f2e8737
--- /dev/null
+++ b/tests/language/async_star_take_reyield_test.dart
@@ -0,0 +1,27 @@
+// Copyright (c) 2015, 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.
+
+import "dart:async";
+import "package:expect/expect.dart";
+import "package:async_helper/async_helper.dart";
+
+expectList(stream, list) {
+  return stream.toList().then((v) {
+    Expect.listEquals(v, list);
+  });
+}
+
+Stream makeStream(int n) async* {
+  for (int i = 0; i < n; i++) yield i;
+}
+
+main() {
+  fivePartialSums(Stream s) async* {
+    var r = 0;
+    await for(var v in s.take(5)) yield r += v;
+  }
+  asyncStart();
+  expectList(fivePartialSums(makeStream(10)), [0, 1, 3, 6, 10])
+      .then(asyncSuccess);
+}
diff --git a/tests/language/async_star_test.dart b/tests/language/async_star_test.dart
index 94a7523..c30f50e 100644
--- a/tests/language/async_star_test.dart
+++ b/tests/language/async_star_test.dart
@@ -143,14 +143,6 @@
       return expectList(f(), [0]);
     });
 
-    // VM issue 2238
-    test("labeled 2", () {          /// 01: ok
-      f() async* {                  /// 01: continued
-        label1: label2: yield 0;    /// 01: continued
-      }                             /// 01: continued
-      return expectList(f(), [0]);  /// 01: continued
-    });                             /// 01: continued
-
     test("for-loop", () {
       f() async* {
         for (int i = 0; i < 3; i++) yield i;
@@ -583,39 +575,6 @@
         return expectList(f().take(0), []);
       });
     });
-
-    // Crashes dart2js.
-    // test("regression-fugl/fisk", () {
-    //   var res = [];
-    //   fisk() async* {
-    //     res.add("+fisk");
-    //     try {
-    //       for (int i = 0; i < 2; i++) {
-    //         yield await new Future.microtask(() => i);
-    //       }
-    //     } finally {
-    //       res.add("-fisk");
-    //     }
-    //   }
-
-    //   fugl(int count) async {
-    //     res.add("fisk $count");
-    //     try {
-    //       await for(int i in fisk().take(count)) res.add(i);
-    //     } finally {
-    //       res.add("done");
-    //     }
-    //   }
-
-    //   return fugl(3).whenComplete(() => fugl(2))
-    //                 .whenComplete(() => fugl(1))
-    //                 .whenComplete(() {
-    //     expect(res, ["fisk 3", "+fisk", 0, 1, "-fisk", "done",
-    //                  "fisk 2", "+fisk", 0, 1, "-fisk", "done",
-    //                  "fisk 1", "+fisk", 0, "done", "-fisk", ]);
-    //   });
-    // });
-
   });
 
   group("pausing", () {
@@ -703,34 +662,6 @@
         expect(list.length == 18 || list.length == 19, isTrue);
       });
     });
-
-    test("canceling while paused at yield", () {                  /// 02: ok
-      var list = [];                                              /// 02: continued
-      var sync = new Sync();                                      /// 02: continued
-      f() async* {                                                /// 02: continued
-        list.add("*1");                                           /// 02: continued
-        yield 1;                                                  /// 02: continued
-        await sync.wait();                                        /// 02: continued
-        sync.release();                                           /// 02: continued
-        list.add("*2");                                           /// 02: continued
-        yield 2;                                                  /// 02: continued
-        list.add("*3");                                           /// 02: continued
-      };                                                          /// 02: continued
-      var stream = f();                                           /// 02: continued
-      var sub = stream.listen(list.add);                          /// 02: continued
-      return sync.wait().whenComplete(() {                        /// 02: continued
-        expect(list, equals(["*1", 1]));                          /// 02: continued
-        sub.pause();                                              /// 02: continued
-        return sync.wait();                                       /// 02: continued
-      }).whenComplete(() {                                        /// 02: continued
-        expect(list, equals(["*1", 1, "*2"]));                    /// 02: continued
-        sub.cancel();                                             /// 02: continued
-        return new Future.delayed(MS * 200, () {                  /// 02: continued
-          // Should not have yielded 2 or added *3 while paused.  /// 02: continued
-          expect(list, equals(["*1", 1, "*2"]));                  /// 02: continued
-        });                                                       /// 02: continued
-      });                                                         /// 02: continued
-    });                                                           /// 02: continued
   });
 
   group("await for", () {
@@ -760,17 +691,6 @@
       });
     });
 
-    test("simple stream - take", () {           /// 03: ok
-      f(s) async {                              /// 03: continued
-        var r = 0;                              /// 03: continued
-        await for(var v in s.take(5)) r += v;   /// 03: continued
-        return r;                               /// 03: continued
-      }                                         /// 03: continued
-      return f(mkStream(10)).then((v) {         /// 03: continued
-        expect(v, equals(10));                  /// 03: continued
-      });                                       /// 03: continued
-    });                                         /// 03: continued
-
     test("simple stream reyield", () {
       f(s) async* {
         var r = 0;
@@ -787,14 +707,6 @@
       return expectList(f(mkStream(5)), [0, 1, 3, 6, 10]);
     });
 
-    test("simple stream - take, reyield", () {                /// 04: ok
-      f(s) async* {                                           /// 04: continued
-        var r = 0;                                            /// 04: continued
-        await for(var v in s.take(5)) yield r += v;           /// 04: continued
-      }                                                       /// 04: continued
-      return expectList(f(mkStream(10)), [0, 1, 3, 6, 10]);   /// 04: continued
-    });                                                       /// 04: continued
-
     test("nested", () {
       f() async {
         var r = 0;
@@ -840,29 +752,6 @@
         expect(v, equals((1 + 2 + 3 + 4) * (1 + 2)));
       });
     });
-
-    test("await pauses loop", () {                                   /// 05: ok
-      var sc;                                                        /// 05: continued
-      var i = 0;                                                     /// 05: continued
-      void send() {                                                  /// 05: continued
-        if (i == 5) {                                                /// 05: continued
-          sc.close();                                                /// 05: continued
-        } else {                                                     /// 05: continued
-          sc.add(i++);                                               /// 05: continued
-        }                                                            /// 05: continued
-      }                                                              /// 05: continued
-      sc = new StreamController(onListen: send, onResume: send);     /// 05: continued
-      f(s) async {                                                   /// 05: continued
-        var r = 0;                                                   /// 05: continued
-        await for (var i in s) {                                     /// 05: continued
-          r += await new Future.delayed(MS * 10, () => i);           /// 05: continued
-        }                                                            /// 05: continued
-        return r;                                                    /// 05: continued
-      }                                                              /// 05: continued
-      return f(sc.stream).then((v) {                                 /// 05: continued
-        expect(v, equals(10));                                       /// 05: continued
-      });                                                            /// 05: continued
-    });                                                              /// 05: continued
   });
 }
 
@@ -894,29 +783,3 @@
     fail("Not implementing Stream.");
   }
 }
-
-/**
- * Allows two asynchronous executions to synchronize.
- *
- * Calling [wait] and waiting for the returned future to complete will
- * wait for the other executions to call [wait] again. At that point,
- * the waiting execution is allowed to continue (the returned future completes),
- * and the more resent call to [wait] is now the waiting execution.
- */
-class Sync {
-  Completer _completer = null;
-  // Release whoever is currently waiting and start waiting yourself.
-  Future wait([v]) {
-    if (_completer != null) _completer.complete(v);
-    _completer = new Completer();
-    return _completer.future;
-  }
-
-  // Release whoever is currently waiting.
-  void release([v]) {
-    if (_completer != null) {
-      _completer.complete(v);
-      _completer = null;
-    }
-  }
-}
diff --git a/tests/language/language.status b/tests/language/language.status
index 2f58a23..55e186d 100644
--- a/tests/language/language.status
+++ b/tests/language/language.status
@@ -27,9 +27,10 @@
 cyclic_type2_test: Fail, OK
 least_upper_bound_expansive_test/*: Fail, OK
 
-async_star_test/01: CompileTimeError, RuntimeError # drt only runtime-errs.
-async_star_test/02: RuntimeError
-async_star_test/05: Timeout, RuntimeError
+async_star_regression_2238_test: CompileTimeError, RuntimeError # drt only runtime-errs.
+async_star_cancel_while_paused_test: RuntimeError
+async_star_await_pauses_test: Skip # Times out. Issue 23996
+async_star_regression_fisk_test: RuntimeError # Issue 23994
 
 [ $compiler == none && $runtime == vm ]
 class_keyword_test/02: MissingCompileTimeError # Issue 13627
diff --git a/tests/language/language_dart2js.status b/tests/language/language_dart2js.status
index 00d35b0..4740960 100644
--- a/tests/language/language_dart2js.status
+++ b/tests/language/language_dart2js.status
@@ -8,8 +8,8 @@
 sync_generator2_test/10: MissingCompileTimeError # Issue 22324
 getter_setter_in_lib_test: Fail # Issue 23288
 
-async_star_test/02: RuntimeError # 22853
-async_star_test/05: RuntimeError, Timeout
+async_star_cancel_while_paused_test: RuntimeError # Issue 22853
+async_star_await_pauses_test: Fail, Timeout # Issue 22853
 tearoff_basic_test: Skip # Tear-off not supported
 tearoff_constructor_basic_test: Skip # Tear-off not supported
 
@@ -382,12 +382,12 @@
 async_return_types_test/wrongTypeParameter: Crash # (test()async{Expect....  cannot handle async/sync*/async* functions
 async_star_cancel_and_throw_in_finally_test: Crash # (test()async{var com...  cannot handle async/sync*/async* functions
 async_star_regression_23116_test: Crash # (test()async{Complet...  cannot handle async/sync*/async* functions
-async_star_test/01: Crash # (f()async*{}): cannot handle async/sync*/async* functions
-async_star_test/02: Crash # (f()async*{}): cannot handle async/sync*/async* functions
-async_star_test/03: Crash # (f()async*{}): cannot handle async/sync*/async* functions
-async_star_test/04: Crash # (f()async*{}): cannot handle async/sync*/async* functions
-async_star_test/05: Crash # (f()async*{}): cannot handle async/sync*/async* functions
-async_star_test/none: Crash # (f()async*{}): cannot handle async/sync*/async* functions
+async_star_regression_2238_test: Crash # (f()async*{}): cannot handle async/sync*/async* functions
+async_star_cancel_while_paused_test: Crash # (f()async*{}): cannot handle async/sync*/async* functions
+async_star_stream_take_test: Crash # (f()async*{}): cannot handle async/sync*/async* functions
+async_star_take_reyield_test: Crash # (f()async*{}): cannot handle async/sync*/async* functions
+async_star_await_pauses_test: Crash # (f()async*{}): cannot handle async/sync*/async* functions
+async_star_test: Crash # (f()async*{}): cannot handle async/sync*/async* functions
 async_switch_test/none: Crash # (test()async{Expect....  cannot handle async/sync*/async* functions
 async_switch_test/withDefault: Crash # (test()async{Expect....  cannot handle async/sync*/async* functions
 async_test/none: Crash # (bar(int p1,p2)async{var z=8;return p2+z+foo;}): cannot handle async/sync*/async* functions