Skip to content

Commit b0d4c35

Browse files
srawlinscommit-bot@chromium.org
authored andcommitted
Move tests for 4 codes to diagnostics directory.
Also add some tests for function-typed field formal parameters. Change-Id: Ia6cb23c15e695a540ac3c6df0a7af8110a8fc1f8 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/151181 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent 8d08bbf commit b0d4c35

File tree

6 files changed

+248
-152
lines changed

6 files changed

+248
-152
lines changed

pkg/analyzer/test/generated/compile_time_error_code.dart

Lines changed: 0 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -844,121 +844,6 @@ class B extends A {
844844
]);
845845
}
846846

847-
test_fieldInitializerFactoryConstructor() async {
848-
await assertErrorsInCode(r'''
849-
class A {
850-
int x;
851-
factory A(this.x) => throw 0;
852-
}
853-
''', [
854-
error(CompileTimeErrorCode.FIELD_INITIALIZER_FACTORY_CONSTRUCTOR, 31, 6),
855-
]);
856-
}
857-
858-
test_fieldInitializerOutsideConstructor() async {
859-
// TODO(brianwilkerson) Fix the duplicate error messages.
860-
await assertErrorsInCode(r'''
861-
class A {
862-
int x;
863-
m(this.x) {}
864-
}
865-
''', [
866-
error(ParserErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR, 23, 4),
867-
error(CompileTimeErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR, 23, 6),
868-
]);
869-
}
870-
871-
test_fieldInitializerOutsideConstructor_closure() async {
872-
await assertErrorsInCode(r'''
873-
class A {
874-
dynamic field = ({this.field}) {};
875-
}
876-
''', [
877-
error(CompileTimeErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR, 30, 10),
878-
]);
879-
}
880-
881-
test_fieldInitializerOutsideConstructor_defaultParameter() async {
882-
await assertErrorsInCode(r'''
883-
class A {
884-
int x;
885-
m([this.x]) {}
886-
}
887-
''', [
888-
error(CompileTimeErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR, 24, 6),
889-
]);
890-
}
891-
892-
test_fieldInitializerOutsideConstructor_inFunctionTypeParameter() async {
893-
await assertErrorsInCode(r'''
894-
class A {
895-
int x;
896-
A(int p(this.x));
897-
}
898-
''', [
899-
error(CompileTimeErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR, 29, 6),
900-
]);
901-
}
902-
903-
test_fieldInitializerOutsideConstructor_topLevelFunction() async {
904-
await assertErrorsInCode(r'''
905-
f(this.x(y)) {}
906-
''', [
907-
error(CompileTimeErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR, 2, 9),
908-
]);
909-
}
910-
911-
test_fieldInitializerRedirectingConstructor_afterRedirection() async {
912-
await assertErrorsInCode(r'''
913-
class A {
914-
int x;
915-
A.named() {}
916-
A() : this.named(), x = 42;
917-
}
918-
''', [
919-
error(CompileTimeErrorCode.FIELD_INITIALIZER_REDIRECTING_CONSTRUCTOR, 56,
920-
6),
921-
]);
922-
}
923-
924-
test_fieldInitializerRedirectingConstructor_beforeRedirection() async {
925-
await assertErrorsInCode(r'''
926-
class A {
927-
int x;
928-
A.named() {}
929-
A() : x = 42, this.named();
930-
}
931-
''', [
932-
error(CompileTimeErrorCode.FIELD_INITIALIZER_REDIRECTING_CONSTRUCTOR, 42,
933-
6),
934-
]);
935-
}
936-
937-
test_fieldInitializingFormalRedirectingConstructor() async {
938-
await assertErrorsInCode(r'''
939-
class A {
940-
int x;
941-
A.named() {}
942-
A(this.x) : this.named();
943-
}
944-
''', [
945-
error(CompileTimeErrorCode.FIELD_INITIALIZER_REDIRECTING_CONSTRUCTOR, 38,
946-
6),
947-
]);
948-
}
949-
950-
test_forInWithConstVariable_forEach_identifier() async {
951-
await assertErrorsInCode(r'''
952-
f() {
953-
const x = 0;
954-
for (x in [0, 1, 2]) {}
955-
}
956-
''', [
957-
error(HintCode.UNUSED_LOCAL_VARIABLE, 14, 1),
958-
error(StaticWarningCode.ASSIGNMENT_TO_CONST, 28, 1),
959-
]);
960-
}
961-
962847
test_fromEnvironment_bool_badArgs() async {
963848
await assertErrorsInCode(r'''
964849
var b1 = const bool.fromEnvironment(1);
@@ -1058,36 +943,6 @@ void g(T f<T>(T x)) {}
1058943
await assertNoErrorsInCode(code);
1059944
}
1060945

1061-
test_implementsDeferredClass() async {
1062-
newFile('/test/lib/lib1.dart', content: '''
1063-
library lib1;
1064-
class A {}
1065-
''');
1066-
await assertErrorsInCode('''
1067-
library root;
1068-
import 'lib1.dart' deferred as a;
1069-
class B implements a.A {}
1070-
''', [
1071-
error(CompileTimeErrorCode.IMPLEMENTS_DEFERRED_CLASS, 67, 3),
1072-
]);
1073-
}
1074-
1075-
test_implementsDeferredClass_classTypeAlias() async {
1076-
newFile('/test/lib/lib1.dart', content: '''
1077-
library lib1;
1078-
class A {}
1079-
''');
1080-
await assertErrorsInCode('''
1081-
library root;
1082-
import 'lib1.dart' deferred as a;
1083-
class B {}
1084-
class M {}
1085-
class C = B with M implements a.A;
1086-
''', [
1087-
error(CompileTimeErrorCode.IMPLEMENTS_DEFERRED_CLASS, 100, 3),
1088-
]);
1089-
}
1090-
1091946
test_importInternalLibrary() async {
1092947
// Note, in these error cases we may generate an UNUSED_IMPORT hint, while
1093948
// we could prevent the hint from being generated by testing the import
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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:analyzer/src/generated/parser.dart' show ParserErrorCode;
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(FieldInitializerFactoryConstructorTest);
14+
});
15+
}
16+
17+
@reflectiveTest
18+
class FieldInitializerFactoryConstructorTest extends DriverResolutionTest {
19+
test_fieldFormalParameter() async {
20+
await assertErrorsInCode(r'''
21+
class A {
22+
int x;
23+
factory A(this.x) => throw 0;
24+
}
25+
''', [
26+
error(CompileTimeErrorCode.FIELD_INITIALIZER_FACTORY_CONSTRUCTOR, 31, 6),
27+
]);
28+
}
29+
30+
test_functionTypedParameter() async {
31+
await assertErrorsInCode(r'''
32+
class A {
33+
int Function() x;
34+
factory A(int this.x());
35+
}
36+
''', [
37+
// TODO(srawlins): Only report one error. Theoretically change Fasta to
38+
// report "Field initiailizer in factory constructor" as a parse error.
39+
error(CompileTimeErrorCode.FIELD_INITIALIZER_FACTORY_CONSTRUCTOR, 42, 12),
40+
error(ParserErrorCode.MISSING_FUNCTION_BODY, 55, 1),
41+
]);
42+
}
43+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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:analyzer/src/generated/parser.dart' show ParserErrorCode;
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(FieldInitializerOutsideConstructorTest);
14+
});
15+
}
16+
17+
@reflectiveTest
18+
class FieldInitializerOutsideConstructorTest extends DriverResolutionTest {
19+
test_closure() async {
20+
await assertErrorsInCode(r'''
21+
class A {
22+
dynamic field = ({this.field}) {};
23+
}
24+
''', [
25+
error(CompileTimeErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR, 30, 10),
26+
]);
27+
}
28+
29+
test_defaultParameter() async {
30+
await assertErrorsInCode(r'''
31+
class A {
32+
int x;
33+
m([this.x]) {}
34+
}
35+
''', [
36+
error(CompileTimeErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR, 24, 6),
37+
]);
38+
}
39+
40+
test_functionTypedFieldFormalParameter() async {
41+
// TODO(srawlins) Fix the duplicate error messages.
42+
await assertErrorsInCode(r'''
43+
class A {
44+
int Function() x;
45+
m(int this.x()) {}
46+
}
47+
''', [
48+
error(CompileTimeErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR, 34, 12),
49+
error(ParserErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR, 38, 4),
50+
]);
51+
}
52+
53+
test_inFunctionTypedParameter() async {
54+
await assertErrorsInCode(r'''
55+
class A {
56+
int x;
57+
A(int p(this.x));
58+
}
59+
''', [
60+
error(CompileTimeErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR, 29, 6),
61+
]);
62+
}
63+
64+
test_method() async {
65+
// TODO(brianwilkerson) Fix the duplicate error messages.
66+
await assertErrorsInCode(r'''
67+
class A {
68+
int x;
69+
m(this.x) {}
70+
}
71+
''', [
72+
error(ParserErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR, 23, 4),
73+
error(CompileTimeErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR, 23, 6),
74+
]);
75+
}
76+
77+
test_topLevelFunction() async {
78+
await assertErrorsInCode(r'''
79+
f(this.x(y)) {}
80+
''', [
81+
error(CompileTimeErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR, 2, 9),
82+
]);
83+
}
84+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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(FieldInitializerRedirectingConstructorTest);
13+
});
14+
}
15+
16+
@reflectiveTest
17+
class FieldInitializerRedirectingConstructorTest extends DriverResolutionTest {
18+
test_afterRedirection() async {
19+
await assertErrorsInCode(r'''
20+
class A {
21+
int x;
22+
A.named() {}
23+
A() : this.named(), x = 42;
24+
}
25+
''', [
26+
error(CompileTimeErrorCode.FIELD_INITIALIZER_REDIRECTING_CONSTRUCTOR, 56,
27+
6),
28+
]);
29+
}
30+
31+
test_beforeRedirection() async {
32+
await assertErrorsInCode(r'''
33+
class A {
34+
int x;
35+
A.named() {}
36+
A() : x = 42, this.named();
37+
}
38+
''', [
39+
error(CompileTimeErrorCode.FIELD_INITIALIZER_REDIRECTING_CONSTRUCTOR, 42,
40+
6),
41+
]);
42+
}
43+
44+
test_redirectionOnly() async {
45+
await assertErrorsInCode(r'''
46+
class A {
47+
int x;
48+
A.named() {}
49+
A(this.x) : this.named();
50+
}
51+
''', [
52+
error(CompileTimeErrorCode.FIELD_INITIALIZER_REDIRECTING_CONSTRUCTOR, 38,
53+
6),
54+
]);
55+
}
56+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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(ImplementsDeferredClassTest);
13+
});
14+
}
15+
16+
@reflectiveTest
17+
class ImplementsDeferredClassTest extends DriverResolutionTest {
18+
test_implements() async {
19+
newFile('/test/lib/lib1.dart', content: '''
20+
library lib1;
21+
class A {}
22+
''');
23+
await assertErrorsInCode('''
24+
library root;
25+
import 'lib1.dart' deferred as a;
26+
class B implements a.A {}
27+
''', [
28+
error(CompileTimeErrorCode.IMPLEMENTS_DEFERRED_CLASS, 67, 3),
29+
]);
30+
}
31+
32+
test_mixinApplication() async {
33+
newFile('/test/lib/lib1.dart', content: '''
34+
library lib1;
35+
class A {}
36+
''');
37+
await assertErrorsInCode('''
38+
library root;
39+
import 'lib1.dart' deferred as a;
40+
class B {}
41+
class M {}
42+
class C = B with M implements a.A;
43+
''', [
44+
error(CompileTimeErrorCode.IMPLEMENTS_DEFERRED_CLASS, 100, 3),
45+
]);
46+
}
47+
}

0 commit comments

Comments
 (0)