From 6e687d1d74d91eadc9b2e80cab5af1ad95ed77c4 Mon Sep 17 00:00:00 2001 From: Sam Rawlins Date: Fri, 10 Jul 2020 17:24:05 +0000 Subject: [PATCH] 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 Reviewed-by: Konstantin Shcheglov Reviewed-by: Brian Wilkerson --- .../static_type_warning_code_test.dart | 191 +----------------- ...instance_access_to_static_member_test.dart | 52 +++++ ...ation_of_non_function_expression_test.dart | 27 +++ .../non_type_as_type_argument_test.dart | 36 ++++ .../test/src/diagnostics/test_all.dart | 11 + ...parameter_supertype_of_its_bound_test.dart | 37 ++++ ...rence_to_non_local_static_member_test.dart | 76 +++++++ 7 files changed, 242 insertions(+), 188 deletions(-) create mode 100644 pkg/analyzer/test/src/diagnostics/invocation_of_non_function_expression_test.dart create mode 100644 pkg/analyzer/test/src/diagnostics/non_type_as_type_argument_test.dart create mode 100644 pkg/analyzer/test/src/diagnostics/type_parameter_supertype_of_its_bound_test.dart create mode 100644 pkg/analyzer/test/src/diagnostics/unqualified_reference_to_non_local_static_member_test.dart diff --git a/pkg/analyzer/test/generated/static_type_warning_code_test.dart b/pkg/analyzer/test/generated/static_type_warning_code_test.dart index 6f57178d8b13..9ad6ac0fcb2a 100644 --- a/pkg/analyzer/test/generated/static_type_warning_code_test.dart +++ b/pkg/analyzer/test/generated/static_type_warning_code_test.dart @@ -190,36 +190,6 @@ void main() { ]); } - test_expectedOneListTypeArgument() async { - await assertErrorsInCode(r''' -main() { - []; -} -''', [ - error(StaticTypeWarningCode.EXPECTED_ONE_LIST_TYPE_ARGUMENTS, 11, 10), - ]); - } - - test_expectedOneSetTypeArgument() async { - await assertErrorsInCode(r''' -main() { - {2, 3}; -} -''', [ - error(StaticTypeWarningCode.EXPECTED_ONE_SET_TYPE_ARGUMENTS, 11, 15), - ]); - } - - test_expectedTwoMapTypeArguments_three() async { - await assertErrorsInCode(r''' -main() { - {}; -} -''', [ - error(StaticTypeWarningCode.EXPECTED_TWO_MAP_TYPE_ARGUMENTS, 11, 15), - ]); - } - test_forIn_declaredVariableRightType() async { await assertErrorsInCode(''' f() { @@ -476,106 +446,9 @@ class C { ]); } - test_instanceAccessToStaticMember_method_reference() async { - await assertErrorsInCode(r''' -class A { - static m() {} -} -main(A a) { - a.m; -} -''', [ - error(StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER, 44, 1), - ]); - } - - test_instanceAccessToStaticMember_propertyAccess_field() async { - await assertErrorsInCode(r''' -class A { - static var f; -} -main(A a) { - a.f; -} -''', [ - error(StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER, 44, 1), - ]); - } - - test_instanceAccessToStaticMember_propertyAccess_getter() async { - await assertErrorsInCode(r''' -class A { - static get f => 42; -} -main(A a) { - a.f; -} -''', [ - error(StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER, 50, 1), - ]); - } - - test_instanceAccessToStaticMember_propertyAccess_setter() async { - await assertErrorsInCode(r''' -class A { - static set f(x) {} -} -main(A a) { - a.f = 42; -} -''', [ - error(StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER, 49, 1), - ]); - } - - test_invocationOfNonFunctionExpression_literal() async { - await assertErrorsInCode(r''' -f() { - 3(5); -} -''', [ - error(StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION_EXPRESSION, 8, 1), - ]); - } - - test_nonTypeAsTypeArgument_notAType() async { - await assertErrorsInCode(r''' -int A; -class B {} -f(B b) {} -''', [ - error(StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT, 25, 1), - ]); - } - - test_nonTypeAsTypeArgument_undefinedIdentifier() async { - await assertErrorsInCode(r''' -class B {} -f(B b) {} -''', [ - error(StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT, 18, 1), - ]); - } - - test_typeParameterSupertypeOfItsBound_1of1() async { - await assertErrorsInCode(r''' -class A { -} -''', [ - error(StaticTypeWarningCode.TYPE_PARAMETER_SUPERTYPE_OF_ITS_BOUND, 8, 11), - ]); - } - - test_typeParameterSupertypeOfItsBound_2of3() async { - await assertErrorsInCode(r''' -class A { -} -''', [ - error(StaticTypeWarningCode.TYPE_PARAMETER_SUPERTYPE_OF_ITS_BOUND, 8, 13), - error( - StaticTypeWarningCode.TYPE_PARAMETER_SUPERTYPE_OF_ITS_BOUND, 27, 13), - ]); - } + // TODO(srawlins) Figure out what to do with the rest of these tests. + // The names do not correspond to diagnostic codes, so it isn't clear what + // they're testing. test_typePromotion_booleanAnd_useInRight_accessedInClosureRight_mutated() async { await assertErrorsInCode(r''' @@ -823,64 +696,6 @@ main(A p) { ]); } - test_unqualifiedReferenceToNonLocalStaticMember_getter() async { - await assertErrorsInCode(r''' -class A { - static int get a => 0; -} -class B extends A { - int b() { - return a; - } -} -''', [ - error( - StaticTypeWarningCode - .UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER, - 80, - 1), - ]); - } - - test_unqualifiedReferenceToNonLocalStaticMember_getter_invokeTarget() async { - await assertErrorsInCode(r''' -class A { - static int foo; -} - -class B extends A { - static bar() { - foo.abs(); - } -} -''', [ - error( - StaticTypeWarningCode - .UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER, - 72, - 3), - ]); - } - - test_unqualifiedReferenceToNonLocalStaticMember_setter() async { - await assertErrorsInCode(r''' -class A { - static set a(x) {} -} -class B extends A { - b(y) { - a = y; - } -} -''', [ - error( - StaticTypeWarningCode - .UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER, - 66, - 1), - ]); - } - test_wrongNumberOfTypeArguments() async { await assertErrorsInCode(r''' class A { diff --git a/pkg/analyzer/test/src/diagnostics/instance_access_to_static_member_test.dart b/pkg/analyzer/test/src/diagnostics/instance_access_to_static_member_test.dart index 0f8682b35a36..a409b21eadb7 100644 --- a/pkg/analyzer/test/src/diagnostics/instance_access_to_static_member_test.dart +++ b/pkg/analyzer/test/src/diagnostics/instance_access_to_static_member_test.dart @@ -75,4 +75,56 @@ f(C c) { findElement.setter('a'), ); } + + test_method_reference() async { + await assertErrorsInCode(r''' +class A { + static m() {} +} +main(A a) { + a.m; +} +''', [ + error(StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER, 44, 1), + ]); + } + + test_propertyAccess_field() async { + await assertErrorsInCode(r''' +class A { + static var f; +} +main(A a) { + a.f; +} +''', [ + error(StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER, 44, 1), + ]); + } + + test_propertyAccess_getter() async { + await assertErrorsInCode(r''' +class A { + static get f => 42; +} +main(A a) { + a.f; +} +''', [ + error(StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER, 50, 1), + ]); + } + + test_propertyAccess_setter() async { + await assertErrorsInCode(r''' +class A { + static set f(x) {} +} +main(A a) { + a.f = 42; +} +''', [ + error(StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER, 49, 1), + ]); + } } diff --git a/pkg/analyzer/test/src/diagnostics/invocation_of_non_function_expression_test.dart b/pkg/analyzer/test/src/diagnostics/invocation_of_non_function_expression_test.dart new file mode 100644 index 000000000000..0554340cbcaa --- /dev/null +++ b/pkg/analyzer/test/src/diagnostics/invocation_of_non_function_expression_test.dart @@ -0,0 +1,27 @@ +// 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(InvocationOfNonFunctionExpressionTest); + }); +} + +@reflectiveTest +class InvocationOfNonFunctionExpressionTest extends DriverResolutionTest { + test_invocationOfNonFunctionExpression_literal() async { + await assertErrorsInCode(r''' +f() { + 3(5); +} +''', [ + error(StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION_EXPRESSION, 8, 1), + ]); + } +} diff --git a/pkg/analyzer/test/src/diagnostics/non_type_as_type_argument_test.dart b/pkg/analyzer/test/src/diagnostics/non_type_as_type_argument_test.dart new file mode 100644 index 000000000000..82e57ab474a9 --- /dev/null +++ b/pkg/analyzer/test/src/diagnostics/non_type_as_type_argument_test.dart @@ -0,0 +1,36 @@ +// 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(NonTypeAsTypeArgumentTest); + }); +} + +@reflectiveTest +class NonTypeAsTypeArgumentTest extends DriverResolutionTest { + test_notAType() async { + await assertErrorsInCode(r''' +int A; +class B {} +f(B b) {} +''', [ + error(StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT, 25, 1), + ]); + } + + test_undefinedIdentifier() async { + await assertErrorsInCode(r''' +class B {} +f(B b) {} +''', [ + error(StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT, 18, 1), + ]); + } +} diff --git a/pkg/analyzer/test/src/diagnostics/test_all.dart b/pkg/analyzer/test/src/diagnostics/test_all.dart index bd8b9b5c4e08..02d07245c097 100644 --- a/pkg/analyzer/test/src/diagnostics/test_all.dart +++ b/pkg/analyzer/test/src/diagnostics/test_all.dart @@ -265,6 +265,8 @@ import 'invalid_visibility_annotation_test.dart' as invalid_visibility_annotation; import 'invocation_of_extension_without_call_test.dart' as invocation_of_extension_without_call; +import 'invocation_of_non_function_expression_test.dart' + as invocation_of_non_function_expression; import 'is_double_test.dart' as is_double; import 'is_int_test.dart' as is_int; import 'is_not_double_test.dart' as is_not_double; @@ -347,6 +349,7 @@ import 'non_generative_constructor_test.dart' as non_generative_constructor; import 'non_native_function_type_argument_to_pointer_test.dart' as non_native_function_type_argument_to_pointer; import 'non_null_opt_out_test.dart' as non_null_opt_out; +import 'non_type_as_type_argument_test.dart' as non_type_as_type_argument; import 'non_type_in_catch_clause_test.dart' as non_type_in_catch_clause; import 'non_void_return_for_operator_test.dart' as non_void_return_for_operator; import 'non_void_return_for_setter_test.dart' as non_void_return_for_setter; @@ -485,6 +488,8 @@ import 'type_check_is_not_null_test.dart' as type_check_is_not_null; import 'type_check_is_null_test.dart' as type_check_is_null; import 'type_parameter_referenced_by_static_test.dart' as type_parameter_referenced_by_static; +import 'type_parameter_supertype_of_its_bound_test.dart' + as type_parameter_supertype_of_its_bound; import 'type_test_with_non_type_test.dart' as type_test_with_non_type; import 'type_test_with_undefined_name_test.dart' as type_test_with_undefined_name; @@ -516,6 +521,8 @@ import 'unnecessary_non_null_assertion_test.dart' as unnecessary_non_null_assertion; import 'unnecessary_null_comparison_test.dart' as unnecessary_null_comparison; import 'unnecessary_type_check_test.dart' as unnecessary_type_check; +import 'unqualified_reference_to_non_local_static_member_test.dart' + as unqualified_reference_to_non_local_static_member; import 'unqualified_reference_to_static_member_of_extended_type_test.dart' as unqualified_reference_to_static_member_of_extended_type; import 'unused_catch_clause_test.dart' as unused_catch_clause; @@ -716,6 +723,7 @@ main() { invalid_use_of_visible_for_testing_member.main(); invalid_visibility_annotation.main(); invocation_of_extension_without_call.main(); + invocation_of_non_function_expression.main(); is_double.main(); is_int.main(); is_not_double.main(); @@ -776,6 +784,7 @@ main() { non_generative_constructor.main(); non_native_function_type_argument_to_pointer.main(); non_null_opt_out.main(); + non_type_as_type_argument.main(); non_type_in_catch_clause.main(); non_void_return_for_operator.main(); non_void_return_for_setter.main(); @@ -865,6 +874,7 @@ main() { type_check_is_not_null.main(); type_check_is_null.main(); type_parameter_referenced_by_static.main(); + type_parameter_supertype_of_its_bound.main(); type_test_with_non_type.main(); type_test_with_undefined_name.main(); undefined_annotation.main(); @@ -893,6 +903,7 @@ main() { unnecessary_non_null_assertion.main(); unnecessary_null_comparison.main(); unnecessary_type_check.main(); + unqualified_reference_to_non_local_static_member.main(); unqualified_reference_to_static_member_of_extended_type.main(); unused_catch_clause.main(); unused_catch_stack.main(); diff --git a/pkg/analyzer/test/src/diagnostics/type_parameter_supertype_of_its_bound_test.dart b/pkg/analyzer/test/src/diagnostics/type_parameter_supertype_of_its_bound_test.dart new file mode 100644 index 000000000000..80a7acee4e04 --- /dev/null +++ b/pkg/analyzer/test/src/diagnostics/type_parameter_supertype_of_its_bound_test.dart @@ -0,0 +1,37 @@ +// 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(TypeParameterSupertypeOfItsBoundTest); + }); +} + +@reflectiveTest +class TypeParameterSupertypeOfItsBoundTest extends DriverResolutionTest { + test_1of1() async { + await assertErrorsInCode(r''' +class A { +} +''', [ + error(StaticTypeWarningCode.TYPE_PARAMETER_SUPERTYPE_OF_ITS_BOUND, 8, 11), + ]); + } + + test_2of3() async { + await assertErrorsInCode(r''' +class A { +} +''', [ + error(StaticTypeWarningCode.TYPE_PARAMETER_SUPERTYPE_OF_ITS_BOUND, 8, 13), + error( + StaticTypeWarningCode.TYPE_PARAMETER_SUPERTYPE_OF_ITS_BOUND, 27, 13), + ]); + } +} diff --git a/pkg/analyzer/test/src/diagnostics/unqualified_reference_to_non_local_static_member_test.dart b/pkg/analyzer/test/src/diagnostics/unqualified_reference_to_non_local_static_member_test.dart new file mode 100644 index 000000000000..52ed3addb967 --- /dev/null +++ b/pkg/analyzer/test/src/diagnostics/unqualified_reference_to_non_local_static_member_test.dart @@ -0,0 +1,76 @@ +// 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(UnqualifiedReferenceToNonLocalStaticMemberTest); + }); +} + +@reflectiveTest +class UnqualifiedReferenceToNonLocalStaticMemberTest + extends DriverResolutionTest { + test_getter() async { + await assertErrorsInCode(r''' +class A { + static int get a => 0; +} +class B extends A { + int b() { + return a; + } +} +''', [ + error( + StaticTypeWarningCode + .UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER, + 80, + 1), + ]); + } + + test_getter_invokeTarget() async { + await assertErrorsInCode(r''' +class A { + static int foo; +} + +class B extends A { + static bar() { + foo.abs(); + } +} +''', [ + error( + StaticTypeWarningCode + .UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER, + 72, + 3), + ]); + } + + test_setter() async { + await assertErrorsInCode(r''' +class A { + static set a(x) {} +} +class B extends A { + b(y) { + a = y; + } +} +''', [ + error( + StaticTypeWarningCode + .UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER, + 66, + 1), + ]); + } +}