-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[wildcard-variables] Add async rethrow test and wildcard patterns.
Fix follow up comments with an async rethrow test. Tests that wildcard patterns still work while mixed with wildcard variables. Bug: #55652 Change-Id: If6ab4de68ff27ad51215427a7183f1aed7229947 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/367501 Reviewed-by: Erik Ernst <eernst@google.com> Commit-Queue: Kallen Tu <kallentu@google.com>
- Loading branch information
Showing
6 changed files
with
112 additions
and
12 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
tests/language/wildcard_variables/multiple/local_declaration_catch_rethrow_async_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Copyright (c) 2024, 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. | ||
|
||
// Tests multiple catch clause wildcard variable declarations with rethrow and | ||
// awaits. | ||
|
||
// SharedOptions=--enable-experiment=wildcard-variables | ||
|
||
import 'package:expect/expect.dart'; | ||
import "package:async_helper/async_helper.dart"; | ||
|
||
void main() async { | ||
asyncStart(); | ||
test().then((_) => asyncEnd()); | ||
} | ||
|
||
Future<void> test() async { | ||
var tryValue = Future<int>.value(1); | ||
var catchValue = Future<int>.value(1); | ||
|
||
var error = StateError("State bad!"); | ||
var stack = StackTrace.fromString("My stack trace"); | ||
var caught = false; | ||
|
||
// Multiple wildcard catch clause variables. | ||
try { | ||
try { | ||
await tryValue; | ||
Error.throwWithStackTrace(error, stack); | ||
} on StateError catch (_, _) { | ||
await catchValue; | ||
caught = true; | ||
rethrow; | ||
} | ||
} on StateError catch (e, s) { | ||
Expect.isTrue(caught); | ||
Expect.identical(error, e); | ||
Expect.equals(stack.toString(), s.toString()); | ||
Expect.equals(stack.toString(), e.stackTrace.toString()); | ||
} | ||
|
||
// Single wildcard catch clause variable. | ||
try { | ||
try { | ||
await tryValue; | ||
Error.throwWithStackTrace(error, stack); | ||
} on StateError catch (_) { | ||
await catchValue; | ||
caught = true; | ||
rethrow; | ||
} | ||
} on StateError catch (e, s) { | ||
Expect.isTrue(caught); | ||
Expect.identical(error, e); | ||
Expect.equals(stack.toString(), s.toString()); | ||
Expect.equals(stack.toString(), e.stackTrace.toString()); | ||
} | ||
|
||
try { | ||
try { | ||
await tryValue; | ||
Error.throwWithStackTrace(error, stack); | ||
} on StateError catch (_, s) { | ||
await catchValue; | ||
Expect.equals(stack.toString(), s.toString()); | ||
caught = true; | ||
rethrow; | ||
} | ||
} on StateError catch (e, s) { | ||
Expect.isTrue(caught); | ||
Expect.identical(error, e); | ||
Expect.equals(stack.toString(), s.toString()); | ||
Expect.equals(stack.toString(), e.stackTrace.toString()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters