[wildcards] UNUSED_CATCH_CLAUSE tests
Fixes: https://github.com/dart-lang/sdk/issues/55721 Change-Id: I5e675c61a7d1eb0f6192f98146fd2dbd5dd0e2e5 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/366407 Commit-Queue: Phil Quitslund <pquitslund@google.com> Reviewed-by: Kallen Tu <kallentu@google.com>
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
// 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:analyzer/dart/analysis/features.dart';
|
||||
import 'package:analyzer/src/error/codes.g.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
@@ -10,6 +11,7 @@ import '../dart/resolution/context_collection_resolution.dart';
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(UnusedCatchClauseTest);
|
||||
defineReflectiveTests(UnusedCatchClauseTestWildCardVariablesTest);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -27,6 +29,16 @@ main() {
|
||||
]);
|
||||
}
|
||||
|
||||
test_on_unusedStack_wildcard() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
main() {
|
||||
try {
|
||||
} on String catch (exception, _) {
|
||||
}
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
test_on_usedException() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
main() {
|
||||
@@ -48,6 +60,26 @@ main() {
|
||||
''');
|
||||
}
|
||||
|
||||
test_unusedException_underscores() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
main() {
|
||||
try {
|
||||
} catch (__) {
|
||||
}
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
test_unusedException_wildcard() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
main() {
|
||||
try {
|
||||
} catch (_) {
|
||||
}
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
test_usedException() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
main() {
|
||||
@@ -59,3 +91,24 @@ main() {
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class UnusedCatchClauseTestWildCardVariablesTest extends UnusedCatchClauseTest {
|
||||
@override
|
||||
List<String> get experiments => [
|
||||
...super.experiments,
|
||||
Feature.wildcard_variables.enableString,
|
||||
];
|
||||
|
||||
test_on_unusedStack_underscores() async {
|
||||
await assertErrorsInCode(r'''
|
||||
main() {
|
||||
try {
|
||||
} on String catch (exception, __) {
|
||||
}
|
||||
}
|
||||
''', [
|
||||
error(WarningCode.UNUSED_CATCH_STACK, 49, 2),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user