Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 05be278

Browse files
srawlinscommit-bot@chromium.org
authored andcommitted
Split MISSING_RETURN tests
Change-Id: I001d3dd2f1c2d1200ede738aa8d838fc0924ba1a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/95960 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Samuel Rawlins <srawlins@google.com>
1 parent 1dd4559 commit 05be278

File tree

4 files changed

+113
-152
lines changed

4 files changed

+113
-152
lines changed

pkg/analyzer/test/generated/hint_code_test.dart

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,78 +1356,6 @@ dynamic variable;
13561356
verify([source]);
13571357
}
13581358

1359-
test_missingReturn_async() async {
1360-
Source source = addSource('''
1361-
import 'dart:async';
1362-
Future<int> f() async {}
1363-
''');
1364-
await computeAnalysisResult(source);
1365-
assertErrors(source, [HintCode.MISSING_RETURN]);
1366-
verify([source]);
1367-
}
1368-
1369-
test_missingReturn_factory() async {
1370-
Source source = addSource(r'''
1371-
class A {
1372-
factory A() {}
1373-
}
1374-
''');
1375-
await computeAnalysisResult(source);
1376-
assertErrors(source, [HintCode.MISSING_RETURN]);
1377-
verify([source]);
1378-
}
1379-
1380-
test_missingReturn_function() async {
1381-
Source source = addSource("int f() {}");
1382-
await computeAnalysisResult(source);
1383-
assertErrors(source, [HintCode.MISSING_RETURN]);
1384-
verify([source]);
1385-
}
1386-
1387-
test_missingReturn_method() async {
1388-
Source source = addSource(r'''
1389-
class A {
1390-
int m() {}
1391-
}''');
1392-
await computeAnalysisResult(source);
1393-
assertErrors(source, [HintCode.MISSING_RETURN]);
1394-
verify([source]);
1395-
}
1396-
1397-
test_missingReturn_method_inferred() async {
1398-
Source source = addSource(r'''
1399-
abstract class A {
1400-
int m();
1401-
}
1402-
class B extends A {
1403-
m() {}
1404-
}
1405-
''');
1406-
await computeAnalysisResult(source);
1407-
assertErrors(source, [HintCode.MISSING_RETURN]);
1408-
verify([source]);
1409-
}
1410-
1411-
test_no_missingReturn_async_futureOrVoid() async {
1412-
Source source = addSource('''
1413-
import 'dart:async';
1414-
FutureOr<void> f(Future f) async {}
1415-
''');
1416-
await computeAnalysisResult(source);
1417-
assertNoErrors(source);
1418-
verify([source]);
1419-
}
1420-
1421-
test_no_missingReturn_async_futureVoid() async {
1422-
Source source = addSource('''
1423-
import 'dart:async';
1424-
Future<void> f() async {}
1425-
''');
1426-
await computeAnalysisResult(source);
1427-
assertNoErrors(source);
1428-
verify([source]);
1429-
}
1430-
14311359
test_nullAwareBeforeOperator_minus() async {
14321360
Source source = addSource(r'''
14331361
m(x) {

pkg/analyzer/test/generated/non_hint_code.dart

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,6 @@ import 'package:analyzer/src/generated/source_io.dart';
99
import 'resolver_test_case.dart';
1010

1111
abstract class NonHintCodeTest extends ResolverTestCase {
12-
@override
13-
void reset() {
14-
super.resetWith(packages: [
15-
[
16-
'meta',
17-
r'''
18-
library meta;
19-
20-
const _AlwaysThrows alwaysThrows = const _AlwaysThrows();
21-
const _Literal literal = const _Literal();
22-
23-
class _AlwaysThrows {
24-
const _AlwaysThrows();
25-
}
26-
class _Literal {
27-
const _Literal();
28-
}
29-
'''
30-
]
31-
]);
32-
}
33-
3412
test_async_future_object_without_return() async {
3513
Source source = addSource('''
3614
import 'dart:async';
@@ -147,64 +125,6 @@ f(var message) {
147125
verify([source]);
148126
}
149127

150-
test_missingReturn_alwaysThrows() async {
151-
Source source = addSource(r'''
152-
import 'package:meta/meta.dart';
153-
154-
@alwaysThrows
155-
void a() {
156-
throw 'msg';
157-
}
158-
159-
int f() {
160-
a();
161-
}''');
162-
await computeAnalysisResult(source);
163-
assertNoErrors(source);
164-
verify([source]);
165-
}
166-
167-
test_missingReturn_emptyFunctionBody() async {
168-
Source source = addSource(r'''
169-
abstract class A {
170-
int m();
171-
}''');
172-
await computeAnalysisResult(source);
173-
assertNoErrors(source);
174-
verify([source]);
175-
}
176-
177-
test_missingReturn_expressionFunctionBody() async {
178-
Source source = addSource("int f() => 0;");
179-
await computeAnalysisResult(source);
180-
assertNoErrors(source);
181-
verify([source]);
182-
}
183-
184-
test_missingReturn_futureVoidReturnType() async {
185-
Source source = addSource('''
186-
import 'dart:async';
187-
Future<void> f() async {}
188-
''');
189-
await computeAnalysisResult(source);
190-
assertNoErrors(source);
191-
verify([source]);
192-
}
193-
194-
test_missingReturn_noReturnType() async {
195-
Source source = addSource("f() {}");
196-
await computeAnalysisResult(source);
197-
assertNoErrors(source);
198-
verify([source]);
199-
}
200-
201-
test_missingReturn_voidReturnType() async {
202-
Source source = addSource("void f() {}");
203-
await computeAnalysisResult(source);
204-
assertNoErrors(source);
205-
verify([source]);
206-
}
207-
208128
test_nullAwareInCondition_for_noCondition() async {
209129
Source source = addSource(r'''
210130
m(x) {
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:analyzer/src/error/codes.dart';
6+
import 'package:analyzer/src/test_utilities/package_mixin.dart';
7+
import 'package:test_reflective_loader/test_reflective_loader.dart';
8+
9+
import '../dart/resolution/driver_resolution.dart';
10+
11+
main() {
12+
defineReflectiveSuite(() {
13+
defineReflectiveTests(MissingReturnTest);
14+
});
15+
}
16+
17+
@reflectiveTest
18+
class MissingReturnTest extends DriverResolutionTest with PackageMixin {
19+
test_async() async {
20+
await assertErrorsInCode(r'''
21+
import 'dart:async';
22+
Future<int> f() async {}
23+
''', [HintCode.MISSING_RETURN]);
24+
}
25+
26+
test_factory() async {
27+
await assertErrorsInCode(r'''
28+
class A {
29+
factory A() {}
30+
}
31+
''', [HintCode.MISSING_RETURN]);
32+
}
33+
34+
test_function() async {
35+
await assertErrorsInCode(r'''
36+
int f() {}
37+
''', [HintCode.MISSING_RETURN]);
38+
}
39+
40+
test_method() async {
41+
await assertErrorsInCode(r'''
42+
class A {
43+
int m() {}
44+
}''', [HintCode.MISSING_RETURN]);
45+
}
46+
47+
test_method_inferred() async {
48+
await assertErrorsInCode(r'''
49+
abstract class A {
50+
int m();
51+
}
52+
class B extends A {
53+
m() {}
54+
}
55+
''', [HintCode.MISSING_RETURN]);
56+
}
57+
58+
test_emptyFunctionBody() async {
59+
await assertNoErrorsInCode(r'''
60+
abstract class A {
61+
int m();
62+
}''');
63+
}
64+
65+
test_expressionFunctionBody() async {
66+
await assertNoErrorsInCode(r'''
67+
int f() => 0;
68+
''');
69+
}
70+
71+
test_async_futureVoid() async {
72+
await assertNoErrorsInCode(r'''
73+
import 'dart:async';
74+
Future<void> f() async {}
75+
''');
76+
}
77+
78+
test_async_futureOrVoid() async {
79+
await assertNoErrorsInCode(r'''
80+
import 'dart:async';
81+
FutureOr<void> f(Future f) async {}
82+
''');
83+
}
84+
85+
test_noReturnType() async {
86+
await assertNoErrorsInCode(r'''
87+
f() {}
88+
''');
89+
}
90+
91+
test_voidReturnType() async {
92+
await assertNoErrorsInCode(r'''
93+
void f() {}
94+
''');
95+
}
96+
97+
test_alwaysThrows() async {
98+
addMetaPackage();
99+
await assertNoErrorsInCode(r'''
100+
import 'package:meta/meta.dart';
101+
102+
@alwaysThrows
103+
void a() {
104+
throw 'msg';
105+
}
106+
107+
int f() {
108+
a();
109+
}''');
110+
}
111+
}

pkg/analyzer/test/src/diagnostics/test_all.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import 'invalid_override_different_default_values_positional_test.dart'
2222
as invalid_override_different_default_values_positional;
2323
import 'invalid_required_param_test.dart' as invalid_required_param;
2424
import 'invalid_sealed_annotation_test.dart' as invalid_sealed_annotation;
25+
import 'missing_return_test.dart' as missing_return;
2526
import 'mixin_on_sealed_class_test.dart' as mixin_on_sealed_class;
2627
import 'must_be_immutable_test.dart' as must_be_immutable;
2728
import 'must_call_super_test.dart' as must_call_super;
@@ -70,6 +71,7 @@ main() {
7071
invalid_override_different_default_values_positional.main();
7172
invalid_required_param.main();
7273
invalid_sealed_annotation.main();
74+
missing_return.main();
7375
mixin_on_sealed_class.main();
7476
must_be_immutable.main();
7577
must_call_super.main();

0 commit comments

Comments
 (0)