Migrate language/async_backwards... ... language/async_star_take...

R=bkonyi@google.com

Review-Url: https://codereview.chromium.org/2985173002 .
This commit is contained in:
Bob Nystrom 2017-07-27 15:48:29 -07:00
parent 0ca1d23eb0
commit 557cab2a3e
46 changed files with 117 additions and 874 deletions

View file

@ -1,35 +0,0 @@
// 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 "package:expect/expect.dart";
void badReturnTypeAsync() async {} // //# 01: static type warning
void badReturnTypeAsyncStar() async* {} // //# 02: static type warning
void badReturnTypeSyncStar() sync* {} // //# 03: static type warning
main() {
try {
badReturnTypeAsync(); // //# 01: continued
} catch (e, st) {
Expect.isTrue(e is TypeError, "wrong exception type");
Expect.isTrue(
st.toString().contains("badReturnTypeAsync"), "missing frame");
}
try {
badReturnTypeAsyncStar(); // //# 02: continued
} catch (e, st) {
Expect.isTrue(e is TypeError, "wrong exception type");
Expect.isTrue(
st.toString().contains("badReturnTypeAsyncStar"), "missing frame");
}
try {
badReturnTypeSyncStar(); // //# 03: continued
} catch (e, st) {
Expect.isTrue(e is TypeError, "wrong exception type");
Expect.isTrue(
st.toString().contains("badReturnTypeSyncStar"), "missing frame");
}
}

View file

@ -51,13 +51,8 @@ assertion_initializer_const_function_error_test/01: MissingCompileTimeError
[ ($runtime == vm || $runtime == flutter || $runtime == dart_precompiled) && $compiler != dartk && $compiler != dartkp ]
abstract_beats_arguments2_test/01: Crash # Issue 29171
[ $runtime == vm || $runtime == dart_precompiled ]
# These test entries will be valid for vm (with and without kernel).
[ $compiler == none || $compiler == app_jit || $compiler == dartk || $runtime == dart_precompiled ]
async_star_cancel_while_paused_test: RuntimeError
# This is OK for now, but we may want to change the semantics to match the test.
async_star_pause_test: Fail, OK
# These tests are skipped in the VM because it has "--supermixin"
# functionality enabled unconditionally. The tests should be removed
@ -102,8 +97,6 @@ multiline_strings_test: Fail # Issue 23020
deferred_redirecting_factory_test: Fail, Crash # Issue 23408
redirecting_constructor_initializer_test: RuntimeError # Issue 23488
async_star_regression_2238_test: CompileTimeError, RuntimeError
[ ($compiler == none || $compiler == precompiler || $compiler == app_jit) && $checked ]
# These generic functions tests pass for the wrong reason in checked mode,
# because the parsed type parameters are mapped to dynamic type.
@ -418,7 +411,6 @@ override_inheritance_method_test/30: CompileTimeError
redirecting_factory_reflection_test: CompileTimeError
method_override6_test: CompileTimeError
try_catch_syntax_test/08: CompileTimeError
async_return_types_test/tooManyTypeParameters: CompileTimeError
method_override4_test: CompileTimeError
super_call4_test: CompileTimeError
wrong_number_type_arguments_test/00: CompileTimeError
@ -566,13 +558,7 @@ deferred_global_test: Skip # Timeout
config_import_test: RuntimeError # Flutter Issue 9110
vm/no_such_method_error_message_callable_vm_test: RuntimeError # Flutter Issue 9110
vm/regress_27201_test: Fail # Flutter Issue 9110
async_return_types_test/nestedFuture: Skip # Flutter Issue 9110
async_return_types_test/wrongTypeParameter: Skip # Flutter Issue 9110
async_return_types_test/wrongReturnType: Skip # Flutter Issue 9110
async_return_types_test/return_value_sync_star: Skip # Flutter Issue 9110
asyncstar_yield_test: Skip # Flutter Issue 9110
async_star_no_cancel_test: Skip # Flutter Issue 9110
async_star_cancel_while_paused_test: Skip # Flutter Issue 9110
await_for_test: Skip # Flutter Issue 9110
await_for_cancel_test: Skip # Flutter Issue 9110

View file

@ -17,8 +17,6 @@ getter_setter_in_lib_test: Fail # Issue 23288
method_name_test: Fail # issue 25574
setter4_test: CompileTimeError # issue 13639
async_star_cancel_while_paused_test: RuntimeError # Issue 22853
try_catch_on_syntax_test/10: Fail # Issue 19823
try_catch_on_syntax_test/11: Fail # Issue 19823
@ -98,8 +96,6 @@ vm/reflect_core_vm_test: Fail # mirrors not supported
await_for_test: Skip # Jsshell does not provide periodic timers, Issue 7728
async_star_test: RuntimeError # Jsshell does not provide non-zero timers, Issue 7728
regress_23996_test: RuntimeError # Jsshell does not provide non-zero timers, Issue 7728
async_star_no_cancel_test: RuntimeError # Need triage
async_star_no_cancel2_test: RuntimeError # Need triage
[ $compiler == dart2js && $browser && ! $dart2js_with_kernel ]
config_import_test: Fail # Test flag is not passed to the compiler.
@ -169,8 +165,6 @@ multiline_newline_test/06r: MissingCompileTimeError # Issue 23888
mixin_mixin_type_arguments_test: RuntimeError # Issue 29587
[ $compiler == dart2js && $checked && ! $dart2js_with_kernel ]
async_return_types_test/nestedFuture: Fail # Issue 26429
async_return_types_test/wrongTypeParameter: Fail # Issue 26429
regress_26133_test: RuntimeError # Issue 26429
regress_29405_test: Fail # Issue 29422
type_variable_bounds_test/02: Fail # Issue 12702
@ -329,10 +323,6 @@ async_await_syntax_test/b06a: RuntimeError # Issue 27394
async_await_syntax_test/c06a: RuntimeError # Issue 27394
async_await_syntax_test/d06a: RuntimeError # Issue 27394
async_await_test: RuntimeError # Issue 27394
async_star_pause_test: RuntimeError # Issue 27394
async_star_regression_fisk_test: RuntimeError # Issue 27394
async_star_stream_take_test: RuntimeError # Issue 27394
async_star_take_reyield_test: RuntimeError # Issue 27394
async_star_test: RuntimeError # Issue 27394
await_for_test: RuntimeError # Issue 27394
await_for_use_local_test: RuntimeError # Issue 27394
@ -659,35 +649,6 @@ async_await_syntax_test/d08c: RuntimeError
async_await_syntax_test/d09a: Crash
async_await_syntax_test/d10a: Crash
async_await_test: Crash
async_break_in_finally_test: Crash
async_continue_label_test/await_in_body: Crash
async_continue_label_test/await_in_condition: Crash
async_continue_label_test/await_in_init: Crash
async_continue_label_test/await_in_update: Crash
async_continue_label_test/none: Crash
async_control_structures_test: Crash
async_finally_rethrow_test: Crash
async_or_generator_return_type_stacktrace_test/01: Crash
async_or_generator_return_type_stacktrace_test/02: Crash
async_or_generator_return_type_stacktrace_test/03: Crash
async_or_generator_return_type_stacktrace_test/none: Crash
async_regression_23058_test: Crash
async_rethrow_test: Crash
async_return_types_test/nestedFuture: Crash
async_return_types_test/none: Crash
async_return_types_test/tooManyTypeParameters: Crash
async_return_types_test/wrongReturnType: Crash
async_return_types_test/wrongTypeParameter: Crash
async_star_cancel_and_throw_in_finally_test: Crash
async_star_cancel_while_paused_test: Crash
async_star_no_cancel2_test: Crash
async_star_no_cancel_test: Crash
async_star_pause_test: Crash
async_star_regression_2238_test: Crash
async_star_regression_23116_test: Crash
async_star_regression_fisk_test: Crash
async_star_stream_take_test: Crash
async_star_take_reyield_test: Crash
async_star_test: Crash
async_switch_test/none: Crash
async_switch_test/withDefault: Crash

View file

@ -276,8 +276,6 @@ assert_initializer_test/48: MissingCompileTimeError # KernelVM bug: Constant eva
assert_initializer_test/none: RuntimeError # KernelVM bug: Constant evaluation.
assign_static_type_test/02: MissingCompileTimeError
async_await_test: RuntimeError
async_return_types_test/nestedFuture: Fail
async_return_types_test/wrongTypeParameter: Fail
compile_time_constant_checked_test/02: MissingCompileTimeError
const_constructor2_test/20: MissingCompileTimeError
const_constructor2_test/22: MissingCompileTimeError

View file

@ -0,0 +1,11 @@
// 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 "package:expect/expect.dart";
void badReturnTypeAsync() async {} // //# 01: compile-time error
void badReturnTypeAsyncStar() async* {} // //# 02: compile-time error
void badReturnTypeSyncStar() sync* {} // //# 03: compile-time error
void main() {}

View file

@ -14,18 +14,17 @@ Future<int> foo2() async {
return 3;
}
Future<int> //# wrongTypeParameter: static type warning, dynamic type error
Future<int> //# wrongTypeParameter: compile-time error
foo3() async {
return "String";
}
// Future<int, String> is treated like Future<dynamic>
Future<int, String> //# tooManyTypeParameters: static type warning
Future<int, String> //# tooManyTypeParameters: compile-time error
foo4() async {
return "String";
}
int //# wrongReturnType: static type warning, dynamic type error
int //# wrongReturnType: compile-time error
foo5() async {
return 3;
}
@ -35,7 +34,7 @@ Future<int> foo6() async {
return new Future<int>.value(3);
}
Future<Future<int>> //# nestedFuture: static type warning, dynamic type error
Future<Future<int>> //# nestedFuture: compile-time error
foo7() async {
return new Future<int>.value(3);
}

View file

@ -4,11 +4,13 @@
library async_star_pause_test;
import "package:unittest/unittest.dart";
import "package:async_helper/async_helper.dart";
import "package:expect/expect.dart";
import "dart:async";
main() {
test("await for pauses stream during body", () async {
// await for pauses stream during body.
asyncTest(() async {
// Assumes await-for uses streamIterator.
var log = [];
var s = () async* {
@ -24,7 +26,7 @@ main() {
await nextMicrotask();
log.add("$i!");
}
expect(log, [
Expect.listEquals(log, [
"0-",
"0?",
"0!",

View file

@ -10,6 +10,16 @@ abstract_exact_selector_test/01: MissingCompileTimeError
abstract_factory_constructor_test/00: MissingCompileTimeError
abstract_getter_test/01: MissingCompileTimeError
abstract_syntax_test/00: MissingCompileTimeError
async_or_generator_return_type_stacktrace_test/01: MissingCompileTimeError
async_or_generator_return_type_stacktrace_test/02: MissingCompileTimeError
async_or_generator_return_type_stacktrace_test/03: MissingCompileTimeError
async_return_types_test/wrongTypeParameter: MissingCompileTimeError
async_return_types_test/tooManyTypeParameters: MissingCompileTimeError
async_return_types_test/wrongReturnType: MissingCompileTimeError
async_return_types_test/nestedFuture: MissingCompileTimeError
[ $compiler == dartdevc ]
async_return_types_test/nestedFuture: MissingCompileTimeError
[ $compiler == dart2js && ! $dart2js_with_kernel ]
accessor_conflict_export2_test: Crash # Issue 25626
@ -80,5 +90,92 @@ and_operation_on_non_integer_operand_test: Crash
arithmetic_canonicalization_test: Crash
arithmetic_smi_overflow_test: Crash
[ $compiler == dartdevc && $runtime != none ]
async_star_cancel_while_paused_test: RuntimeError # Issue 29920
async_star_pause_test: RuntimeError
[ $compiler == dart2js && $dart2js_with_kernel && $use_sdk ]
*: Skip # Issue 29626
[ $compiler == dart2js && ! $dart2js_with_kernel && $runtime != none ]
async_star_cancel_while_paused_test: RuntimeError # Issue 22853
[ $compiler == dart2js && $runtime == jsshell && ! $dart2js_with_kernel ]
async_star_no_cancel_test: RuntimeError # Need triage
async_star_no_cancel2_test: RuntimeError # Need triage
[ $compiler == dart2js && $checked && ! $dart2js_with_kernel ]
async_return_types_test/nestedFuture: Fail # Issue 26429
async_return_types_test/wrongTypeParameter: Fail # Issue 26429
[ $compiler == dart2js && $dart2js_with_kernel_in_ssa ]
async_star_pause_test: RuntimeError # Issue 27394
async_star_regression_fisk_test: RuntimeError # Issue 27394
async_star_stream_take_test: RuntimeError # Issue 27394
async_star_take_reyield_test: RuntimeError # Issue 27394
[ $compiler == dart2js && $runtime == d8 && $dart2js_with_kernel ]
async_break_in_finally_test: Crash
async_continue_label_test/await_in_body: Crash
async_continue_label_test/await_in_condition: Crash
async_continue_label_test/await_in_init: Crash
async_continue_label_test/await_in_update: Crash
async_continue_label_test/none: Crash
async_control_structures_test: Crash
async_finally_rethrow_test: Crash
async_or_generator_return_type_stacktrace_test/01: Crash
async_or_generator_return_type_stacktrace_test/02: Crash
async_or_generator_return_type_stacktrace_test/03: Crash
async_or_generator_return_type_stacktrace_test/none: Crash
async_regression_23058_test: Crash
async_rethrow_test: Crash
async_return_types_test/nestedFuture: Crash
async_return_types_test/none: Crash
async_return_types_test/tooManyTypeParameters: Crash
async_return_types_test/wrongReturnType: Crash
async_return_types_test/wrongTypeParameter: Crash
async_star_cancel_and_throw_in_finally_test: Crash
async_star_cancel_while_paused_test: Crash
async_star_no_cancel2_test: Crash
async_star_no_cancel_test: Crash
async_star_pause_test: Crash
async_star_regression_2238_test: Crash
async_star_regression_23116_test: Crash
async_star_regression_fisk_test: Crash
async_star_stream_take_test: Crash
async_star_take_reyield_test: Crash
[ $checked && ($compiler == dartk || $compiler == dartkp) ]
async_return_types_test/nestedFuture: Fail
async_return_types_test/wrongTypeParameter: Fail
# These test entries will be valid for vm (with and without kernel).
[ $compiler == none || $compiler == app_jit || $compiler == dartk || $runtime == dart_precompiled ]
async_star_cancel_while_paused_test: RuntimeError
# This is OK for now, but we may want to change the semantics to match the test.
async_star_pause_test: Fail, OK
[ $compiler == dartk && $runtime == vm ]
async_star_cancel_and_throw_in_finally_test: RuntimeError
async_star_cancel_while_paused_test: RuntimeError
async_star_regression_fisk_test: Timeout
async_star_stream_take_test: Timeout
async_star_take_reyield_test: Timeout
[ $compiler == none || $compiler == precompiler || $compiler == app_jit ]
async_star_regression_2238_test: CompileTimeError, RuntimeError
[ $runtime == flutter ]
# flutter uses --error_on_bad_type, --error_on_bad_override
# and --await_is_keyword so # the following tests fail with
# a Compilation Error
async_return_types_test/tooManyTypeParameters: CompileTimeError
# Look like bugs.
async_return_types_test/nestedFuture: Skip # Flutter Issue 9110
async_return_types_test/return_value_sync_star: Skip # Flutter Issue 9110
async_return_types_test/wrongReturnType: Skip # Flutter Issue 9110
async_return_types_test/wrongTypeParameter: Skip # Flutter Issue 9110
async_star_cancel_while_paused_test: Skip # Flutter Issue 9110
async_star_no_cancel_test: Skip # Flutter Issue 9110

View file

@ -1,17 +0,0 @@
// Copyright (c) 2014, 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.
int get async {
return 1;
}
class A {
async() => null;
}
main() {
var a = async;
var b = new A();
var c = b.async();
}

View file

@ -1,54 +0,0 @@
// 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 "package:expect/expect.dart";
import "package:async_helper/async_helper.dart";
then43() async {
label:
try {
return await 42;
} finally {
break label;
}
return await 43;
}
then42() async {
label:
try {
return await 42;
} finally {}
return await 43;
}
now43() {
label:
try {
return 42;
} finally {
break label;
}
return 43;
}
now42() {
label:
try {
return 42;
} finally {}
return 43;
}
test() async {
Expect.equals(42, await then42());
Expect.equals(43, await then43());
Expect.equals(42, now42());
Expect.equals(43, now43());
}
main() {
asyncStart();
test().then((_) => asyncEnd());
}

View file

@ -1,116 +0,0 @@
// 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 "package:expect/expect.dart";
import "package:async_helper/async_helper.dart";
// Two loop variables
test1() async {
var r = 0;
label:
for (var i = 1,
j =
await //# await_in_init: ok
10;
i < 10 &&
j >
await //# await_in_condition: ok
-5;
j--,
i +=
await //# await_in_update: ok
1) {
if (i <
await //# await_in_body: ok
5 ||
j < -5) {
continue label;
}
r++;
}
Expect.equals(5, r);
}
// One loop variable
test2() async {
var r = 0;
label:
for (var i =
await //# await_in_init: ok
0;
i <
await //# await_in_condition: ok
10;
i +=
await //# await_in_update: ok
1) {
if (i <
await //# await_in_body: ok
5) {
continue label;
}
r++;
}
Expect.equals(5, r);
}
// Variable not declared in initializer;
test3() async {
var r = 0, i, j;
label:
for (i =
await //# await_in_init: ok
0;
i <
await //# await_in_condition: ok
10;
i +=
await //# await_in_update: ok
1) {
if (i <
await //# await_in_body: ok
5) {
continue label;
}
r++;
}
Expect.equals(5, r);
}
// Nested loop
test4() async {
var r = 0;
label:
for (var i =
await //# await_in_init: ok
0;
i <
await //# await_in_condition: ok
10;
i +=
await //# await_in_update: ok
1) {
if (i <
await //# await_in_body: ok
5) {
for (int i = 0; i < 10; i++) {
continue label;
}
}
r++;
}
Expect.equals(5, r);
}
test() async {
await test1();
await test2();
await test3();
await test4();
}
main() {
asyncStart();
test().then((_) => asyncEnd());
}

View file

@ -1,97 +0,0 @@
// Copyright (c) 2014, 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.
// VMOptions=--optimization-counter-threshold=10
import 'package:expect/expect.dart';
import 'dart:async';
expectThenValue(future, value) {
Expect.isTrue(future is Future);
future.then((result) {
Expect.equals(value, result);
});
}
asyncIf(condition) async {
if (condition) {
return 1;
} else {
return 2;
}
// This return is never reached as the finally block returns from the
// function.
return 3;
}
asyncFor(condition) async {
for (int i = 0; i < 10; i++) {
if (i == 5 && condition) {
return 1;
}
}
return 2;
}
asyncTryCatchFinally(overrideInFinally, doThrow) async {
try {
if (doThrow) throw 444;
return 1;
} catch (e) {
return e;
} finally {
if (overrideInFinally) return 3;
}
}
asyncTryCatchLoop() async {
var i = 0;
var throws = 13;
while (true) {
try {
throw throws;
} catch (e) {
if (i == throws) {
return e;
}
} finally {
i++;
}
}
}
asyncImplicitReturn() async {
try {} catch (e) {} finally {}
}
main() {
var asyncReturn;
for (int i = 0; i < 10; i++) {
asyncReturn = asyncIf(true);
expectThenValue(asyncReturn, 1);
asyncReturn = asyncIf(false);
expectThenValue(asyncReturn, 2);
asyncReturn = asyncFor(true);
expectThenValue(asyncReturn, 1);
asyncReturn = asyncFor(false);
expectThenValue(asyncReturn, 2);
asyncReturn = asyncTryCatchFinally(true, false);
expectThenValue(asyncReturn, 3);
asyncReturn = asyncTryCatchFinally(false, false);
expectThenValue(asyncReturn, 1);
asyncReturn = asyncTryCatchFinally(true, true);
expectThenValue(asyncReturn, 3);
asyncReturn = asyncTryCatchFinally(false, true);
expectThenValue(asyncReturn, 444);
asyncReturn = asyncTryCatchLoop();
expectThenValue(asyncReturn, 13);
asyncReturn = asyncImplicitReturn();
expectThenValue(asyncReturn, null);
}
}

View file

@ -1,28 +0,0 @@
// 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";
foo() async {
try {
await 1;
throw "error";
} on String catch (e) {
await 2;
throw e;
} finally {
await 3;
}
}
main() async {
var error = "no error";
try {
await foo();
} catch (e) {
error = e;
}
Expect.equals("error", error);
}

View file

@ -1,7 +0,0 @@
// Copyright (c) 2014, 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 async;
class async {}

View file

@ -1,35 +0,0 @@
// 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 "package:expect/expect.dart";
void badReturnTypeAsync() async {} // //# 01: static type warning
void badReturnTypeAsyncStar() async* {} // //# 02: static type warning
void badReturnTypeSyncStar() sync* {} // //# 03: static type warning
main() {
try {
badReturnTypeAsync(); // //# 01: continued
} catch (e, st) {
Expect.isTrue(e is TypeError, "wrong exception type");
Expect.isTrue(
st.toString().contains("badReturnTypeAsync"), "missing frame");
}
try {
badReturnTypeAsyncStar(); // //# 02: continued
} catch (e, st) {
Expect.isTrue(e is TypeError, "wrong exception type");
Expect.isTrue(
st.toString().contains("badReturnTypeAsyncStar"), "missing frame");
}
try {
badReturnTypeSyncStar(); // //# 03: continued
} catch (e, st) {
Expect.isTrue(e is TypeError, "wrong exception type");
Expect.isTrue(
st.toString().contains("badReturnTypeSyncStar"), "missing frame");
}
}

View file

@ -1,36 +0,0 @@
// 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.
// Regression test for issue 23058.
import "package:expect/expect.dart";
import "package:async_helper/async_helper.dart";
class A {
var x = new B();
foo() async {
return x.foo == 2 ? 42 : x.foo;
}
}
class B {
var x = 0;
get foo {
if (x == -1) {
return 0;
} else {
return x++;
}
}
}
main() {
asyncStart();
new A().foo().then((result) {
Expect.equals(1, result);
asyncEnd();
});
}

View file

@ -1,49 +0,0 @@
// 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";
const String exceptionString = "exceptionalString";
throwString() async {
try {
throw exceptionString;
} catch (e) {
await 1;
throw e;
}
}
rethrowString() async {
try {
throw exceptionString;
} catch (e) {
await 1;
rethrow;
}
}
testThrow() {
Future f = throwString();
f.then((v) {
Expect.fail("Exception not thrown");
}, onError: (e) {
Expect.equals(exceptionString, e);
});
}
testRethrow() {
Future f = rethrowString();
f.then((v) {
Expect.fail("Exception not thrown");
}, onError: (e) {
Expect.equals(exceptionString, e);
});
}
main() {
testThrow();
testRethrow();
}

View file

@ -1,55 +0,0 @@
// 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";
Future foo1() async {
return 3;
}
Future<int> foo2() async {
return 3;
}
Future<int> //# wrongTypeParameter: static type warning
foo3() async {
return "String";
}
// Future<int, String> is treated like Future<dynamic>
Future<int, String> //# tooManyTypeParameters: static type warning
foo4() async {
return "String";
}
int //# wrongReturnType: static type warning, dynamic type error
foo5() async {
return 3;
}
Future<int> foo6() async {
// This is fine, the future is flattened
return new Future<int>.value(3);
}
Future<Future<int>> //# nestedFuture: static type warning
foo7() async {
return new Future<int>.value(3);
}
test() async {
Expect.equals(3, await foo1());
Expect.equals(3, await foo2());
Expect.equals("String", await foo3());
Expect.equals("String", await foo4());
Expect.equals(3, await foo5());
Expect.equals(3, await await foo6());
Expect.equals(3, await await foo7());
}
main() {
asyncTest(test);
}

View file

@ -1,42 +0,0 @@
// 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";
// When an exception is thrown in the finally block cleaning up after a cancel,
// the future returned from cancel should complete with an error.
foo() async* {
try {
int i = 0;
while (true) {
yield i++;
}
} finally {
throw "Error";
}
}
test() async {
var completer = new Completer();
var s;
s = foo().listen((e) async {
Expect.equals(0, e);
try {
await s.cancel();
Expect.fail("Did not throw");
} catch (e) {
Expect.equals("Error", e);
completer.complete();
}
});
await completer.future;
}
main() {
asyncStart();
test().then((_) => asyncEnd());
}

View file

@ -1,68 +0,0 @@
// 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;
}
}
}

View file

@ -1,22 +0,0 @@
// 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();
});
}

View file

@ -1,33 +0,0 @@
// 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.
// Regression test for https://code.google.com/p/dart/issues/detail?id=23116
import "package:expect/expect.dart";
import "package:async_helper/async_helper.dart";
import 'dart:async';
Stream<int> foo(Completer completer, Future future) async* {
completer.complete(100);
int x = await future;
Expect.equals(42, x);
}
test() async {
Completer completer1 = new Completer();
Completer completer2 = new Completer();
StreamSubscription s = foo(completer1, completer2.future).listen((v) => null);
await completer1.future;
// At this moment foo is waiting on the given future.
s.pause();
// Ensure that execution of foo is not resumed - the future is not completed
// yet.
s.resume();
completer2.complete(42);
}
main() {
asyncStart();
test().then((_) => asyncEnd());
}

View file

@ -1,59 +0,0 @@
// 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([
"fisk 3",
"+fisk",
0,
1,
"-fisk",
"done",
"fisk 2",
"+fisk",
0,
1,
"-fisk",
"done",
"fisk 1",
"+fisk",
0,
"-fisk",
"done"
], res);
asyncEnd();
});
}

View file

@ -1,25 +0,0 @@
// 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();
});
}

View file

@ -1,28 +0,0 @@
// 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);
}

View file

@ -8,11 +8,6 @@ assertion_test: RuntimeError
async_await_test/02: DartkCompileTimeError
async_await_test/03: DartkCompileTimeError
async_await_test/none: DartkCompileTimeError
async_star_cancel_and_throw_in_finally_test: RuntimeError
async_star_cancel_while_paused_test: RuntimeError
async_star_regression_fisk_test: Timeout
async_star_stream_take_test: Timeout
async_star_take_reyield_test: Timeout
async_star_test/01: DartkCompileTimeError
async_star_test/02: DartkCompileTimeError
async_star_test/03: DartkCompileTimeError