a409a1c07d
This helps to avoid any accidental mispellings, enables find usages, and potentially makes future renames easier. The primary goal is to make future work in https://github.com/dart-lang/sdk/issues/56835 easier. Change-Id: I684630a4d6cb145031de0dabc221f247246ea00c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388042 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Auto-Submit: Parker Lougheed <parlough@gmail.com> Commit-Queue: Phil Quitslund <pquitslund@google.com> Reviewed-by: Phil Quitslund <pquitslund@google.com>
97 lines
1.7 KiB
Dart
97 lines
1.7 KiB
Dart
// Copyright (c) 2023, 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:test_reflective_loader/test_reflective_loader.dart';
|
|
|
|
import '../rule_test_support.dart';
|
|
|
|
main() {
|
|
defineReflectiveSuite(() {
|
|
defineReflectiveTests(AvoidCatchingErrorsTest);
|
|
});
|
|
}
|
|
|
|
@reflectiveTest
|
|
class AvoidCatchingErrorsTest extends LintRuleTest {
|
|
@override
|
|
String get lintRule => LintNames.avoid_catching_errors;
|
|
|
|
test_doesNotSubclassError() async {
|
|
await assertNoDiagnostics(r'''
|
|
void f() {
|
|
try {} on String catch (_) {}
|
|
}
|
|
''');
|
|
}
|
|
|
|
test_exactlyError() async {
|
|
await assertDiagnostics(r'''
|
|
void f() {
|
|
try {} on Error catch (_) {}
|
|
}
|
|
''', [
|
|
lint(20, 21),
|
|
]);
|
|
}
|
|
|
|
test_exactlyException() async {
|
|
await assertNoDiagnostics(r'''
|
|
void f() {
|
|
try {} on Exception catch (_) {}
|
|
}
|
|
''');
|
|
}
|
|
|
|
test_typeExtendsError() async {
|
|
await assertDiagnostics(r'''
|
|
void f() {
|
|
try {} on C {}
|
|
}
|
|
|
|
class C extends Error {}
|
|
class D extends C {}
|
|
''', [
|
|
lint(20, 7),
|
|
]);
|
|
}
|
|
|
|
test_typeExtendsTypeThatExtendsError() async {
|
|
await assertDiagnostics(r'''
|
|
void f() {
|
|
try {} on D {}
|
|
}
|
|
|
|
class D extends C {}
|
|
class C extends Error {}
|
|
''', [
|
|
lint(20, 7),
|
|
]);
|
|
}
|
|
|
|
test_typeExtendsTypeThatImplementsError() async {
|
|
await assertDiagnostics(r'''
|
|
void f() {
|
|
try {} on B catch (_) {}
|
|
}
|
|
|
|
abstract class A implements Error {}
|
|
abstract class B extends A {}
|
|
''', [
|
|
lint(20, 17),
|
|
]);
|
|
}
|
|
|
|
test_typeImplementsError() async {
|
|
await assertDiagnostics(r'''
|
|
void f() {
|
|
try {} on A catch (_) {}
|
|
}
|
|
|
|
abstract class A implements Error {}
|
|
''', [
|
|
lint(20, 17),
|
|
]);
|
|
}
|
|
}
|