mirror of
https://github.com/dart-lang/sdk
synced 2024-09-04 16:03:44 +00:00
Update language_2/await_test.dart to use async_helper.
Add more tests. See #31535. Bug: http://dartbug.com/31535 Change-Id: I1db9ecb84d9ed87f1111e3fdc9637143cf46fa33 Reviewed-on: https://dart-review.googlesource.com/26220 Commit-Queue: Lasse R.H. Nielsen <lrn@google.com> Reviewed-by: Bob Nystrom <rnystrom@google.com>
This commit is contained in:
parent
7f91a438f5
commit
8dc7d5e907
|
@ -38,7 +38,10 @@ Exception _buildException(String msg) {
|
|||
}
|
||||
|
||||
/// Call this method before an asynchronous test is created.
|
||||
void asyncStart() {
|
||||
///
|
||||
/// If [count] is provided, expect [count] [asyncEnd] calls instead of just one.
|
||||
void asyncStart([int count = 1]) {
|
||||
if (count <= 0) return;
|
||||
if (_initialized && _asyncLevel == 0) {
|
||||
throw _buildException('asyncStart() was called even though we are done '
|
||||
'with testing.');
|
||||
|
@ -48,7 +51,7 @@ void asyncStart() {
|
|||
_initialized = true;
|
||||
_port = new ReceivePort();
|
||||
}
|
||||
_asyncLevel++;
|
||||
_asyncLevel += count;
|
||||
}
|
||||
|
||||
/// Call this after an asynchronous test has ended successfully.
|
||||
|
|
|
@ -35,7 +35,7 @@ Exception _buildException(String msg) {
|
|||
}
|
||||
|
||||
/// Implementation method called from language_tests.js.
|
||||
/// Registers the callback that will be used complete the test.
|
||||
/// Registers the callback that will be used to complete the test.
|
||||
void asyncTestInitialize(_Action0 callback) {
|
||||
_asyncLevel = 0;
|
||||
_initialized = false;
|
||||
|
@ -47,7 +47,10 @@ void asyncTestInitialize(_Action0 callback) {
|
|||
bool get asyncTestStarted => _initialized;
|
||||
|
||||
/// Call this method before an asynchronous test is created.
|
||||
void asyncStart() {
|
||||
///
|
||||
/// If [count] is provided, expect [count] [asyncEnd] calls instead of just one.
|
||||
void asyncStart([int count = 1]) {
|
||||
if (count <= 0) return;
|
||||
if (_initialized && _asyncLevel == 0) {
|
||||
throw _buildException('asyncStart() was called even though we are done '
|
||||
'with testing.');
|
||||
|
@ -61,7 +64,7 @@ void asyncStart() {
|
|||
print('unittest-suite-wait-for-done');
|
||||
_initialized = true;
|
||||
}
|
||||
_asyncLevel++;
|
||||
_asyncLevel += count;
|
||||
}
|
||||
|
||||
/// Call this after an asynchronous test has ended successfully.
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
// VMOptions=---optimization-counter-threshold=10
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
import 'package:async_helper/async_helper.dart';
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
|
@ -89,9 +90,6 @@ instanceMembers() async {
|
|||
Expect.equals(e, 5);
|
||||
}
|
||||
|
||||
await() => 4;
|
||||
nonAsyncFunction() => await();
|
||||
|
||||
others() async {
|
||||
var a = "${globalVariable} ${await dummy()} " + await "someString";
|
||||
Expect.equals(a, "1 1 someString");
|
||||
|
@ -103,7 +101,6 @@ others() async {
|
|||
Expect.equals(b[cnt], 1);
|
||||
var e = b[0] + await dummy();
|
||||
Expect.equals(e, 2);
|
||||
Expect.equals(nonAsyncFunction(), 4);
|
||||
}
|
||||
|
||||
conditionals() async {
|
||||
|
@ -120,12 +117,124 @@ conditionals() async {
|
|||
} catch (e) {}
|
||||
}
|
||||
|
||||
main() {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
staticMembers();
|
||||
topLevelMembers();
|
||||
instanceMembers();
|
||||
conditionals();
|
||||
others();
|
||||
asserts() async {
|
||||
for (final FutureOr<T> Function<T>(T) func in <Function>[id, future]) {
|
||||
assert(await func(true));
|
||||
assert(id(true), await func("message"));
|
||||
assert(await func(true), await (func("message")));
|
||||
bool success = true;
|
||||
try {
|
||||
assert(await func(false), await (func("message")));
|
||||
if (assertStatementsEnabled) Expect.fail("Didn't throw");
|
||||
} on AssertionError catch (e) {
|
||||
Expect.equals("message", e.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
controlFlow() async {
|
||||
for (final FutureOr<T> Function<T>(T) func in <Function>[id, future]) {
|
||||
// For.
|
||||
var c = 0;
|
||||
for (var i = await (func(0)); await func(i < 5); await func(i++)) {
|
||||
c++;
|
||||
}
|
||||
Expect.equals(5, c);
|
||||
// While.
|
||||
c = 0;
|
||||
while (await func(c < 5)) c++;
|
||||
Expect.equals(5, c);
|
||||
// Do-while.
|
||||
c = 0;
|
||||
do {
|
||||
c++;
|
||||
} while (await func(c < 5));
|
||||
Expect.equals(5, c);
|
||||
// If.
|
||||
if (await func(c == 5)) {
|
||||
Expect.equals(5, c);
|
||||
} else {
|
||||
Expect.fail("unreachable");
|
||||
}
|
||||
// Throw.
|
||||
try {
|
||||
throw await func("string");
|
||||
} on String {
|
||||
// OK.
|
||||
}
|
||||
|
||||
try {
|
||||
await (throw "string");
|
||||
} on String {
|
||||
// OK.
|
||||
}
|
||||
// Try/catch/finally
|
||||
try {
|
||||
try {
|
||||
throw "string";
|
||||
} catch (e) {
|
||||
Expect.equals("string", e);
|
||||
Expect.equals(0, await func(0));
|
||||
rethrow;
|
||||
} finally {
|
||||
Expect.equals(0, await func(0));
|
||||
}
|
||||
} catch (e) {
|
||||
Expect.equals(0, await func(0));
|
||||
Expect.equals("string", e);
|
||||
} finally {
|
||||
Expect.equals(0, await func(0));
|
||||
}
|
||||
// Switch
|
||||
switch (await func(2)) {
|
||||
case 2:
|
||||
break;
|
||||
default:
|
||||
Expect.fail("unreachable");
|
||||
}
|
||||
// Return.
|
||||
Expect.equals(
|
||||
42,
|
||||
await () async {
|
||||
return await func(42);
|
||||
}());
|
||||
Expect.equals(
|
||||
42,
|
||||
await () async {
|
||||
return func(42);
|
||||
}());
|
||||
// Yield.
|
||||
Stream<int> testStream1() async* {
|
||||
yield await func(42);
|
||||
}
|
||||
|
||||
Expect.listEquals([42], await testStream1().toList());
|
||||
// Yield*
|
||||
Stream<int> testStream2() async* {
|
||||
yield* await func(intStream());
|
||||
}
|
||||
|
||||
Expect.listEquals([42], await testStream2().toList());
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<T> future<T>(T value) async => value;
|
||||
FutureOr<T> id<T>(T value) => value;
|
||||
|
||||
Stream<int> intStream() async* {
|
||||
yield 42;
|
||||
}
|
||||
|
||||
main() {
|
||||
asyncStart();
|
||||
for (int i = 0; i < 11; i++) {
|
||||
asyncTest(staticMembers);
|
||||
asyncTest(topLevelMembers);
|
||||
asyncTest(instanceMembers);
|
||||
asyncTest(conditionals);
|
||||
asyncTest(others);
|
||||
asyncTest(asserts);
|
||||
asyncTest(controlFlow);
|
||||
}
|
||||
asyncEnd();
|
||||
}
|
||||
|
|
|
@ -467,6 +467,7 @@ generic_no_such_method_dispatcher_simple_test: Skip # This test is just for kern
|
|||
fuzzy_arrows_test/01: MissingCompileTimeError
|
||||
built_in_identifier_type_annotation_test/22: MissingCompileTimeError # Issue 28813
|
||||
built_in_identifier_type_annotation_test/85: Crash # Issue 28813
|
||||
await_test: Crash # Issue 31540
|
||||
|
||||
[ $compiler == dart2analyzer && !$strong ]
|
||||
combiner_type_lookup_indexed_test: StaticWarning # Issue #31484
|
||||
|
|
|
@ -121,6 +121,7 @@ assertion_initializer_const_error2_test/cc11: Pass # Issue #31319
|
|||
assertion_initializer_const_error2_test/none: Pass
|
||||
assertion_initializer_const_function_test/01: Crash
|
||||
assertion_initializer_test: CompileTimeError
|
||||
await_test: Crash # Issue 31540
|
||||
black_listed_test/none: fail # Issue 14228
|
||||
built_in_identifier_prefix_test: CompileTimeError
|
||||
built_in_identifier_type_annotation_test/22: MissingCompileTimeError # Issue 28816
|
||||
|
@ -256,6 +257,7 @@ async_or_generator_return_type_stacktrace_test/02: MissingCompileTimeError
|
|||
async_or_generator_return_type_stacktrace_test/03: MissingCompileTimeError
|
||||
async_return_types_test/tooManyTypeParameters: MissingCompileTimeError
|
||||
async_return_types_test/wrongReturnType: Crash # Maltyped input from Fasta, issue 31414
|
||||
await_test: CompileTimeError # Issue 31541
|
||||
bad_named_parameters2_test/01: MissingCompileTimeError
|
||||
bad_named_parameters_test/01: MissingCompileTimeError
|
||||
bad_named_parameters_test/02: MissingCompileTimeError
|
||||
|
|
|
@ -66,6 +66,7 @@ async_star_test/03: CompileTimeError # Issue 31402 (Invocation arguments)
|
|||
async_star_test/04: CompileTimeError # Issue 31402 (Invocation arguments)
|
||||
async_star_test/05: CompileTimeError # Issue 31402 (Invocation arguments)
|
||||
async_star_test/none: CompileTimeError # Issue 31402 (Invocation arguments)
|
||||
await_test: CompileTimeError # Issue 31541
|
||||
bad_named_parameters2_test/01: MissingCompileTimeError
|
||||
bad_named_parameters_test/01: MissingCompileTimeError
|
||||
bad_named_parameters_test/02: MissingCompileTimeError
|
||||
|
|
Loading…
Reference in a new issue