Skip to content

Commit

Permalink
Add tests for throwing async return
Browse files Browse the repository at this point in the history
Cf. #44395.

Change-Id: I753a6a4fae65c50267d8cf1575d2ce87e7ac345b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/175064
Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
Commit-Queue: Erik Ernst <eernst@google.com>
  • Loading branch information
eernstg authored and commit-bot@chromium.org committed Dec 4, 2020
1 parent 224351b commit 073acc7
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tests/language/async/return_throw_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) 2020, 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";

Future<String> f() async {
throw 'f';
}

Future<String> g() async {
try {
// Should obtain the `Future<String>`, await it, then throw.
return f();
} catch (e) {
// Having caught the exception, we return a value.
return 'g';
}
}

void main() async {
Expect.equals('g', await g());
}
23 changes: 23 additions & 0 deletions tests/language_2/async/return_throw_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) 2020, 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";

Future<String> f() async {
throw 'f';
}

Future<String> g() async {
try {
// Should obtain the `Future<String>`, await it, then throw.
return f();
} catch (e) {
// Having caught the exception, we return a value.
return 'g';
}
}

void main() async {
Expect.equals('g', await g());
}

0 comments on commit 073acc7

Please sign in to comment.