Move empty_catches tests (#4489)
diff --git a/test/rules/all.dart b/test/rules/all.dart index fe28e33..28de7cb 100644 --- a/test/rules/all.dart +++ b/test/rules/all.dart
@@ -49,6 +49,7 @@ as deprecated_member_use_from_same_package; import 'directives_ordering_test.dart' as directives_ordering; import 'discarded_futures_test.dart' as discarded_futures; +import 'empty_catches_test.dart' as empty_catches; import 'empty_statements_test.dart' as empty_statements; import 'eol_at_end_of_file_test.dart' as eol_at_end_of_file; import 'exhaustive_cases_test.dart' as exhaustive_cases; @@ -187,6 +188,7 @@ deprecated_member_use_from_same_package.main(); directives_ordering.main(); discarded_futures.main(); + empty_catches.main(); empty_statements.main(); eol_at_end_of_file.main(); exhaustive_cases.main();
diff --git a/test/rules/empty_catches_test.dart b/test/rules/empty_catches_test.dart new file mode 100644 index 0000000..07c8e31 --- /dev/null +++ b/test/rules/empty_catches_test.dart
@@ -0,0 +1,64 @@ +// 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(EmptyCatchesTest); + }); +} + +@reflectiveTest +class EmptyCatchesTest extends LintRuleTest { + @override + String get lintRule => 'empty_catches'; + test_comment() async { + await assertNoDiagnostics(r''' +void foo() { + try { + throw new Exception(); + } catch (e) { + // Nothing. + } +} +'''); + } + + test_emptyCatch() async { + await assertDiagnostics(r''' +void foo() { + try { + throw Exception(); + } catch (e) {} +} +''', [ + lint(58, 2), + ]); + } + + test_statement() async { + await assertNoDiagnostics(r''' +void foo() { + try { + throw new Exception(); + } catch (e) { + print(e); + } +} +'''); + } + + test_underscore() async { + await assertNoDiagnostics(r''' +void foo() { + try { + throw Exception(); + } catch (_) {} +} +'''); + } +}
diff --git a/test_data/rules/empty_catches.dart b/test_data/rules/empty_catches.dart deleted file mode 100644 index 26e3009..0000000 --- a/test_data/rules/empty_catches.dart +++ /dev/null
@@ -1,28 +0,0 @@ -// Copyright (c) 2016, 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. - -// test w/ `dart test -N empty_catches` - -void foo() { - try { - throw new Exception(); - } catch (_) { } //OK - - try { - throw new Exception(); - } catch (e) { } //LINT - - try { - throw new Exception(); - } catch (e) { - // Nothing. - } //OK! - - try { - throw new Exception(); - } catch (e) { - print(e); - } //OK - -}