Linter: move control_flow_in_finally tests
Change-Id: Idf1aaea14ead44969fb8d978b74d33e77aa2dc68 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/328767 Reviewed-by: Phil Quitslund <pquitslund@google.com> Auto-Submit: Samuel Rawlins <srawlins@google.com> Commit-Queue: Phil Quitslund <pquitslund@google.com>
This commit is contained in:
committed by
Commit Queue
parent
64f52c0f0a
commit
a6eb0d08db
@@ -60,6 +60,7 @@ import 'comment_references_test.dart' as comment_references;
|
||||
import 'conditional_uri_does_not_exist_test.dart'
|
||||
as conditional_uri_does_not_exist;
|
||||
import 'constant_identifier_names_test.dart' as constant_identifier_names;
|
||||
import 'control_flow_in_finally_test.dart' as control_flow_in_finally;
|
||||
import 'dangling_library_doc_comments_test.dart'
|
||||
as dangling_library_doc_comments;
|
||||
import 'depend_on_referenced_packages_test.dart'
|
||||
@@ -288,6 +289,7 @@ void main() {
|
||||
comment_references.main();
|
||||
conditional_uri_does_not_exist.main();
|
||||
constant_identifier_names.main();
|
||||
control_flow_in_finally.main();
|
||||
dangling_library_doc_comments.main();
|
||||
depend_on_referenced_packages.main();
|
||||
deprecated_consistency.main();
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
// 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(ControlFlowInFinallyTest);
|
||||
// TODO(srawlins): Add tests with labels.
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class ControlFlowInFinallyTest extends LintRuleTest {
|
||||
@override
|
||||
String get lintRule => 'control_flow_in_finally';
|
||||
|
||||
test_break() async {
|
||||
await assertDiagnostics(r'''
|
||||
void f() {
|
||||
for (var o in [1, 2]) {
|
||||
try {
|
||||
} catch (e) {
|
||||
} finally {
|
||||
if (1 > 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
''', [
|
||||
lint(108, 6),
|
||||
]);
|
||||
}
|
||||
|
||||
test_break_loopDeclaredWithinFinally() async {
|
||||
await assertNoDiagnostics(r'''
|
||||
void f() {
|
||||
try {
|
||||
} catch (e) {
|
||||
} finally {
|
||||
for (var o in [1, 2]) {
|
||||
if (1 > 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
test_continue() async {
|
||||
await assertDiagnostics(r'''
|
||||
void f() {
|
||||
for (var o in [1, 2]) {
|
||||
try {
|
||||
} catch (e) {
|
||||
} finally {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
''', [
|
||||
lint(87, 9),
|
||||
]);
|
||||
}
|
||||
|
||||
test_continue_deep() async {
|
||||
await assertNoDiagnostics(r'''
|
||||
void f() {
|
||||
try {
|
||||
} catch (e) {
|
||||
} finally {
|
||||
for (var o in [1, 2]) {
|
||||
if (1 > 0) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
test_nonControlFlow() async {
|
||||
await assertNoDiagnostics(r'''
|
||||
void f(int i) {
|
||||
try {
|
||||
} catch (e) {
|
||||
} finally {
|
||||
i = i * i;
|
||||
}
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
test_return() async {
|
||||
await assertDiagnostics(r'''
|
||||
void f() {
|
||||
try {
|
||||
} catch (e) {
|
||||
} finally {
|
||||
return;
|
||||
}
|
||||
}
|
||||
''', [
|
||||
lint(53, 7),
|
||||
]);
|
||||
}
|
||||
|
||||
test_returnInClosure() async {
|
||||
await assertNoDiagnostics(r'''
|
||||
void f() {
|
||||
try {
|
||||
} catch (e) {
|
||||
} finally {
|
||||
() {
|
||||
return 1.0;
|
||||
};
|
||||
}
|
||||
}
|
||||
''');
|
||||
}
|
||||
}
|
||||
@@ -1,113 +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.
|
||||
|
||||
class Ok {
|
||||
double compliantMethod() {
|
||||
var i = 5.0;
|
||||
try {
|
||||
i = 1 / 0;
|
||||
} catch (e) {
|
||||
print(e);
|
||||
} finally {
|
||||
i = i * i; // OK
|
||||
}
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
class BadReturn {
|
||||
double nonCompliantMethod() {
|
||||
try {
|
||||
return 1 / 0;
|
||||
} catch (e) {
|
||||
print(e);
|
||||
} finally {
|
||||
return 1.0; // LINT
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class GoodReturn {
|
||||
double? compliantMethod() {
|
||||
try {
|
||||
return 1 / 0;
|
||||
} catch (e) {
|
||||
print(e);
|
||||
} finally {
|
||||
() {
|
||||
return 1.0; // OK
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class BadContinue {
|
||||
double nonCompliantMethod() {
|
||||
for (var o in [1, 2]) {
|
||||
try {
|
||||
print(o / 0);
|
||||
} catch (e) {
|
||||
print(e);
|
||||
} finally {
|
||||
continue; // LINT
|
||||
}
|
||||
}
|
||||
return 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
class GoodContinue {
|
||||
double compliantMethod() {
|
||||
try {
|
||||
print(1 / 0);
|
||||
} catch (e) {
|
||||
print(e);
|
||||
} finally {
|
||||
for (var o in [1, 2]) {
|
||||
print(o);
|
||||
if (1 > 0) {
|
||||
continue; // OK
|
||||
}
|
||||
}
|
||||
}
|
||||
return 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
class BadBreak {
|
||||
double nonCompliantMethod() {
|
||||
for (var o in [1, 2]) {
|
||||
try {
|
||||
print(o / 0);
|
||||
} catch (e) {
|
||||
print(e);
|
||||
} finally {
|
||||
if (1 > 0) {
|
||||
break; // LINT
|
||||
} else {
|
||||
print('should catch nested cases!');
|
||||
}
|
||||
}
|
||||
}
|
||||
return 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
class GoodBreak {
|
||||
double compliantMethod() {
|
||||
try {
|
||||
print(1 / 0);
|
||||
} catch (e) {
|
||||
print(e);
|
||||
} finally {
|
||||
for (var o in [1, 2]) {
|
||||
print(o);
|
||||
if (1 > 0) {
|
||||
break; // OK
|
||||
}
|
||||
}
|
||||
}
|
||||
return 1.0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user