mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 08:24:39 +00:00
[tests] update await_for_test to test behavior variations.
This introduces an asyncExpectThrowsWhen to async_helper, similar to Expect.throwsWhen, to allow specifying semantics under behavior variations in this test. We also update await_for_test to no longer skip expectations in dart2js. Change-Id: Ie147f74f384a0e196e40b75c59fe585f011ede49 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/351721 Reviewed-by: Lasse Nielsen <lrn@google.com> Reviewed-by: Stephen Adams <sra@google.com> Commit-Queue: Sigmund Cherem <sigmund@google.com>
This commit is contained in:
parent
050afd650f
commit
9a9f23fd35
|
@ -142,3 +142,16 @@ Future<T> asyncExpectThrows<T extends Object>(Future<void> result,
|
|||
return error;
|
||||
});
|
||||
}
|
||||
|
||||
/// Checks that the asynchronous [result] throws a [T] if and only if
|
||||
/// [condition] is `true`.
|
||||
///
|
||||
/// When [condition] is `false`, [result] is expected to complete without
|
||||
/// errors.
|
||||
Future<T?> asyncExpectThrowsWhen<T extends Object>(
|
||||
bool condition, Future<void> result,
|
||||
[String reason = ""]) {
|
||||
return condition
|
||||
? asyncExpectThrows<T>(result, reason)
|
||||
: result.then<T?>((_) => null);
|
||||
}
|
||||
|
|
|
@ -281,42 +281,46 @@ Future<void> testKeyOrder() async {
|
|||
Expect.equals("1:a,2:a", set.join(","));
|
||||
}
|
||||
|
||||
Future<void> testRuntimeErrors() async {
|
||||
// TODO(54798): split these and move them closer to each expectation.
|
||||
if (!v.checkedParameters || !v.checkedImplicitDowncasts) {
|
||||
return;
|
||||
asyncExpectThrowsTypeErrorOrNSM(Future<void> result) {
|
||||
if (v.checkedParameters) {
|
||||
return asyncExpectThrows<TypeError>(result);
|
||||
} else {
|
||||
return asyncExpectThrows<NoSuchMethodError>(result);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> testRuntimeErrors() async {
|
||||
// Cast variable.
|
||||
dynamic nonStream = 3;
|
||||
asyncExpectThrows<TypeError>(() async {
|
||||
asyncExpectThrowsTypeErrorOrNSM(() async {
|
||||
<int>[await for (int i in nonStream) 1];
|
||||
}());
|
||||
asyncExpectThrows<TypeError>(() async {
|
||||
asyncExpectThrowsTypeErrorOrNSM(() async {
|
||||
<int, int>{await for (int i in nonStream) 1: 1};
|
||||
}());
|
||||
asyncExpectThrows<TypeError>(() async {
|
||||
asyncExpectThrowsTypeErrorOrNSM(() async {
|
||||
<int>{await for (int i in nonStream) 1};
|
||||
}());
|
||||
|
||||
// Wrong element type.
|
||||
dynamic nonInt = "string";
|
||||
asyncExpectThrows<TypeError>(() async {
|
||||
asyncExpectThrowsWhen(v.checkedImplicitDowncasts, () async {
|
||||
<int>[
|
||||
await for (var i in stream([1])) nonInt
|
||||
];
|
||||
}());
|
||||
asyncExpectThrows<TypeError>(() async {
|
||||
asyncExpectThrowsWhen(v.checkedImplicitDowncasts, () async {
|
||||
<int, int>{
|
||||
await for (var i in stream([1])) nonInt: 1
|
||||
};
|
||||
}());
|
||||
asyncExpectThrows<TypeError>(() async {
|
||||
asyncExpectThrowsWhen(v.checkedImplicitDowncasts, () async {
|
||||
<int, int>{
|
||||
await for (var i in stream([1])) 1: nonInt
|
||||
};
|
||||
}());
|
||||
asyncExpectThrows<TypeError>(() async {
|
||||
|
||||
asyncExpectThrowsWhen(v.checkedImplicitDowncasts, () async {
|
||||
<int>{
|
||||
await for (var i in stream([1])) nonInt
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue