Analyzer: Move tests for 5 codes to diagnostics/
Change-Id: I6545819d659f18b0bbd0cf79b10c564a0bd66777
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/155848
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
diff --git a/pkg/analyzer/test/generated/compile_time_error_code.dart b/pkg/analyzer/test/generated/compile_time_error_code.dart
index 5035a98..8afcd5b 100644
--- a/pkg/analyzer/test/generated/compile_time_error_code.dart
+++ b/pkg/analyzer/test/generated/compile_time_error_code.dart
@@ -178,134 +178,6 @@
]);
}
- test_constWithNonType() async {
- await assertErrorsInCode(r'''
-int A;
-f() {
- return const A();
-}
-''', [
- error(CompileTimeErrorCode.CONST_WITH_NON_TYPE, 28, 1),
- ]);
- }
-
- test_constWithNonType_fromLibrary() async {
- newFile('/test/lib/lib1.dart');
- await assertErrorsInCode('''
-import 'lib1.dart' as lib;
-void f() {
- const lib.A();
-}
-''', [
- error(CompileTimeErrorCode.CONST_WITH_NON_TYPE, 50, 1),
- ]);
- }
-
- test_constWithTypeParameters_direct() async {
- await assertErrorsInCode(r'''
-class A<T> {
- static const V = const A<T>();
- const A();
-}
-''', [
- error(CompileTimeErrorCode.TYPE_PARAMETER_REFERENCED_BY_STATIC, 40, 1),
- error(CompileTimeErrorCode.CONST_WITH_TYPE_PARAMETERS, 40, 1),
- ]);
- }
-
- test_constWithTypeParameters_indirect() async {
- await assertErrorsInCode(r'''
-class A<T> {
- static const V = const A<List<T>>();
- const A();
-}
-''', [
- error(CompileTimeErrorCode.CONST_WITH_TYPE_PARAMETERS, 45, 1),
- error(CompileTimeErrorCode.TYPE_PARAMETER_REFERENCED_BY_STATIC, 45, 1),
- ]);
- }
-
- test_constWithUndefinedConstructor() async {
- await assertErrorsInCode(r'''
-class A {
- const A();
-}
-f() {
- return const A.noSuchConstructor();
-}
-''', [
- error(CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR, 48, 17),
- ]);
- }
-
- test_constWithUndefinedConstructorDefault() async {
- await assertErrorsInCode(r'''
-class A {
- const A.name();
-}
-f() {
- return const A();
-}
-''', [
- error(
- CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT, 51, 1),
- ]);
- }
-
- test_extraPositionalArguments_const() async {
- await assertErrorsInCode(r'''
-class A {
- const A();
-}
-main() {
- const A(0);
-}
-''', [
- error(CompileTimeErrorCode.EXTRA_POSITIONAL_ARGUMENTS, 43, 3),
- ]);
- }
-
- test_extraPositionalArguments_const_super() async {
- await assertErrorsInCode(r'''
-class A {
- const A();
-}
-class B extends A {
- const B() : super(0);
-}
-''', [
- error(CompileTimeErrorCode.EXTRA_POSITIONAL_ARGUMENTS, 64, 3),
- ]);
- }
-
- test_extraPositionalArgumentsCouldBeNamed_const() async {
- await assertErrorsInCode(r'''
-class A {
- const A({int x});
-}
-main() {
- const A(0);
-}
-''', [
- error(CompileTimeErrorCode.EXTRA_POSITIONAL_ARGUMENTS_COULD_BE_NAMED, 50,
- 3),
- ]);
- }
-
- test_extraPositionalArgumentsCouldBeNamed_const_super() async {
- await assertErrorsInCode(r'''
-class A {
- const A({int x});
-}
-class B extends A {
- const B() : super(0);
-}
-''', [
- error(CompileTimeErrorCode.EXTRA_POSITIONAL_ARGUMENTS_COULD_BE_NAMED, 71,
- 3),
- ]);
- }
-
test_fromEnvironment_bool_badArgs() async {
await assertErrorsInCode(r'''
var b1 = const bool.fromEnvironment(1);
@@ -359,45 +231,6 @@
]);
}
- test_genericFunctionTypeAsBound_class() async {
- await assertErrorsInCode(r'''
-class C<T extends S Function<S>(S)> {
-}
-''', [
- error(CompileTimeErrorCode.GENERIC_FUNCTION_TYPE_CANNOT_BE_BOUND, 18, 16),
- ]);
- }
-
- test_genericFunctionTypeAsBound_genericFunction() async {
- await assertErrorsInCode(r'''
-T Function<T extends S Function<S>(S)>(T) fun;
-''', [
- error(CompileTimeErrorCode.GENERIC_FUNCTION_TYPE_CANNOT_BE_BOUND, 21, 16),
- ]);
- }
-
- test_genericFunctionTypeAsBound_genericFunctionTypedef() async {
- await assertErrorsInCode(r'''
-typedef foo = T Function<T extends S Function<S>(S)>(T t);
-''', [
- error(CompileTimeErrorCode.GENERIC_FUNCTION_TYPE_CANNOT_BE_BOUND, 35, 16),
- ]);
- }
-
- test_genericFunctionTypeAsBound_parameterOfFunction() async {
- await assertNoErrorsInCode(r'''
-class C<T extends void Function(S Function<S>(S))> {}
-''');
- }
-
- test_genericFunctionTypeAsBound_typedef() async {
- await assertErrorsInCode(r'''
-typedef T foo<T extends S Function<S>(S)>(T t);
-''', [
- error(CompileTimeErrorCode.GENERIC_FUNCTION_TYPE_CANNOT_BE_BOUND, 24, 16),
- ]);
- }
-
test_genericFunctionTypedParameter() async {
var code = '''
void g(T f<T>(T x)) {}
@@ -405,34 +238,6 @@
await assertNoErrorsInCode(code);
}
- test_importInternalLibrary() async {
- // Note, in these error cases we may generate an UNUSED_IMPORT hint, while
- // we could prevent the hint from being generated by testing the import
- // directive for the error, this is such a minor corner case that we don't
- // think we should add the additional computation time to figure out such
- // cases.
- await assertErrorsInCode('''
-import 'dart:_interceptors';
-''', [
- error(CompileTimeErrorCode.IMPORT_INTERNAL_LIBRARY, 7, 20),
- error(HintCode.UNUSED_IMPORT, 7, 20),
- ]);
- }
-
- test_importOfNonLibrary() async {
- newFile("/test/lib/part.dart", content: r'''
-part of lib;
-class A{}
-''');
- await assertErrorsInCode(r'''
-library lib;
-import 'part.dart';
-A a;
-''', [
- error(CompileTimeErrorCode.IMPORT_OF_NON_LIBRARY, 20, 11),
- ]);
- }
-
test_length_of_erroneous_constant() async {
// Attempting to compute the length of constant that couldn't be evaluated
// (due to an error) should not crash the analyzer (see dartbug.com/23383)
diff --git a/pkg/analyzer/test/src/diagnostics/const_with_non_type_test.dart b/pkg/analyzer/test/src/diagnostics/const_with_non_type_test.dart
new file mode 100644
index 0000000..1bd6571
--- /dev/null
+++ b/pkg/analyzer/test/src/diagnostics/const_with_non_type_test.dart
@@ -0,0 +1,40 @@
+// Copyright (c) 2020, 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:analyzer/src/error/codes.dart';
+import 'package:test_reflective_loader/test_reflective_loader.dart';
+
+import '../dart/resolution/driver_resolution.dart';
+
+main() {
+ defineReflectiveSuite(() {
+ defineReflectiveTests(ConstWithNonTypeTest);
+ });
+}
+
+@reflectiveTest
+class ConstWithNonTypeTest extends DriverResolutionTest {
+ test_fromLibrary() async {
+ newFile('/test/lib/lib1.dart');
+ await assertErrorsInCode('''
+import 'lib1.dart' as lib;
+void f() {
+ const lib.A();
+}
+''', [
+ error(CompileTimeErrorCode.CONST_WITH_NON_TYPE, 50, 1),
+ ]);
+ }
+
+ test_variable() async {
+ await assertErrorsInCode(r'''
+int A;
+f() {
+ return const A();
+}
+''', [
+ error(CompileTimeErrorCode.CONST_WITH_NON_TYPE, 28, 1),
+ ]);
+ }
+}
diff --git a/pkg/analyzer/test/src/diagnostics/const_with_type_parameters_test.dart b/pkg/analyzer/test/src/diagnostics/const_with_type_parameters_test.dart
new file mode 100644
index 0000000..5aed8fe
--- /dev/null
+++ b/pkg/analyzer/test/src/diagnostics/const_with_type_parameters_test.dart
@@ -0,0 +1,41 @@
+// Copyright (c) 2020, 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:analyzer/src/error/codes.dart';
+import 'package:test_reflective_loader/test_reflective_loader.dart';
+
+import '../dart/resolution/driver_resolution.dart';
+
+main() {
+ defineReflectiveSuite(() {
+ defineReflectiveTests(ConstWithTypeParametersTest);
+ });
+}
+
+@reflectiveTest
+class ConstWithTypeParametersTest extends DriverResolutionTest {
+ test_direct() async {
+ await assertErrorsInCode(r'''
+class A<T> {
+ static const V = const A<T>();
+ const A();
+}
+''', [
+ error(CompileTimeErrorCode.TYPE_PARAMETER_REFERENCED_BY_STATIC, 40, 1),
+ error(CompileTimeErrorCode.CONST_WITH_TYPE_PARAMETERS, 40, 1),
+ ]);
+ }
+
+ test_indirect() async {
+ await assertErrorsInCode(r'''
+class A<T> {
+ static const V = const A<List<T>>();
+ const A();
+}
+''', [
+ error(CompileTimeErrorCode.CONST_WITH_TYPE_PARAMETERS, 45, 1),
+ error(CompileTimeErrorCode.TYPE_PARAMETER_REFERENCED_BY_STATIC, 45, 1),
+ ]);
+ }
+}
diff --git a/pkg/analyzer/test/src/diagnostics/const_with_undefined_constructor_test.dart b/pkg/analyzer/test/src/diagnostics/const_with_undefined_constructor_test.dart
new file mode 100644
index 0000000..f60efa0
--- /dev/null
+++ b/pkg/analyzer/test/src/diagnostics/const_with_undefined_constructor_test.dart
@@ -0,0 +1,44 @@
+// Copyright (c) 2020, 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:analyzer/src/error/codes.dart';
+import 'package:test_reflective_loader/test_reflective_loader.dart';
+
+import '../dart/resolution/driver_resolution.dart';
+
+main() {
+ defineReflectiveSuite(() {
+ defineReflectiveTests(ConstWithUndefinedConstructorTest);
+ });
+}
+
+@reflectiveTest
+class ConstWithUndefinedConstructorTest extends DriverResolutionTest {
+ test_named() async {
+ await assertErrorsInCode(r'''
+class A {
+ const A();
+}
+f() {
+ return const A.noSuchConstructor();
+}
+''', [
+ error(CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR, 48, 17),
+ ]);
+ }
+
+ test_unnamed() async {
+ await assertErrorsInCode(r'''
+class A {
+ const A.name();
+}
+f() {
+ return const A();
+}
+''', [
+ error(
+ CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT, 51, 1),
+ ]);
+ }
+}
diff --git a/pkg/analyzer/test/src/diagnostics/extra_positional_arguments_test.dart b/pkg/analyzer/test/src/diagnostics/extra_positional_arguments_test.dart
index 1a18b4a..991bdd9 100644
--- a/pkg/analyzer/test/src/diagnostics/extra_positional_arguments_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/extra_positional_arguments_test.dart
@@ -16,6 +16,34 @@
@reflectiveTest
class ExtraPositionalArgumentsCouldBeNamedTest extends DriverResolutionTest {
+ test_constConstructor() async {
+ await assertErrorsInCode(r'''
+class A {
+ const A({int x});
+}
+main() {
+ const A(0);
+}
+''', [
+ error(CompileTimeErrorCode.EXTRA_POSITIONAL_ARGUMENTS_COULD_BE_NAMED, 50,
+ 3),
+ ]);
+ }
+
+ test_constConstructor_super() async {
+ await assertErrorsInCode(r'''
+class A {
+ const A({int x});
+}
+class B extends A {
+ const B() : super(0);
+}
+''', [
+ error(CompileTimeErrorCode.EXTRA_POSITIONAL_ARGUMENTS_COULD_BE_NAMED, 71,
+ 3),
+ ]);
+ }
+
test_functionExpressionInvocation() async {
await assertErrorsInCode('''
main() {
@@ -42,6 +70,32 @@
@reflectiveTest
class ExtraPositionalArgumentsTest extends DriverResolutionTest {
+ test_constConstructor() async {
+ await assertErrorsInCode(r'''
+class A {
+ const A();
+}
+main() {
+ const A(0);
+}
+''', [
+ error(CompileTimeErrorCode.EXTRA_POSITIONAL_ARGUMENTS, 43, 3),
+ ]);
+ }
+
+ test_constConstructor_super() async {
+ await assertErrorsInCode(r'''
+class A {
+ const A();
+}
+class B extends A {
+ const B() : super(0);
+}
+''', [
+ error(CompileTimeErrorCode.EXTRA_POSITIONAL_ARGUMENTS, 64, 3),
+ ]);
+ }
+
test_functionExpressionInvocation() async {
await assertErrorsInCode('''
main() {
diff --git a/pkg/analyzer/test/src/diagnostics/generic_function_type_cannot_be_bound_test.dart b/pkg/analyzer/test/src/diagnostics/generic_function_type_cannot_be_bound_test.dart
new file mode 100644
index 0000000..a07471e
--- /dev/null
+++ b/pkg/analyzer/test/src/diagnostics/generic_function_type_cannot_be_bound_test.dart
@@ -0,0 +1,56 @@
+// Copyright (c) 2020, 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:analyzer/src/error/codes.dart';
+import 'package:test_reflective_loader/test_reflective_loader.dart';
+
+import '../dart/resolution/driver_resolution.dart';
+
+main() {
+ defineReflectiveSuite(() {
+ defineReflectiveTests(GenericFunctionTypeCannotBeBoundTest);
+ });
+}
+
+@reflectiveTest
+class GenericFunctionTypeCannotBeBoundTest extends DriverResolutionTest {
+ test_class() async {
+ await assertErrorsInCode(r'''
+class C<T extends S Function<S>(S)> {
+}
+''', [
+ error(CompileTimeErrorCode.GENERIC_FUNCTION_TYPE_CANNOT_BE_BOUND, 18, 16),
+ ]);
+ }
+
+ test_genericFunction() async {
+ await assertErrorsInCode(r'''
+T Function<T extends S Function<S>(S)>(T) fun;
+''', [
+ error(CompileTimeErrorCode.GENERIC_FUNCTION_TYPE_CANNOT_BE_BOUND, 21, 16),
+ ]);
+ }
+
+ test_genericFunctionTypedef() async {
+ await assertErrorsInCode(r'''
+typedef foo = T Function<T extends S Function<S>(S)>(T t);
+''', [
+ error(CompileTimeErrorCode.GENERIC_FUNCTION_TYPE_CANNOT_BE_BOUND, 35, 16),
+ ]);
+ }
+
+ test_parameterOfFunction() async {
+ await assertNoErrorsInCode(r'''
+class C<T extends void Function(S Function<S>(S))> {}
+''');
+ }
+
+ test_typedef() async {
+ await assertErrorsInCode(r'''
+typedef T foo<T extends S Function<S>(S)>(T t);
+''', [
+ error(CompileTimeErrorCode.GENERIC_FUNCTION_TYPE_CANNOT_BE_BOUND, 24, 16),
+ ]);
+ }
+}
diff --git a/pkg/analyzer/test/src/diagnostics/import_internal_library_test.dart b/pkg/analyzer/test/src/diagnostics/import_internal_library_test.dart
new file mode 100644
index 0000000..7397975
--- /dev/null
+++ b/pkg/analyzer/test/src/diagnostics/import_internal_library_test.dart
@@ -0,0 +1,31 @@
+// Copyright (c) 2020, 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:analyzer/src/error/codes.dart';
+import 'package:test_reflective_loader/test_reflective_loader.dart';
+
+import '../dart/resolution/driver_resolution.dart';
+
+main() {
+ defineReflectiveSuite(() {
+ defineReflectiveTests(ImportInternalLibraryTest);
+ });
+}
+
+@reflectiveTest
+class ImportInternalLibraryTest extends DriverResolutionTest {
+ test_internal() async {
+ // Note, in these error cases we may generate an UNUSED_IMPORT hint, while
+ // we could prevent the hint from being generated by testing the import
+ // directive for the error, this is such a minor corner case that we don't
+ // think we should add the additional computation time to figure out such
+ // cases.
+ await assertErrorsInCode('''
+import 'dart:_interceptors';
+''', [
+ error(CompileTimeErrorCode.IMPORT_INTERNAL_LIBRARY, 7, 20),
+ error(HintCode.UNUSED_IMPORT, 7, 20),
+ ]);
+ }
+}
diff --git a/pkg/analyzer/test/src/diagnostics/import_of_non_library_test.dart b/pkg/analyzer/test/src/diagnostics/import_of_non_library_test.dart
index c5d1d06..36ac79a 100644
--- a/pkg/analyzer/test/src/diagnostics/import_of_non_library_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/import_of_non_library_test.dart
@@ -15,7 +15,7 @@
@reflectiveTest
class ImportOfNonLibraryTest extends DriverResolutionTest {
- test_part() async {
+ test_deferred() async {
newFile("/test/lib/lib1.dart", content: '''
part of lib;
class A {}
@@ -28,4 +28,18 @@
error(CompileTimeErrorCode.IMPORT_OF_NON_LIBRARY, 20, 11),
]);
}
+
+ test_part() async {
+ newFile("/test/lib/part.dart", content: r'''
+part of lib;
+class A{}
+''');
+ await assertErrorsInCode(r'''
+library lib;
+import 'part.dart';
+A a;
+''', [
+ error(CompileTimeErrorCode.IMPORT_OF_NON_LIBRARY, 20, 11),
+ ]);
+ }
}
diff --git a/pkg/analyzer/test/src/diagnostics/test_all.dart b/pkg/analyzer/test/src/diagnostics/test_all.dart
index a6df3c6..f5f1ba7 100644
--- a/pkg/analyzer/test/src/diagnostics/test_all.dart
+++ b/pkg/analyzer/test/src/diagnostics/test_all.dart
@@ -89,6 +89,10 @@
as const_spread_expected_list_or_set;
import 'const_spread_expected_map_test.dart' as const_spread_expected_map;
import 'const_with_non_const_test.dart' as const_with_non_const;
+import 'const_with_non_type_test.dart' as const_with_non_type;
+import 'const_with_type_parameters_test.dart' as const_with_type_parameters;
+import 'const_with_undefined_constructor_test.dart'
+ as const_with_undefined_constructor;
import 'dead_code_test.dart' as dead_code;
import 'dead_null_aware_expression_test.dart' as dead_null_aware_expression;
import 'default_list_constructor_test.dart' as default_list_constructor;
@@ -185,6 +189,8 @@
as for_in_of_invalid_element_type;
import 'for_in_of_invalid_type_test.dart' as for_in_of_invalid_type;
import 'for_in_with_const_variable_test.dart' as for_in_with_const_variable;
+import 'generic_function_type_cannot_be_bound_test.dart'
+ as generic_function_type_cannot_be_bound;
import 'generic_struct_subclass_test.dart' as generic_struct_subclass;
import 'getter_not_assignable_setter_types_test.dart'
as getter_not_assignable_setter_types;
@@ -205,6 +211,7 @@
as implicit_this_reference_in_initializer;
import 'import_deferred_library_with_load_function_test.dart'
as import_deferred_library_with_load_function;
+import 'import_internal_library_test.dart' as import_internal_library;
import 'import_of_non_library_test.dart' as import_of_non_library;
import 'inconsistent_case_expression_types_test.dart'
as inconsistent_case_expression_types;
@@ -660,6 +667,9 @@
const_spread_expected_list_or_set.main();
const_spread_expected_map.main();
const_with_non_const.main();
+ const_with_non_type.main();
+ const_with_type_parameters.main();
+ const_with_undefined_constructor.main();
dead_code.main();
dead_null_aware_expression.main();
default_list_constructor.main();
@@ -724,6 +734,7 @@
for_in_of_invalid_element_type.main();
for_in_of_invalid_type.main();
for_in_with_const_variable.main();
+ generic_function_type_cannot_be_bound.main();
generic_struct_subclass.main();
getter_not_assignable_setter_types.main();
getter_not_subtype_setter_types.main();
@@ -737,6 +748,7 @@
implements_super_class.main();
implicit_this_reference_in_initializer.main();
import_deferred_library_with_load_function.main();
+ import_internal_library.main();
import_of_non_library.main();
inconsistent_case_expression_types.main();
inconsistent_inheritance_getter_and_method.main();