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

Commit 8aabbf3

Browse files
srawlinscommit-bot@chromium.org
authored andcommitted
Move last meta-based hint code tests to diagnostics:
* INVALID_FACTORY_ANNOTATION * INVALID_FACTORY_METHOD_IMPL * INVALID_USE_OF_PROTECTED_MEMBER * INVALID_USE_OF_VISIBLE_FOR_TEMPLATE * INVALID_USE_OF_VISIBLE_FOR_TESTING * MISSING_REQUIRED_PARAM Change-Id: I3bb556f140dd61d8c707ae8db7ec2ce36d01ed97 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/98451 Commit-Queue: Samuel Rawlins <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent 6d934b9 commit 8aabbf3

8 files changed

+1320
-1279
lines changed

pkg/analyzer/test/generated/hint_code_test.dart

Lines changed: 55 additions & 1279 deletions
Large diffs are not rendered by default.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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(InvalidFactoryAnnotationTest);
14+
});
15+
}
16+
17+
@reflectiveTest
18+
class InvalidFactoryAnnotationTest extends DriverResolutionTest
19+
with PackageMixin {
20+
test_class() async {
21+
addMetaPackage();
22+
await assertErrorsInCode(r'''
23+
import 'package:meta/meta.dart';
24+
@factory
25+
class X {
26+
}
27+
''', [HintCode.INVALID_FACTORY_ANNOTATION]);
28+
}
29+
30+
test_field() async {
31+
addMetaPackage();
32+
await assertErrorsInCode(r'''
33+
import 'package:meta/meta.dart';
34+
class X {
35+
@factory
36+
int x;
37+
}
38+
''', [HintCode.INVALID_FACTORY_ANNOTATION]);
39+
}
40+
41+
test_topLevelFunction() async {
42+
addMetaPackage();
43+
await assertErrorsInCode(r'''
44+
import 'package:meta/meta.dart';
45+
@factory
46+
main() { }
47+
''', [HintCode.INVALID_FACTORY_ANNOTATION]);
48+
}
49+
}
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
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(InvalidFactoryMethodImplTest);
14+
});
15+
}
16+
17+
@reflectiveTest
18+
class InvalidFactoryMethodImplTest extends DriverResolutionTest
19+
with PackageMixin {
20+
test_expr_returnNull() async {
21+
addMetaPackage();
22+
await assertNoErrorsInCode(r'''
23+
import 'package:meta/meta.dart';
24+
class Stateful {
25+
@factory
26+
State createState() => null;
27+
}
28+
class State { }
29+
''');
30+
}
31+
32+
test_abstract() async {
33+
addMetaPackage();
34+
await assertNoErrorsInCode(r'''
35+
import 'package:meta/meta.dart';
36+
abstract class Stateful {
37+
@factory
38+
State createState();
39+
}
40+
class State { }
41+
''');
42+
}
43+
44+
test_badReturn() async {
45+
addMetaPackage();
46+
await assertErrorsInCode(r'''
47+
import 'package:meta/meta.dart';
48+
class Stateful {
49+
State _s = new State();
50+
51+
@factory
52+
State createState() => _s;
53+
}
54+
class State { }
55+
''', [HintCode.INVALID_FACTORY_METHOD_IMPL]);
56+
}
57+
58+
test_block() async {
59+
addMetaPackage();
60+
await assertNoErrorsInCode(r'''
61+
import 'package:meta/meta.dart';
62+
class Stateful {
63+
@factory
64+
State createState() {
65+
return new State();
66+
}
67+
}
68+
class State { }
69+
''');
70+
}
71+
72+
test_block_returnNull() async {
73+
addMetaPackage();
74+
await assertNoErrorsInCode(r'''
75+
import 'package:meta/meta.dart';
76+
class Stateful {
77+
@factory
78+
State createState() {
79+
return null;
80+
}
81+
}
82+
class State { }
83+
''');
84+
}
85+
86+
test_expr() async {
87+
addMetaPackage();
88+
await assertNoErrorsInCode(r'''
89+
import 'package:meta/meta.dart';
90+
class Stateful {
91+
@factory
92+
State createState() => new State();
93+
}
94+
class State { }
95+
''');
96+
}
97+
98+
test_noReturnType() async {
99+
addMetaPackage();
100+
// Null return types will get flagged elsewhere, no need to pile on here.
101+
await assertNoErrorsInCode(r'''
102+
import 'package:meta/meta.dart';
103+
class Stateful {
104+
@factory
105+
createState() {
106+
return new Stateful();
107+
}
108+
}
109+
''');
110+
}
111+
112+
test_subclass() async {
113+
addMetaPackage();
114+
await assertNoErrorsInCode(r'''
115+
import 'package:meta/meta.dart';
116+
abstract class Stateful {
117+
@factory
118+
State createState();
119+
}
120+
class MyThing extends Stateful {
121+
@override
122+
State createState() {
123+
print('my state');
124+
return new MyState();
125+
}
126+
}
127+
class State { }
128+
class MyState extends State { }
129+
''');
130+
}
131+
132+
test_voidReturn() async {
133+
addMetaPackage();
134+
await assertErrorsInCode(r'''
135+
import 'package:meta/meta.dart';
136+
137+
class Stateful {
138+
@factory
139+
void createState() {}
140+
}
141+
''', [HintCode.INVALID_FACTORY_METHOD_DECL]);
142+
}
143+
}

0 commit comments

Comments
 (0)