Skip to content

Commit 6e687d1

Browse files
srawlinscommit-bot@chromium.org
authored andcommitted
analyzer: move tests to 4 new test files in diagnostics/
Change-Id: Ied68dc6a383c7ca0a44dbcd8381f3a94832d44fe Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/153903 Commit-Queue: Samuel Rawlins <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent 90ce990 commit 6e687d1

7 files changed

+242
-188
lines changed

pkg/analyzer/test/generated/static_type_warning_code_test.dart

Lines changed: 3 additions & 188 deletions
Original file line numberDiff line numberDiff line change
@@ -190,36 +190,6 @@ void main() {
190190
]);
191191
}
192192

193-
test_expectedOneListTypeArgument() async {
194-
await assertErrorsInCode(r'''
195-
main() {
196-
<int, int> [];
197-
}
198-
''', [
199-
error(StaticTypeWarningCode.EXPECTED_ONE_LIST_TYPE_ARGUMENTS, 11, 10),
200-
]);
201-
}
202-
203-
test_expectedOneSetTypeArgument() async {
204-
await assertErrorsInCode(r'''
205-
main() {
206-
<int, int, int>{2, 3};
207-
}
208-
''', [
209-
error(StaticTypeWarningCode.EXPECTED_ONE_SET_TYPE_ARGUMENTS, 11, 15),
210-
]);
211-
}
212-
213-
test_expectedTwoMapTypeArguments_three() async {
214-
await assertErrorsInCode(r'''
215-
main() {
216-
<int, int, int> {};
217-
}
218-
''', [
219-
error(StaticTypeWarningCode.EXPECTED_TWO_MAP_TYPE_ARGUMENTS, 11, 15),
220-
]);
221-
}
222-
223193
test_forIn_declaredVariableRightType() async {
224194
await assertErrorsInCode('''
225195
f() {
@@ -476,106 +446,9 @@ class C {
476446
]);
477447
}
478448

479-
test_instanceAccessToStaticMember_method_reference() async {
480-
await assertErrorsInCode(r'''
481-
class A {
482-
static m() {}
483-
}
484-
main(A a) {
485-
a.m;
486-
}
487-
''', [
488-
error(StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER, 44, 1),
489-
]);
490-
}
491-
492-
test_instanceAccessToStaticMember_propertyAccess_field() async {
493-
await assertErrorsInCode(r'''
494-
class A {
495-
static var f;
496-
}
497-
main(A a) {
498-
a.f;
499-
}
500-
''', [
501-
error(StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER, 44, 1),
502-
]);
503-
}
504-
505-
test_instanceAccessToStaticMember_propertyAccess_getter() async {
506-
await assertErrorsInCode(r'''
507-
class A {
508-
static get f => 42;
509-
}
510-
main(A a) {
511-
a.f;
512-
}
513-
''', [
514-
error(StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER, 50, 1),
515-
]);
516-
}
517-
518-
test_instanceAccessToStaticMember_propertyAccess_setter() async {
519-
await assertErrorsInCode(r'''
520-
class A {
521-
static set f(x) {}
522-
}
523-
main(A a) {
524-
a.f = 42;
525-
}
526-
''', [
527-
error(StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER, 49, 1),
528-
]);
529-
}
530-
531-
test_invocationOfNonFunctionExpression_literal() async {
532-
await assertErrorsInCode(r'''
533-
f() {
534-
3(5);
535-
}
536-
''', [
537-
error(StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION_EXPRESSION, 8, 1),
538-
]);
539-
}
540-
541-
test_nonTypeAsTypeArgument_notAType() async {
542-
await assertErrorsInCode(r'''
543-
int A;
544-
class B<E> {}
545-
f(B<A> b) {}
546-
''', [
547-
error(StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT, 25, 1),
548-
]);
549-
}
550-
551-
test_nonTypeAsTypeArgument_undefinedIdentifier() async {
552-
await assertErrorsInCode(r'''
553-
class B<E> {}
554-
f(B<A> b) {}
555-
''', [
556-
error(StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT, 18, 1),
557-
]);
558-
}
559-
560-
test_typeParameterSupertypeOfItsBound_1of1() async {
561-
await assertErrorsInCode(r'''
562-
class A<T extends T> {
563-
}
564-
''', [
565-
error(StaticTypeWarningCode.TYPE_PARAMETER_SUPERTYPE_OF_ITS_BOUND, 8, 11),
566-
]);
567-
}
568-
569-
test_typeParameterSupertypeOfItsBound_2of3() async {
570-
await assertErrorsInCode(r'''
571-
class A<T1 extends T3, T2, T3 extends T1> {
572-
}
573-
''', [
574-
error(StaticTypeWarningCode.TYPE_PARAMETER_SUPERTYPE_OF_ITS_BOUND, 8, 13),
575-
error(
576-
StaticTypeWarningCode.TYPE_PARAMETER_SUPERTYPE_OF_ITS_BOUND, 27, 13),
577-
]);
578-
}
449+
// TODO(srawlins) Figure out what to do with the rest of these tests.
450+
// The names do not correspond to diagnostic codes, so it isn't clear what
451+
// they're testing.
579452

580453
test_typePromotion_booleanAnd_useInRight_accessedInClosureRight_mutated() async {
581454
await assertErrorsInCode(r'''
@@ -823,64 +696,6 @@ main(A<V> p) {
823696
]);
824697
}
825698

826-
test_unqualifiedReferenceToNonLocalStaticMember_getter() async {
827-
await assertErrorsInCode(r'''
828-
class A {
829-
static int get a => 0;
830-
}
831-
class B extends A {
832-
int b() {
833-
return a;
834-
}
835-
}
836-
''', [
837-
error(
838-
StaticTypeWarningCode
839-
.UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER,
840-
80,
841-
1),
842-
]);
843-
}
844-
845-
test_unqualifiedReferenceToNonLocalStaticMember_getter_invokeTarget() async {
846-
await assertErrorsInCode(r'''
847-
class A {
848-
static int foo;
849-
}
850-
851-
class B extends A {
852-
static bar() {
853-
foo.abs();
854-
}
855-
}
856-
''', [
857-
error(
858-
StaticTypeWarningCode
859-
.UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER,
860-
72,
861-
3),
862-
]);
863-
}
864-
865-
test_unqualifiedReferenceToNonLocalStaticMember_setter() async {
866-
await assertErrorsInCode(r'''
867-
class A {
868-
static set a(x) {}
869-
}
870-
class B extends A {
871-
b(y) {
872-
a = y;
873-
}
874-
}
875-
''', [
876-
error(
877-
StaticTypeWarningCode
878-
.UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER,
879-
66,
880-
1),
881-
]);
882-
}
883-
884699
test_wrongNumberOfTypeArguments() async {
885700
await assertErrorsInCode(r'''
886701
class A<E> {

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

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,56 @@ f(C c) {
7575
findElement.setter('a'),
7676
);
7777
}
78+
79+
test_method_reference() async {
80+
await assertErrorsInCode(r'''
81+
class A {
82+
static m() {}
83+
}
84+
main(A a) {
85+
a.m;
86+
}
87+
''', [
88+
error(StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER, 44, 1),
89+
]);
90+
}
91+
92+
test_propertyAccess_field() async {
93+
await assertErrorsInCode(r'''
94+
class A {
95+
static var f;
96+
}
97+
main(A a) {
98+
a.f;
99+
}
100+
''', [
101+
error(StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER, 44, 1),
102+
]);
103+
}
104+
105+
test_propertyAccess_getter() async {
106+
await assertErrorsInCode(r'''
107+
class A {
108+
static get f => 42;
109+
}
110+
main(A a) {
111+
a.f;
112+
}
113+
''', [
114+
error(StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER, 50, 1),
115+
]);
116+
}
117+
118+
test_propertyAccess_setter() async {
119+
await assertErrorsInCode(r'''
120+
class A {
121+
static set f(x) {}
122+
}
123+
main(A a) {
124+
a.f = 42;
125+
}
126+
''', [
127+
error(StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER, 49, 1),
128+
]);
129+
}
78130
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) 2020, 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:test_reflective_loader/test_reflective_loader.dart';
7+
8+
import '../dart/resolution/driver_resolution.dart';
9+
10+
main() {
11+
defineReflectiveSuite(() {
12+
defineReflectiveTests(InvocationOfNonFunctionExpressionTest);
13+
});
14+
}
15+
16+
@reflectiveTest
17+
class InvocationOfNonFunctionExpressionTest extends DriverResolutionTest {
18+
test_invocationOfNonFunctionExpression_literal() async {
19+
await assertErrorsInCode(r'''
20+
f() {
21+
3(5);
22+
}
23+
''', [
24+
error(StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION_EXPRESSION, 8, 1),
25+
]);
26+
}
27+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright (c) 2020, 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:test_reflective_loader/test_reflective_loader.dart';
7+
8+
import '../dart/resolution/driver_resolution.dart';
9+
10+
main() {
11+
defineReflectiveSuite(() {
12+
defineReflectiveTests(NonTypeAsTypeArgumentTest);
13+
});
14+
}
15+
16+
@reflectiveTest
17+
class NonTypeAsTypeArgumentTest extends DriverResolutionTest {
18+
test_notAType() async {
19+
await assertErrorsInCode(r'''
20+
int A;
21+
class B<E> {}
22+
f(B<A> b) {}
23+
''', [
24+
error(StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT, 25, 1),
25+
]);
26+
}
27+
28+
test_undefinedIdentifier() async {
29+
await assertErrorsInCode(r'''
30+
class B<E> {}
31+
f(B<A> b) {}
32+
''', [
33+
error(StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT, 18, 1),
34+
]);
35+
}
36+
}

0 commit comments

Comments
 (0)